using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using UnityEngine; using BITKit; using BITKit.Entities; using BITKit.Entities.Player; using BITKit.UX; using RotaryHeart.Lib.SerializableDictionary; using UnityEngine.Playables; using UnityEngine.UIElements; namespace BITFALL { public class UXEquipSelector : MonoBehaviour,IEquipSelectorCallback { [SerializeReference,SubclassSelector] private IPlayerService playerService; [SerializeField] private SerializableDictionaryBase dictionary = new(); [SerializeField] private UXImage currentUXEquip; private readonly ConcurrentDictionary cache=new(); public void OnEquip(IBasicItem item) { var assets = item.GetAssetable(); currentUXEquip.SetTexture(assets.RectangleIcon); } public void OnDeEquip(IBasicItem item) { currentUXEquip.SetTexture(null); } public void OnUpdateEquip(IDictionary maps) { cache.Clear(); foreach (var x in dictionary) { var image = x.Value; if (maps.TryGetValue(x.Key, out var item)) { var asset = item.GetAssetable(); image.SetTexture(asset.RectangleIcon); } else { image.SetTexture(null); } cache.TryAdd(x.Key, item); } } private void Start() { playerService.OnPlayerInitialized += OnStartLocalPlayer; OnDeEquip(null); } private void OnDestroy() { playerService.OnPlayerInitialized -= OnStartLocalPlayer; } private void OnStartLocalPlayer(IEntity entity) { entity.RegisterCallback(this); } } }