2023-06-08 14:09:50 +08:00
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2023-08-23 01:59:40 +08:00
|
|
|
using AYellowpaper.SerializedCollections;
|
2023-10-20 19:31:12 +08:00
|
|
|
using BITFALL.Entities.Equipment;
|
2023-08-23 01:59:40 +08:00
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
namespace BITFALL
|
|
|
|
{
|
2023-10-30 01:25:53 +08:00
|
|
|
public class EntityPropsDisplay : EntityBehavior
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
[SerializeField] private SerializedDictionary<string, GameObject> equipped = new();
|
|
|
|
[SerializeField] private SerializedDictionary<string, GameObject> bodyEquips = new();
|
|
|
|
[SerializeField] private SerializedDictionary<string, GameObject> holsteredEquips = new();
|
2023-10-20 19:31:12 +08:00
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
[Inject(true)] private IEntityEquipment _entityEquipment;
|
|
|
|
[Inject(true)] private IEntityEquipmentContainer _playerEquipContainer;
|
|
|
|
[Inject(true)] private IPlayerEquipSelector _playerEquipSelector;
|
2023-10-20 19:31:12 +08:00
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
public override void OnStart()
|
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
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;
|
|
|
|
}
|
2023-09-01 14:33:54 +08:00
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
if (_playerEquipContainer is not null)
|
|
|
|
{
|
|
|
|
_playerEquipContainer.OnEquip += OnEquipBodyEquip;
|
|
|
|
_playerEquipContainer.OnDeEquip += OnUnEquipBodyEquip;
|
|
|
|
}
|
2023-09-01 14:33:54 +08:00
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
foreach (var x in equipped)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
x.Value.SetActive(false);
|
|
|
|
}
|
2023-10-29 15:27:13 +08:00
|
|
|
foreach (var x in bodyEquips)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
x.Value.SetActive(false);
|
|
|
|
}
|
2023-10-29 15:27:13 +08:00
|
|
|
foreach (var x in holsteredEquips)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
|
|
|
x.Value.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
2023-10-29 15:27:13 +08:00
|
|
|
|
|
|
|
private void OnUnEquippedEquipAddressable(string obj)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
if (string.IsNullOrEmpty(obj) is false && equipped.TryGetValue(obj, out var go))
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
go.SetActive(false);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-11-30 00:23:23 +08:00
|
|
|
if (_playerEquipSelector is not null)
|
|
|
|
{
|
|
|
|
OnUpdateHolsteredEquip(_playerEquipSelector.Equipped);
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
private void OnEquippedEquipAddressable(string obj)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
if (string.IsNullOrEmpty(obj) is false && equipped.TryGetValue(obj, out var go))
|
|
|
|
{
|
|
|
|
go.SetActive(true);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
2023-11-30 00:23:23 +08:00
|
|
|
|
|
|
|
if (_playerEquipSelector is not null)
|
|
|
|
{
|
|
|
|
OnUpdateHolsteredEquip(_playerEquipSelector.Equipped);
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
private void OnUnEquipBodyEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
if (bodyEquips.TryGetValue(arg2.AddressablePath, out var go))
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
go.SetActive(false);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 15:27:13 +08:00
|
|
|
private void OnEquipBodyEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
if (bodyEquips.TryGetValue(arg2.AddressablePath, out var go))
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
go.SetActive(true);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-29 15:27:13 +08:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2023-11-30 00:23:23 +08:00
|
|
|
if (_entityEquipment.CurrentItem?.AddressablePath != x.Value.AddressablePath)
|
|
|
|
go.SetActive(true);
|
2023-10-29 15:27:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEquippedUnEquip(IBasicItem obj)
|
|
|
|
{
|
|
|
|
OnUnEquippedEquipAddressable(obj?.AddressablePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEquippedEquip(IBasicItem obj)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-10-29 15:27:13 +08:00
|
|
|
OnEquippedEquipAddressable(obj?.AddressablePath);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|