This article pinned Link: http://blog.csdn.net/u013108312/article/details/54378613
Using Unityengine;
Using System.Collections;
Using System.Collections.Generic;
Using System;
public class Timemgr:monobehaviour {private static timemgr minstance;
public static Timemgr Instance {get {return minstance;
}} public delegate void Interval ();
Private Dictionary<interval, float> mdicinterval = new Dictionary<interval, float> (); public void Addinterval (Interval interval,float time) {if (null! = Interval) Mdicinterval[interval] =
Time.time + time; The public void Removeinterval (Interval Interval) {if (null! = Interval) {if (mDic Interval.
ContainsKey (interval)) {mdicinterval.remove (interval);
}}}//Awake is called then the script instance is being loaded.
void Awake () {minstance = this; } void Update () {if (Mdicinterval.count >
0) {list<interval> remove = new list<interval> (); foreach (keyvaluepair<interval,float> KeyValue in Mdicinterval) {if (Keyvalue.value < = Time.time) {Remove.
ADD (Keyvalue.key); }} for (int i = 0; i < remove.
count;i++) {remove[i] ();
Mdicinterval.remove (Remove[i]);
}
}
}
}
Test
void Start ()
{
TimeMgr.Instance.AddInterval (TestCall1, 3f);
}
void TestCall1 ()
{
debug.logerror ("Testcall_1");
TimeMgr.Instance.AddInterval (TestCall2, 2f);
}
void TestCall2 ()
{
debug.logerror ("testcall_2");
TimeMgr.Instance.AddInterval (TESTCALL1, 5f);
}
This article fixed link: http://blog.csdn.net/u013108312/article/details/54378613