using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TimeDownMgr : SingletonMonobehaviour { public enum CoolTimeType { Test=0, BagSort=1, DepotSort=2, DeadCD = 3, //距离玩家复活的时间 DeadTiredCD = 4, //距离清除玩家复活疲劳的时间 BossAutoReborn = 5, //在Boss附近被玩家击杀复活 DuplicatesReborn = 6, //副本死亡类型 SyncServerTime=7,//同步服务器时间 HeavenBattleReaminTime = 8, //仙魔之争剩余时间 prepareBetRemainTime = 9, //最终比分预测 firstBetRemainTime = 10, //第一阶段比分预测 secondBetRemainTime = 11, //第二阶段比分预测 thirdBetRemainTime = 12, //第三阶段比分预测 BattlePrepareTime = 13, //战斗前倒计时 HappyFreeBestXB = 14,//极品寻宝免费时间倒计时 废弃 HappyFreeRuneXB = 15, //符印寻宝免费时间倒计时 废弃 HappyXBWarehouse = 16, //寻宝仓库整理倒计时 FlashRushToBuyAppointment = 17, //限时抢购预约倒计时 DungeonAssistCoolTime = 18, //副本助战一键召唤倒计时 } public void Begin(CoolTimeType type, float duration,Action func,float tick=1.0f) { CoolTimeData data = coolTimeList.Find((CoolTimeData x) => { return x.type==type; }); if (data != null) { coolTimeList.Remove(data); data = null; } data = new CoolTimeData(); data.time = 0; data.type = type; data.tick = tick; data.duration = duration; data.func = func; coolTimeList.Add(data); } public void Stop(CoolTimeType type) { CoolTimeData value = null; if (Get(type,out value)) { coolTimeList.Remove(value); } } public bool Get(CoolTimeType type,out CoolTimeData value) { CoolTimeData data = coolTimeList.Find((CoolTimeData x) => { return x.type == type; }); value = null; if (data!=null) { value = data; return true; } return false; } public class CoolTimeData { public CoolTimeType type; public float tick; public float duration; public float time; private Action m_func; public Action func { get { return m_func; } set { if (m_func == null) m_func = value; else { if (Array.IndexOf(m_func.GetInvocationList(), value) == -1) { m_func += value; } } } } } private List coolTimeList = new List(); private void LateUpdate() { for (int i = 0; i < coolTimeList.Count; i++) { CoolTimeData data = coolTimeList[i]; data.time += Time.deltaTime; if (data.time >= data.tick) { if (data.func != null) data.func(Mathf.CeilToInt(data.duration-data.time)); data.tick += 1; data.tick = Mathf.Min(data.tick, data.duration); } if (data.time >= data.duration) { data = null; coolTimeList.RemoveAt(i); i--; } } } }