Coder Social home page Coder Social logo

unitimer's Introduction

UniTimer

一个为Unity3D编写的简单的时间管理器,提供了延迟(TimerAfter)、前置(TimerBefore)、重复(TimerRepeat)三种Timer。

代码示例

using UnityEngine;
using System.Collections;
using UniTimer;

public class Example : MonoBehaviour {

	
	void Start () 
    {
        //在2.5s后触发一个事件然后销毁自身
        TimeManager.Get().RegisterTimer(
            new TimerAfter(Time.time, 2.5f, (t)=>{ Debug.Log("时间到!"); }));

        //在时间到达10s前显示一个倒计时时间到达后销毁自身
        TimeManager.Get().RegisterTimer(
            new TimerBefore(Time.time, 10f, (t)=> { Debug.Log("距离10s还有"+ (10-t) + "s"); }));

        //每隔2.5s触发一个事件
        TimeManager.Get().RegisterTimer(
            new TimerRepeat(Time.time, 2.5f, (time) => { Debug.Log("我每隔2.5s触发一次"); }));

        //在2.5s后每隔10s触发一个事件
        TimeManager.Get().RegisterTimer(
            new TimerAfter(Time.time, 2.5f, (t) =>
            {
                TimeManager.Get().RegisterTimer(
                    new TimerRepeat(t, 10f, (time) => { Debug.Log("这是一个混合使用Timer的例子"); }));
            }));
	}



}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.