-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaitTimeManager.cs
41 lines (38 loc) · 1016 Bytes
/
WaitTimeManager.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class WaitTimeManager
{
private static TaskBehaviour m_Task;
static WaitTimeManager()
{
GameObject go = new GameObject("#WaitTimeManager#");
GameObject.DontDestroyOnLoad(go);
m_Task = go.AddComponent<TaskBehaviour>();
}
//等待
static public Coroutine WaitTime(float time, UnityAction callback)
{
return m_Task.StartCoroutine(Coroutine(time, callback));
}
//取消等待
static public void CancelWait(ref Coroutine coroutine)
{
if (coroutine != null)
{
m_Task.StopCoroutine(coroutine);
coroutine = null;
}
}
static IEnumerator Coroutine(float time, UnityAction callback)
{
yield return new WaitForSeconds(time);
if (callback != null)
{
callback();
}
}
//内部类
class TaskBehaviour : MonoBehaviour { }
}