/// <summary> /// Add a function that will be called whenever an event is dispatched /// GARBAGE COLLECTION WILL NOT REMOVE EVENTS, YOU MUST DO THIS BEFORE OBJECT DESTRUCTION OR THERE WILL BE MEMORY LEAKS /// </summary> /// <param name="type"> The event you want to listen for</param> /// <param name="callback">The Function that you wish to recieve the response(MUST TAKE IN A System.Object param) </param> public void AddEventListener(EngineEvents type, Action <System.Object> callback) { if (_eventList.ContainsKey(type)) { _eventList[type].AddListener(callback); } }
/// <summary> /// Remove a function that was being called whenever an event is dispatched /// </summary> /// <param name="type"> The event you were listening for</param> /// <param name="callback">The Function that was recieving the response(MUST TAKE IN A System.Object param) </param> public void RemoveEventListener(EngineEvents type, Action <System.Object> callback) { if (_eventList.ContainsKey(type)) { AEvent someEvent = new AEvent(_eventList[type]); someEvent.RemoveListener(callback); _eventList[type] = someEvent; } }
/// <summary> /// Dispatch an EngineEvent. /// </summary> /// <param name="type"> The event you wish to disatch</param> public void Dispatch(EngineEvents type) { if (_eventList.ContainsKey(type)) { _eventList[type].Dispatch(); } else { Debug.LogWarning("Warning: No currenlty registered listners for event :" + type); } }
public override void installEvents() { base.installEvents(); EngineEvents.InstallEvents(); if (!LogicEvents.Check()) { Dbg.ERROR_MSG("clientapp::installEvents:逻辑事件检查失败,可能有重名!"); Destroy(this); return; } GameCore.ResourceManager.Instance.Init(); LogicSceneMgr.Instance.Init(); }
/// <summary> /// 检查是否与引擎内置的事件名冲突 /// </summary> /// <returns></returns> public static bool Check() { List <string> events = EngineEvents.GetEngineEventNames(); //Debug.Log("LogicEvents::Check:" + events.Count); if (!_AccountEvents_In.Check(events)) { return(false); } if (!_AccountEvents_Out.Check(events)) { return(false); } //Debug.Log("LogicEvents::Check:" + events.Count); return(true); }
private void CheckState(EngineEvents type) { switch (type) { case EngineEvents.ENGINE_GAME_START: _stateMachine.SetState(EngineState.ACTIVE); break; case EngineEvents.ENGINE_GAME_RESUME: _stateMachine.SetState(EngineState.ACTIVE); break; case EngineEvents.ENGINE_STAGE_COMPLETE: _stateMachine.SetState(EngineState.STAGE_END); break; case EngineEvents.ENGINE_LOAD_START: _stateMachine.SetState(EngineState.LOADING_STATE); break; case EngineEvents.ENGINE_GAME_PAUSE: _stateMachine.SetState(EngineState.MENU); break; case EngineEvents.ENGINE_GAME_OVER: _stateMachine.SetState(EngineState.PLAYER_DEAD); break; case EngineEvents.ENGINE_CUTSCENE_START: _stateMachine.SetState(EngineState.CUTSCENES); break; // default: return; } _StateChangeEvent.Dispatch(type); }