示例#1
0
    // 延迟处理事件,若失效时间不为0则做失效处理
    private IEnumerator DelayOrExpireEvent(Loop.Event e, float delay, float expire)
    {
        yield return(new WaitForSeconds(delay));

        e.IsValid = true;
        e.ExecHanlders();
        Loop.EventManager.SyncFlag = false;

        // 失效处理
        if (expire != 0)
        {
            yield return(new WaitForSeconds(expire));

            e.IsValid = false;
        }
    }
示例#2
0
    // 取事件队列并执行(区分同步和异步事件的执行方式)
    public IEnumerator PopAndExecEvent()
    {
        if (!Loop.EventManager.IsEventQueueEmpty() && !Loop.EventManager.SyncFlag)
        {
            _currentEventIndex = Loop.EventManager.PopEventQueue();
            Loop.Event currentEvent = Loop.EventManager.EventArray[_currentEventIndex];

            // 出队事件是否是异步执行
            if (currentEvent.IsAsync)
            {
                Loop.EventManager.SyncFlag = false;
            }
            else
            {
                Loop.EventManager.SyncFlag = true;
            }

            Debug.Log("Pop Event Queue and execute Event : " + (Loop.EventType)currentEvent.Index);
            float cd = currentEvent.DelayPeriod;
            float ce = currentEvent.ExpiredPeriod;

            if (cd != 0 || ce != 0)
            {
                yield return(StartCoroutine(DelayOrExpireEvent(currentEvent, cd, ce)));
            }
            else
            {
                currentEvent.IsValid = true;
                currentEvent.ExecHanlders();
                Loop.EventManager.SyncFlag = false;
            }
        }
        else if (Loop.EventManager.SyncFlag)
        {
            yield return(null);
        }
    }