1
This commit is contained in:
@@ -13,15 +13,18 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
public class UXEquipSelector : MonoBehaviour,IEquipSelectorCallback
|
||||
public class UXEquipSelector : MonoBehaviour
|
||||
{
|
||||
[SerializeReference,SubclassSelector] private IPlayerService playerService;
|
||||
[SerializeField]
|
||||
private SerializableDictionaryBase<int, UXImage> dictionary = new();
|
||||
[SerializeField] private UXImage currentUXEquip;
|
||||
private readonly ConcurrentDictionary<int,IBasicItem> cache=new();
|
||||
|
||||
private IPlayerEquipSelector _equipSelector;
|
||||
public void OnEquip(IBasicItem item)
|
||||
{
|
||||
if(item is null) return;
|
||||
var assets = item.GetAssetable();
|
||||
currentUXEquip.SetTexture(assets.RectangleIcon);
|
||||
}
|
||||
@@ -32,10 +35,9 @@ namespace BITFALL
|
||||
public void OnUpdateEquip(IDictionary<int, IBasicItem> maps)
|
||||
{
|
||||
cache.Clear();
|
||||
foreach (var x in dictionary)
|
||||
foreach (var (key, image) in dictionary)
|
||||
{
|
||||
var image = x.Value;
|
||||
if (maps.TryGetValue(x.Key, out var item))
|
||||
if (maps.TryGetValue(key, out var item))
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
image.SetTexture(asset.RectangleIcon);
|
||||
@@ -44,14 +46,24 @@ namespace BITFALL
|
||||
{
|
||||
image.SetTexture(null);
|
||||
}
|
||||
|
||||
cache.TryAdd(x.Key, item);
|
||||
cache.TryAdd(key, item);
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
playerService.OnPlayerInitialized += OnStartLocalPlayer;
|
||||
OnDeEquip(null);
|
||||
foreach (var x in dictionary)
|
||||
{
|
||||
x.Value.visualElement.RegisterCallback<MouseDownEvent>(evt =>
|
||||
{
|
||||
if (evt.button is not 1) return;
|
||||
if (cache.TryGetValue(x.Key, out var item))
|
||||
{
|
||||
_equipSelector.TryDeEquip(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
@@ -59,7 +71,10 @@ namespace BITFALL
|
||||
}
|
||||
private void OnStartLocalPlayer(IEntity entity)
|
||||
{
|
||||
entity.RegisterCallback<IEquipSelectorCallback>(this);
|
||||
_equipSelector = entity.Get<IPlayerEquipSelector>();
|
||||
_equipSelector.OnEquip += OnEquip;
|
||||
_equipSelector.OnDeEquip += OnDeEquip;
|
||||
_equipSelector.OnUpdateEquip += OnUpdateEquip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user