TheInitialProject/Assets/Scripts/UI/Tips/TipHintUnit.cs
2024-10-23 16:59:02 +08:00

59 lines
1.5 KiB
C#

// Author: whc
// Desc:
using Game;
using Game.HotFix;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TipHintUnit : TipUnit
{
private static Color _warnColor = new Color(0.91f, 0.8f, 0.43f);
private static Color _errorColor = new Color(1f, 0.36f, 0.36f);
private RectTransform _rtfBg;
public override void Awake() {
tmpText = transform.Find("spBg/tmpText").GetComponent<TextMeshProUGUI>();
_rtfBg = transform.Find("spBg").GetComponent<RectTransform>();
}
public override void Refresh(TipData _Data)
{
base.Refresh(_Data);
HintData vData = _Data as HintData;
switch (vData.p_HintType)
{
case eHintType.Info:
tmpText.color = Color.white;
break;
case eHintType.Warn:
tmpText.color = _warnColor;
break;
case eHintType.Error:
tmpText.color = _errorColor;
break;
default:
Debug.LogError("not handle HintType:" + vData.p_HintType);
break;
}
LayoutRebuilder.ForceRebuildLayoutImmediate(_rtfBg);
StartCoroutine(AutoHide());
}
IEnumerator AutoHide()
{
yield return new WaitForSeconds(2f);
gameObject.SetActive(false);
//AppEntry.Event.Fire(null, ReduceTipHintEventArgs.Create(false));
Inform<bool>.Dispatch(eInformId.ReduceTipHintEventArgs, false);
}
}