Unity3d Game Development Framework-time management class, set time execution method.

Source: Internet
Author: User
Tags set time

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 &GT
            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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.