2023-08-27 02:58:19 +08:00
|
|
|
using System;
|
2023-06-08 14:09:50 +08:00
|
|
|
using System.Collections;
|
2023-08-27 02:58:19 +08:00
|
|
|
using System.Collections.Concurrent;
|
2023-06-08 14:09:50 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
2023-08-27 02:58:19 +08:00
|
|
|
using BITKit.Entities.Player;
|
2023-06-08 14:09:50 +08:00
|
|
|
using BITKit.UX;
|
|
|
|
using RotaryHeart.Lib.SerializableDictionary;
|
2023-08-27 02:58:19 +08:00
|
|
|
using UnityEngine.Playables;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
2023-06-08 14:09:50 +08:00
|
|
|
namespace BITFALL
|
|
|
|
{
|
|
|
|
public class UXEquipSelector : MonoBehaviour,IEquipSelectorCallback
|
|
|
|
{
|
2023-08-27 02:58:19 +08:00
|
|
|
[SerializeReference,SubclassSelector] private IPlayerService playerService;
|
2023-06-08 14:09:50 +08:00
|
|
|
[SerializeField]
|
|
|
|
private SerializableDictionaryBase<int, UXImage> dictionary = new();
|
|
|
|
[SerializeField] private UXImage currentUXEquip;
|
2023-08-27 02:58:19 +08:00
|
|
|
private readonly ConcurrentDictionary<int,IBasicItem> cache=new();
|
2023-06-08 14:09:50 +08:00
|
|
|
public void OnEquip(IBasicItem item)
|
|
|
|
{
|
|
|
|
var assets = item.GetAssetable();
|
|
|
|
currentUXEquip.SetTexture(assets.RectangleIcon);
|
|
|
|
}
|
|
|
|
public void OnDeEquip(IBasicItem item)
|
|
|
|
{
|
|
|
|
currentUXEquip.SetTexture(null);
|
|
|
|
}
|
2023-08-23 01:59:40 +08:00
|
|
|
public void OnUpdateEquip(IDictionary<int, IBasicItem> maps)
|
2023-06-08 14:09:50 +08:00
|
|
|
{
|
2023-08-27 02:58:19 +08:00
|
|
|
cache.Clear();
|
2023-06-08 14:09:50 +08:00
|
|
|
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);
|
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
|
|
|
|
cache.TryAdd(x.Key, item);
|
2023-06-08 14:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private void Start()
|
|
|
|
{
|
2023-08-27 02:58:19 +08:00
|
|
|
playerService.OnPlayerInitialized += OnStartLocalPlayer;
|
2023-06-08 14:09:50 +08:00
|
|
|
OnDeEquip(null);
|
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
playerService.OnPlayerInitialized -= OnStartLocalPlayer;
|
|
|
|
}
|
2023-06-08 14:09:50 +08:00
|
|
|
private void OnStartLocalPlayer(IEntity entity)
|
|
|
|
{
|
|
|
|
entity.RegisterCallback<IEquipSelectorCallback>(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|