52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|