Files
Main/Assets/GameAssets/Resources/GameUI/Common/AlphaUtils/NoticeIconAlphaAnim.cs
2025-01-25 04:38:09 +08:00

108 lines
2.8 KiB
C#

using Thousandto.Core.Base;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using PathUtils = UnityEngine.Gonbest.MagicCube.PathUtils;
using CoroutinePool = UnityEngine.Gonbest.MagicCube.CoroutinePool;
using StringUtils = UnityEngine.Gonbest.MagicCube.StringUtils;
namespace Thousandto.Plugins.Common
{
/// <summary>
/// UISprite组件的alpha动画
/// </summary>
public class NoticeIconAlphaAnim
{
//所有的提示动画,每一个聊天对象都有一个
private List<UISprite> _noticeList;
//是否显示私聊提示动画
private bool _enabelNotice;
private static NoticeIconAlphaAnim _instance;
public static NoticeIconAlphaAnim Instance
{
get
{
if (_instance == null)
{
_instance = new NoticeIconAlphaAnim();
}
return _instance;
}
set { NoticeIconAlphaAnim._instance = value; }
}
private NoticeIconAlphaAnim()
{
Initialize();
}
public void Initialize()
{
_enabelNotice = true;
_noticeList = new List<UISprite>();
CoroutinePool.AddTask(showNotice());
}
public void Unitialize()
{
_enabelNotice = false;
if (_noticeList != null)
{
_noticeList.Clear();
}
}
public void AddNoticeIcon(UISprite go)
{
if (!_noticeList.Contains(go))
{
_noticeList.Add(go);
TweenAlpha sa = go.gameObject.RequireComponent<TweenAlpha>();
sa.from = 1.0f;
sa.to = 0.0f;
sa.enabled = true;
sa.style = UITweener.Style.PingPong;
sa.PlayForward();
}
}
IEnumerator showNotice()
{
yield return null;
while (_enabelNotice)
{
yield return new WaitForSeconds(0.2f);
for (int i = _noticeList.Count - 1; i >= 0; i--)
{
try
{
if (_noticeList[i] == null || !_noticeList[i].gameObject.activeInHierarchy)
{
_noticeList.RemoveAt(i);
continue;
}
}
catch (System.Exception ex)
{
UnityEngine.Debug.LogError(ex.StackTrace);
_noticeList.RemoveAt(i);
continue;
}
}
}
}
}
}