BITFALL/Assets/Artists/Scripts/UX/UXEquipSelector.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2023-06-08 14:09:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using BITKit.Entities;
using BITKit.UX;
using RotaryHeart.Lib.SerializableDictionary;
namespace BITFALL
{
public class UXEquipSelector : MonoBehaviour,IEquipSelectorCallback
{
[SerializeField]
private SerializableDictionaryBase<int, UXImage> dictionary = new();
[SerializeField] private UXImage currentUXEquip;
public void OnEquip(IBasicItem item)
{
var assets = item.GetAssetable();
currentUXEquip.SetTexture(assets.RectangleIcon);
}
public void OnDeEquip(IBasicItem item)
{
currentUXEquip.SetTexture(null);
}
public void OnUpdateEquiped(IDictionary<int, IBasicItem> maps)
{
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);
}
}
}
private void Start()
{
IEntity.OnSpawnLocalPlayer += OnStartLocalPlayer;
OnDeEquip(null);
}
private void OnStartLocalPlayer(IEntity entity)
{
entity.RegisterCallback<IEquipSelectorCallback>(this);
}
}
}