예제 #1
0
    /// <summary>
    /// 每帧执行回调函数
    /// </summary>
    public object RegisterFrameTimer(TimerEleCallBack callBack, int loopCount = -1, bool isTimeScale = true, bool immRun = false,
                                     float life = -1, TimerEleCallBack endCB = null)
    {
        TimerElement element = GetFreeElement();

        element.type           = 1;
        element.key            = GetUid();
        element.isTimeScale    = isTimeScale;
        element.loopCountLimit = loopCount;
        element.callback       = callBack;
        element.life           = life;
        element.endCB          = endCB;

        if (immRun)
        {
            element.Execute();
        }

        if (!element.isFinish)
        {
            _timerList.Add(element);
        }
        else
        {
            element.OnDestroy();
        }

        return(element.key);
    }
예제 #2
0
    /// <summary>
    /// 每隔多长时间执行一次
    /// </summary>
    /// <param name="key">注册key</param>
    /// <param name="duration">间隔时间</param>
    /// <param name="callBack">事件回调</param>
    /// <param name="isTimeScale">是否受TimeScale影响</param>
    /// <param name="loopCount">循环次数,小于0为无限循环</param>
    /// <param name="life">生命周期,如果同时指定loopCount,谁先到执行finish</param>
    /// <param name="endCB">结束回调</param>
    /// <param name="immRun">立即执行</param>
    public void RegisterCDTimer(object key, float duration, TimerEleCallBack callBack, bool isTimeScale = true, bool immRun = false,
                                int loopCount = 1, float life = -1, TimerEleCallBack endCB = null)
    {
        if (callBack == null)
        {
            return;
        }
        TimerElement element = GetFreeElement();

        element.type           = 0;
        element.key            = key;
        element.duration       = duration;
        element.isTimeScale    = isTimeScale;
        element.callback       = callBack;
        element.loopCountLimit = loopCount;
        element.life           = life;
        element.endCB          = endCB;

        if (immRun)
        {
            element.Execute();
        }

        if (!element.isFinish)
        {
            _timerList.Add(element);
        }
        else
        {
            element.OnDestroy();
        }
    }
예제 #3
0
 private void TimerElementRelease(TimerElement element)
 {
     element.OnDestroy();
     _elementPool.Push(element);
 }