122 lines
3.9 KiB
C#
122 lines
3.9 KiB
C#
using BITKit;
|
|
using BITKit.Entities;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using AYellowpaper.SerializedCollections;
|
|
using BITFALL.Entities.Equipment;
|
|
|
|
namespace BITFALL
|
|
{
|
|
public class EntityPropsDisplay : EntityBehavior
|
|
{
|
|
[SerializeField] private SerializedDictionary<string, GameObject> equipped = new();
|
|
[SerializeField] private SerializedDictionary<string, GameObject> bodyEquips = new();
|
|
[SerializeField] private SerializedDictionary<string, GameObject> holsteredEquips = new();
|
|
|
|
[Inject(true)] private IEntityEquipment _entityEquipment;
|
|
[Inject(true)] private IEntityEquipmentContainer _playerEquipContainer;
|
|
[Inject(true)] private IPlayerEquipSelector _playerEquipSelector;
|
|
|
|
public override void OnStart()
|
|
{
|
|
if (_entityEquipment is not null)
|
|
{
|
|
_entityEquipment.OnEquip += OnEquippedEquip;
|
|
_entityEquipment.OnUnEquip += OnEquippedUnEquip;
|
|
_entityEquipment.OnEquipAddressable+=OnEquippedEquipAddressable;
|
|
_entityEquipment.OnUnEquipAddressable+=OnUnEquippedEquipAddressable;
|
|
}
|
|
|
|
if (_playerEquipSelector is not null)
|
|
{
|
|
_playerEquipSelector.OnUpdateEquip += OnUpdateHolsteredEquip;
|
|
}
|
|
|
|
if (_playerEquipContainer is not null)
|
|
{
|
|
_playerEquipContainer.OnEquip += OnEquipBodyEquip;
|
|
_playerEquipContainer.OnDeEquip += OnUnEquipBodyEquip;
|
|
}
|
|
|
|
foreach (var x in equipped)
|
|
{
|
|
x.Value.SetActive(false);
|
|
}
|
|
foreach (var x in bodyEquips)
|
|
{
|
|
x.Value.SetActive(false);
|
|
}
|
|
foreach (var x in holsteredEquips)
|
|
{
|
|
x.Value.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnUnEquippedEquipAddressable(string obj)
|
|
{
|
|
if (string.IsNullOrEmpty(obj) is false && equipped.TryGetValue(obj, out var go))
|
|
{
|
|
go.SetActive(false);
|
|
}
|
|
if (_playerEquipSelector is not null)
|
|
{
|
|
OnUpdateHolsteredEquip(_playerEquipSelector.Equipped);
|
|
}
|
|
}
|
|
|
|
private void OnEquippedEquipAddressable(string obj)
|
|
{
|
|
if (string.IsNullOrEmpty(obj) is false && equipped.TryGetValue(obj, out var go))
|
|
{
|
|
go.SetActive(true);
|
|
}
|
|
|
|
if (_playerEquipSelector is not null)
|
|
{
|
|
OnUpdateHolsteredEquip(_playerEquipSelector.Equipped);
|
|
}
|
|
}
|
|
|
|
private void OnUnEquipBodyEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
|
{
|
|
if (bodyEquips.TryGetValue(arg2.AddressablePath, out var go))
|
|
{
|
|
go.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnEquipBodyEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
|
{
|
|
if (bodyEquips.TryGetValue(arg2.AddressablePath, out var go))
|
|
{
|
|
go.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void OnUpdateHolsteredEquip(IDictionary<int, IBasicItem> obj)
|
|
{
|
|
foreach (var x in holsteredEquips)
|
|
{
|
|
x.Value.SetActive(false);
|
|
}
|
|
foreach (var x in obj)
|
|
{
|
|
if (holsteredEquips.TryGetValue(x.Value.AddressablePath, out var go))
|
|
{
|
|
if (_entityEquipment.CurrentItem?.AddressablePath != x.Value.AddressablePath)
|
|
go.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnEquippedUnEquip(IBasicItem obj)
|
|
{
|
|
OnUnEquippedEquipAddressable(obj?.AddressablePath);
|
|
}
|
|
|
|
private void OnEquippedEquip(IBasicItem obj)
|
|
{
|
|
OnEquippedEquipAddressable(obj?.AddressablePath);
|
|
}
|
|
}
|
|
} |