AkiraPixelWind/Assets/Scripts/Main/UI/UIMgr/Tips/TipHintUnit.cs
2022-12-29 18:20:40 +08:00

50 lines
1.2 KiB
C#

// Author: whc
// Desc:
using System;
using System.Collections;
using System.Collections.Generic;
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() {
m_txtText = transform.Find("spBg/txtText").GetComponent<Text>();
_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:
m_txtText.color = Color.white;
break;
case eHintType.Warn:
m_txtText.color = _warnColor;
break;
case eHintType.Error:
m_txtText.color = _errorColor;
break;
}
LayoutRebuilder.ForceRebuildLayoutImmediate(_rtfBg);
StartCoroutine(AutoHide());
}
IEnumerator AutoHide()
{
yield return new WaitForSeconds(2f);
gameObject.SetActive(false);
}
}