public EventHandler(ActionContainer targetActionContainer, float delay, CutsceneEvent cEvent, EEventHandlerType handlerType) { TargetActionContainer = targetActionContainer; Delay = delay; CEvent = cEvent; HandlerType = handlerType; }
/// <summary> /// 向Cutscene抛出一个自定义事件 /// </summary> /// <param name="id">Identifier.</param> protected void ThrowCustomEvent(int id) { // Debug.Log(string.Format("__________________________{0}::ThrowCustomEvent : {1}", GetType().Name, id)); CutsceneEvent newEvent = new CutsceneEvent(); newEvent.m_nCustomEventID = id; m_Events.Enqueue(newEvent); }
public bool IsTrigger(CutsceneEvent cEvent) { return(cEvent == CEvent); }
public void Update(float deltaTime) { if (m_State != ECutsceneState.Playing) { return; } //LogModule.DebugLog("__________________________________________ m_CurrentRunningAction.Count " + m_CurrentRunningAction.Count); // 更新正在跑的Action for (int i = m_CurrentRunningAction.Count - 1; i >= 0; i--) { // 判断有没有结束的Action if (m_CurrentRunningAction[i].Action.Finished) { // 触发结束事件 if (m_CurrentRunningAction[i].FinishEventHandler != null) { for (int j = m_CurrentRunningAction[i].FinishEventHandler.Count - 1; j >= 0; j--) { HandleEvent(m_CurrentRunningAction[i].FinishEventHandler[j]); } } // 处理完事件从当前列表删除 m_CurrentRunningAction.RemoveAt(i); } else { m_CurrentRunningAction[i].Action.Update(deltaTime); // 处理自定义事件 while (m_CurrentRunningAction[i].Action.HasEvent()) { CutsceneEvent cEvent = m_CurrentRunningAction[i].Action.GetEvent(); if (m_CurrentRunningAction[i].CustomEventHandler != null) { for (int j = m_CurrentRunningAction[i].CustomEventHandler.Count - 1; j >= 0; j--) { if (m_CurrentRunningAction[i].CustomEventHandler[j].IsTrigger(cEvent)) { HandleEvent(m_CurrentRunningAction[i].CustomEventHandler[j]); m_CurrentRunningAction[i].CustomEventHandler.RemoveAt(j); } } } } } } // 更新延时触发的Event for (int i = m_TimedEvent.Count - 1; i >= 0; i--) { EventHandler timedEvent = m_TimedEvent[i]; timedEvent.Delay = m_TimedEvent[i].Delay - deltaTime; if (timedEvent.Delay <= 0) { if (m_TimedEvent[i].HandlerType == EventHandler.EEventHandlerType.StartAction) { m_WaitToStartActionQueue.Enqueue(m_TimedEvent[i].TargetActionContainer); } if (m_TimedEvent[i].HandlerType == EventHandler.EEventHandlerType.FinishAction) { FinishAction(m_TimedEvent[i].TargetActionContainer); } m_TimedEvent.RemoveAt(i); } else { m_TimedEvent[i] = timedEvent; } } // 更新等待开始Action列表 for (int i = 0; i < m_nStartActionPerFrameNum; i++) { if (m_WaitToStartActionQueue.Count > 0) { ActionContainer ac = m_WaitToStartActionQueue.Dequeue(); StartAction(ac); } else { break; } } }