Beispiel #1
0
        public TimerData(uint oid, TimerCallback callback, object param, float delay, float time, float repeatRate, object tag, RepeatCallRemoveCallback repeatCallRemove)
        {
            state                 = TimerState.PeddingForInit;
            this.oid              = oid;
            this.callback         = callback;
            this.param            = param;
            this.delay            = delay;
            this.durationTime     = time;
            this.repeatRate       = repeatRate;
            this.repeatCallRemove = repeatCallRemove;
            this.tag              = tag;

            m_DurationTimer          = 0;
            m_DelayTimerCounter      = 0;
            m_RepeatRateTimerCounter = repeatRate;
        }
Beispiel #2
0
    /// <summary>
    /// 添加定时器
    /// </summary>
    /// <param name="callback">回调</param>
    /// <param name="param">自定义参数</param>
    /// <param name="delay">延迟触发</param>
    /// <param name="time">持续时间,小于0时为无限</param>
    /// <param name="repeatRate">调用的频率</param>
    /// <param name="repeatCallRemoveCallback">结束后的回调</param>
    /// <returns></returns>
    public uint AddTimer(TimerCallback callback, object param, float delay, float time, float repeatRate, object tag = null, RepeatCallRemoveCallback repeatCallRemoveCallback = null)
    {
        if (callback != null && (delay > 0f || time != 0f))
        {
            uint oid = 0;
            if (time != 0f && repeatRate <= 0f)
            {
                Debug.LogError("定时器的调用频率不能小于0");
                return(oid);
            }

            do
            {
                oid = Untility.GuidCreator.GetOid();
            }while (m_TimerList.ContainsKey(oid));

            m_PeddingInitTimerList.Add(new TimerData(oid, callback, param, delay, time, repeatRate, tag, repeatCallRemoveCallback));
            return(oid);
        }
        else
        {
            return(0);
        }
    }