(client) feat:实现热重载,实现多维度,实现武器,实现掉落物,实现状态UI,实现攻击AI (#44)

Co-authored-by: zzdxxz <2079238449@qq.com>
Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
2025-08-27 19:56:49 +08:00
committed by TheRedApricot
parent d91210a6ff
commit 8456b6c162
132 changed files with 18568 additions and 2534 deletions

View File

@ -0,0 +1,91 @@
using System;
using Base;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UI
{
public class ItemUI:MonoBehaviour,IPointerEnterHandler,IPointerExitHandler,IPointerClickHandler,ITick
{
[SerializeField] private Image textureUI;
[SerializeField] private TMP_Text countUI;
[SerializeField] private TMP_Text nameUI;
[SerializeField] private GameObject selectedOutline;
private Entity.InventorySlot _item;
private float timer = 0;
private float switchTime = 0;
private int texturePtr = 0;
public event Action OnPlayerSelect;
public bool Select
{
get => selectedOutline.activeSelf;
set => selectedOutline.SetActive(value);
}
public int SlotIndex { get; private set; } = -1;
public void Init(Entity.InventorySlot item,int index)
{
if (item == null)
{
switchTime = -1;
textureUI.gameObject.SetActive(false);
countUI.text = "";
nameUI.text = "";
return;
}
textureUI.gameObject.SetActive(true);
_item = item;
textureUI.sprite = item.Item.Icon[0];
countUI.text = item.Quantity.ToString();
nameUI.text = item.Item.Name;
nameUI.gameObject.SetActive(false);
Select = false;
SlotIndex = index;
if (item.Item.FPS > 0)
{
switchTime = 1f / item.Item.FPS;
}
else
{
switchTime = 0;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
nameUI.gameObject.SetActive(true);
}
public void OnPointerExit(PointerEventData eventData)
{
nameUI.gameObject.SetActive(false);
}
public void OnPointerClick(PointerEventData eventData)
{
OnPlayerSelect?.Invoke();
}
public void Tick()
{
if (switchTime > 0)
{
timer+=Time.deltaTime;
if (timer >= switchTime)
{
timer-=switchTime;
texturePtr++;
texturePtr%=_item.Item.Icon.Count;
textureUI.sprite=_item.Item.Icon[texturePtr];
}
}
}
}
}