商店除发放和货币扣除,其余部分完毕。加入药水icon免费包
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class storeItemPrefab : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[Header("so")]
|
||||
public storeItemSO thisItemSO;
|
||||
|
||||
[Header("basics")]
|
||||
public Image thisItem_iconImage;
|
||||
public Text thisItem_nameText;
|
||||
public Text thisItem_amountAndLimitationText;
|
||||
public Image thisPrice_iconImage;
|
||||
public Text thisItem_priceText;
|
||||
|
||||
[Header("other")]
|
||||
public GameObject rightCorner_statusImage; //这个是用来显示限量或新品等状态的图标
|
||||
public GameObject leftCorner_statusImage; //这个是用来显示售罄等状态的图标
|
||||
public GameObject lock_cannotClickImage; //这个是用来显示无法点击的锁图标的
|
||||
|
||||
[Header("texts")]
|
||||
public Text why_cannot_buy;
|
||||
|
||||
[Header("descriptions")]
|
||||
public GameObject descriptionObject;
|
||||
public Text itemTitle;
|
||||
public Text itemDescription;
|
||||
|
||||
public Action<storeItemPrefab> onItemClicked;
|
||||
|
||||
private const float ShowDelay = 0.5f;
|
||||
private const float HideDelay = 0.25f;
|
||||
private const float FadeDuration = 0.2f;
|
||||
|
||||
private CanvasGroup descriptionCanvasGroup;
|
||||
private Coroutine pendingShowCoroutine;
|
||||
private Coroutine pendingHideCoroutine;
|
||||
private int lastNotifyFrame = -1;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
PrepareDescriptionPanel();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
StopPendingDescriptionCoroutines();
|
||||
if (descriptionCanvasGroup != null)
|
||||
{
|
||||
descriptionCanvasGroup.DOKill();
|
||||
descriptionCanvasGroup.alpha = 0f;
|
||||
descriptionCanvasGroup.interactable = false;
|
||||
descriptionCanvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
|
||||
if (descriptionObject != null)
|
||||
{
|
||||
descriptionObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
NotifyClicked();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (descriptionObject == null) return;
|
||||
|
||||
if (pendingHideCoroutine != null)
|
||||
{
|
||||
StopCoroutine(pendingHideCoroutine);
|
||||
pendingHideCoroutine = null;
|
||||
}
|
||||
|
||||
if (pendingShowCoroutine == null)
|
||||
{
|
||||
pendingShowCoroutine = StartCoroutine(ShowDescriptionWithDelay());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (descriptionObject == null) return;
|
||||
|
||||
if (pendingShowCoroutine != null)
|
||||
{
|
||||
StopCoroutine(pendingShowCoroutine);
|
||||
pendingShowCoroutine = null;
|
||||
}
|
||||
|
||||
if (pendingHideCoroutine == null)
|
||||
{
|
||||
pendingHideCoroutine = StartCoroutine(HideDescriptionWithDelay());
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyClicked()
|
||||
{
|
||||
if (lastNotifyFrame == Time.frameCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastNotifyFrame = Time.frameCount;
|
||||
if (onItemClicked != null)
|
||||
{
|
||||
onItemClicked(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDescriptionContent(string title, string description)
|
||||
{
|
||||
if (itemTitle != null)
|
||||
{
|
||||
itemTitle.text = title ?? string.Empty;
|
||||
}
|
||||
|
||||
if (itemDescription != null)
|
||||
{
|
||||
itemDescription.text = string.IsNullOrWhiteSpace(description) ? "暂无描述信息" : description;
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareDescriptionPanel()
|
||||
{
|
||||
if (descriptionObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
descriptionCanvasGroup = descriptionObject.GetComponent<CanvasGroup>();
|
||||
if (descriptionCanvasGroup == null)
|
||||
{
|
||||
descriptionCanvasGroup = descriptionObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
descriptionCanvasGroup.DOKill();
|
||||
descriptionCanvasGroup.alpha = 0f;
|
||||
descriptionCanvasGroup.interactable = false;
|
||||
descriptionCanvasGroup.blocksRaycasts = false;
|
||||
descriptionObject.SetActive(false);
|
||||
}
|
||||
|
||||
private IEnumerator ShowDescriptionWithDelay()
|
||||
{
|
||||
yield return new WaitForSeconds(ShowDelay);
|
||||
pendingShowCoroutine = null;
|
||||
ShowDescriptionPanel();
|
||||
}
|
||||
|
||||
private IEnumerator HideDescriptionWithDelay()
|
||||
{
|
||||
yield return new WaitForSeconds(HideDelay);
|
||||
pendingHideCoroutine = null;
|
||||
HideDescriptionPanel();
|
||||
}
|
||||
|
||||
private void ShowDescriptionPanel()
|
||||
{
|
||||
if (descriptionObject == null || descriptionCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
descriptionCanvasGroup.DOKill();
|
||||
descriptionObject.SetActive(true);
|
||||
descriptionCanvasGroup.interactable = true;
|
||||
descriptionCanvasGroup.blocksRaycasts = true;
|
||||
descriptionCanvasGroup.DOFade(1f, FadeDuration).SetEase(Ease.OutQuad);
|
||||
}
|
||||
|
||||
private void HideDescriptionPanel()
|
||||
{
|
||||
if (descriptionObject == null || descriptionCanvasGroup == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
descriptionCanvasGroup.DOKill();
|
||||
descriptionCanvasGroup.interactable = false;
|
||||
descriptionCanvasGroup.blocksRaycasts = false;
|
||||
descriptionCanvasGroup.DOFade(0f, FadeDuration)
|
||||
.SetEase(Ease.OutQuad)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
if (descriptionObject != null)
|
||||
{
|
||||
descriptionObject.SetActive(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void StopPendingDescriptionCoroutines()
|
||||
{
|
||||
if (pendingShowCoroutine != null)
|
||||
{
|
||||
StopCoroutine(pendingShowCoroutine);
|
||||
pendingShowCoroutine = null;
|
||||
}
|
||||
|
||||
if (pendingHideCoroutine != null)
|
||||
{
|
||||
StopCoroutine(pendingHideCoroutine);
|
||||
pendingHideCoroutine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user