BITFALL/Assets/Artists/Scripts/Entities/Skins/EntityPropsDisplay.cs

80 lines
2.5 KiB
C#
Raw Normal View History

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-09-01 14:33:54 +08:00
public class EntityPropsDisplay : EntityComponent
2023-06-08 14:09:50 +08:00
{
2023-08-23 01:59:40 +08:00
[SerializeField] private SerializedDictionary<string, GameObject> equipments = new();
[SerializeField] private SerializedDictionary<string, GameObject> unEquipDictionary = new();
[SerializeField] private SerializedDictionary<string, GameObject> equipDictionary = new();
2023-10-20 19:31:12 +08:00
[Inject] private IEntityEquipment _entityEquipment;
2023-10-20 22:46:14 +08:00
[Inject] private IEntityEquipmentContainer _playerEquipContainer;
2023-10-20 19:31:12 +08:00
[Inject] private IPlayerEquipSelector _playerEquipSelector;
2023-06-08 14:09:50 +08:00
public override void OnStart()
{
2023-10-20 19:31:12 +08:00
_playerEquipContainer.OnEquip += OnEquip;
_playerEquipContainer.OnDeEquip += OnDeEquip;
2023-09-01 14:33:54 +08:00
2023-10-20 19:31:12 +08:00
_entityEquipment.OnEquip += OnEquip;
_entityEquipment.OnDeEquip += OnDeEquip;
_playerEquipSelector.OnUpdateEquip += OnUpdateEquip;
2023-09-01 14:33:54 +08:00
2023-06-08 14:09:50 +08:00
foreach (var x in equipments)
{
x.Value.SetActive(false);
}
2023-08-23 01:59:40 +08:00
foreach (var x in unEquipDictionary)
2023-06-08 14:09:50 +08:00
{
x.Value.SetActive(false);
}
2023-08-23 01:59:40 +08:00
foreach (var x in equipDictionary)
2023-06-08 14:09:50 +08:00
{
x.Value.SetActive(false);
}
}
2023-09-01 14:33:54 +08:00
private void OnDeEquip(IEquipmentSlot slot, IBasicItem item)
2023-06-08 14:09:50 +08:00
{
var asset = item.GetAssetable();
2023-09-01 14:33:54 +08:00
if (equipments.TryGetValue(asset.AddressablePath, out GameObject prop))
2023-06-08 14:09:50 +08:00
{
prop.SetActive(false);
}
}
2023-09-01 14:33:54 +08:00
private void OnEquip(IEquipmentSlot slot, IBasicItem item)
2023-06-08 14:09:50 +08:00
{
var asset = item.GetAssetable();
2023-09-01 14:33:54 +08:00
if(equipments.TryGetValue(asset.AddressablePath, out GameObject prop)) {
2023-06-08 14:09:50 +08:00
prop.SetActive(true);
}
}
2023-09-01 14:33:54 +08:00
private void OnEquip(IBasicItem item)
2023-06-08 14:09:50 +08:00
{
2023-09-01 14:33:54 +08:00
if(item is null) return;
if (equipDictionary.TryGetValue(item.AddressablePath, out var model))
2023-06-08 14:09:50 +08:00
{
model.SetActive(true);
}
}
2023-09-01 14:33:54 +08:00
private void OnDeEquip(IBasicItem item)
2023-06-08 14:09:50 +08:00
{
2023-08-23 01:59:40 +08:00
foreach (var x in equipDictionary)
2023-06-08 14:09:50 +08:00
{
x.Value.gameObject.SetActive(false);
}
}
2023-09-01 14:33:54 +08:00
private void OnUpdateEquip(IDictionary<int, IBasicItem> maps)
2023-06-08 14:09:50 +08:00
{
}
}
}