装备系统完结,修复并加入很多
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class uBagItemPrefab : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[Header("ui")]
|
||||
public Image itemIcon;
|
||||
public TMP_Text itemCount;
|
||||
public Image itemBtmImg;
|
||||
|
||||
private uBag owner;
|
||||
private Coroutine hoverRoutine;
|
||||
private float hoverDelaySeconds = 0.5f;
|
||||
|
||||
public void Bind(uBag bagOwner, Sprite icon, string countText, Color backgroundColor, float hoverDelay)
|
||||
{
|
||||
owner = bagOwner;
|
||||
hoverDelaySeconds = hoverDelay > 0f ? hoverDelay : 0.5f;
|
||||
|
||||
if (itemIcon != null)
|
||||
{
|
||||
itemIcon.sprite = icon;
|
||||
itemIcon.enabled = icon != null;
|
||||
itemIcon.color = Color.white;
|
||||
}
|
||||
|
||||
if (itemCount != null)
|
||||
{
|
||||
itemCount.text = countText ?? string.Empty;
|
||||
}
|
||||
|
||||
if (itemBtmImg != null)
|
||||
{
|
||||
itemBtmImg.color = backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (owner == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CancelHover();
|
||||
hoverRoutine = StartCoroutine(HoverDelay());
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
CancelHover();
|
||||
if (owner != null)
|
||||
{
|
||||
owner.HidePreviewFor(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (owner == null || eventData == null || eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
owner.SelectItemForDetail(this);
|
||||
}
|
||||
|
||||
private IEnumerator HoverDelay()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(hoverDelaySeconds);
|
||||
hoverRoutine = null;
|
||||
if (owner != null)
|
||||
{
|
||||
owner.ShowPreviewFor(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
CancelHover();
|
||||
if (owner != null)
|
||||
{
|
||||
owner.HidePreviewFor(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelHover()
|
||||
{
|
||||
if (hoverRoutine != null)
|
||||
{
|
||||
StopCoroutine(hoverRoutine);
|
||||
hoverRoutine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user