zoukankan      html  css  js  c++  java
  • Github

    https://github.com/pointcache/Unity3d-Timers

    Unity3d-Timers

    Timer class with various behaviors

    About: Have a system allowing to easily create and extend complex timer behaviors.

    Usage:

    //Start simple repeater 
    Timer.Repeater(5f, () => Debug.Log("Repeater test"));
    //Start countdown and call Draw in 2.5 seconds
    Timer.Countdown(2.5f, Draw);

    Concept: A manager class pools and constructs new timers, timer store up to 4 handlers, and arbitrarely raise events in concrete implementation.

    private class CountdownBehavior : TimerBehaviorBase, ITimerBehavior
    {
        float exitTime;
        public void Initialize()
        {
            exitTime = f1;
        }
    
        public void Update(float deltaTime)
        {
            TimePassed += deltaTime;
            TotalTimeActive += deltaTime;
    
            if (TimePassed > exitTime)
            {
                Completed = true;
                c1();
            }
        }
    }
    

    Countdown inherits TimerBehaviorBase and implements ITimerBehavior. On top of that only concrete behavior in implemented that uses data and callbacks provided in constructor:

    public static Timer Countdown(float exitTime, Action callback)
    {
        Timer timer = TimerManager.getTimer();
        timer.SetBehavior<CountdownBehavior>();
        timer.behaviorBase
            .SetFloats(exitTime, 0, 0, 0)
            .SetCallbacks(callback, null, null, null);
        timer.behavior.Initialize();
        return timer;
    }
    

    as you can see you can set 4 floats, and 4 callbacks and use them in your implementation of behavior as you like. Examples 

    For concrete real example look at Ability class, it implements typical game ability, with cooldown.

  • 相关阅读:
    Hdu1711 Number Sequence--Kmp模板题
    Trie入门--Poj3630 Phone List,查单词,HDU1251 统计前缀,PKU2503 Babelfish
    高次幂的组合数表示形式
    BZOJ1697 [Usaco2007 Feb] Cow Sorting牛排序
    1025 [SCOI2009]游戏(置换群,DP)
    Poj1721 Cards
    [Poi2003]Shuffle
    poj 3128 Leonardo's Notebook(置换的幂)
    POJ3734 Block母函数入门
    重心拉格朗日插值法
  • 原文地址:https://www.cnblogs.com/mimime/p/6995427.html
Copyright © 2011-2022 走看看