hch
9 小时以前 cba555476b1f1b856b9211451e739d8cdce0eeba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 
public class TimeDownMgr : SingletonMonobehaviour<TimeDownMgr> {
 
 
    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<float> 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<float> m_func;
        public Action<float> 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<CoolTimeData> coolTimeList = new List<CoolTimeData>();
 
    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--;
            }
        }
    }
 
 
}