-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cs
64 lines (59 loc) · 1.75 KB
/
Timer.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Timer : SingletonBehaviour<Timer>
{
//不知道用来做什么的词典
//public Dictionary<GameObject, float> dictGameObject;
public List<TimeEvent> listTimeEvent;
//为什么要用迭代器
public List<TimeEvent>.Enumerator enumTimeEvent;
//不知道用来做什么的列表
//public List<TimeEvent> listTimeup;
private Timer()
{
//this.dictGameObject = new Dictionary<GameObject, float>();
listTimeEvent = new List<TimeEvent>();
//listTimeup = new List<TimeEvent>();
}
// Use this for initialization
void Start () {
}
//固定时间刷新,在Update函数之前执行
private void FixedUpdate()
{
// enumTimeEvent = listTimeEvent.GetEnumerator();
// while (enumTimeEvent.MoveNext())
// {
// if (enumTimeEvent.Current != null)
// {
// enumTimeEvent.Current.UpdateCurrentTime();
// }
// }
}
// Update is called once per frame
void Update () {
}
//将计时器加入资源管理器中
public void AddTimer(TimeEvent timeEvent, float duration, Action callBack)
{
//如果不包含这个timeEvent
if (!listTimeEvent.Contains(timeEvent))
{
timeEvent.OnTimeupEvent = callBack;
timeEvent.HandleData(timeEvent.gameObject, duration);
listTimeEvent.Add(timeEvent);
}
//已经存在就将其销毁?
else
{
Destroy(timeEvent);
}
}
//将计时器从资源管理器中移除
public void RemoveTimer(TimeEvent timeEvent)
{
listTimeEvent.Remove(timeEvent);
}
}