/// <summary> /// 游戏初始化 /// </summary> void Awake() { // 防止重复创建 if (!IsSingle) { Destroy(gameObject); return; } // 主逻辑所挂接的gameObject不能在切换场景的时候删除。 DontDestroyOnLoad(gameObject); // 初始化系统管理器(注册器) gameObject.AddComponent <L_SystemRegister>(); // 初始化缓存池,创建一个根节点 gameObject.AddComponent <L_DataPool>(); // 初始化排行榜管理器 gameObject.AddComponent <L_RankManager>(); // 初始化状态机 m_stateMachine = new IStateMachine <L_Root, GameState>(this); // 注册状态 RegisterStates(); // 防止忘记设置初始化状态 if (m_stateMachine.CurrentState() == null) { Debuger.LogError("当前状态为NULL,请在注册函数中设置初始化状态!"); } // 游戏逻辑初始化完成,游戏启动 EventMachine.SendEvent(EventID.Event_GameLogicStart); }
public override void Start() { // 4秒后关闭loading ClockMachine.It.CreateClock(2, () => { EventMachine.SendEvent(EventID.Event_Loading, 1.0f); }); // 创建一个UI EventMachine.SendEvent(EventID.Event_UI_Create, UIType.UIPlay); // 注册事件 EventMachine.Register(EventID.Event_UI_Play_Back, OnPlayBack); // ... // 创建游戏规则 string playType = L_DataPool.Instance.FindChild("MenuData", "PlayType").GetValue <string>(); if (playType == "Singleplayer") { JudgeCreater.CreateJudge <L_Judge_Single>(); } if (playType == "TowPlayers") { JudgeCreater.CreateJudge <L_Judge_Towplay>(); } else if (playType == "Mulitiplayer") { //创建网络管理器并创建用户 JudgeCreater.CreateJudge <L_Judge_Network>(); } }
void OnDestroy() { // 注销事件 EventMachine.Unregister(EventID.Event_UI_Create, OnCreateUI); EventMachine.Unregister(EventID.Event_UI_Delete, OnDeleteUI); EventMachine.Unregister(EventID.Event_UI_DeleteAll, OnDeleteAllUI); }
public override void End() { // 移除一个UI EventMachine.SendEvent(EventID.Event_UI_Delete, UIType.UIPlay); // 注销事件 EventMachine.Unregister(EventID.Event_UI_Play_Back, OnPlayBack); // ... }
public override void End() { // 移除一个UI EventMachine.SendEvent(EventID.Event_UI_Delete, UIType.UIMenu); EventMachine.SendEvent(EventID.Event_UI_Create, UIType.UILoading); // 注销监听函数 EventMachine.Unregister(EventID.Event_UI_Menu_Play, OnPlay); EventMachine.Unregister(EventID.Event_UI_Menu_TwoPlay, OnTwoPlay); EventMachine.Unregister(EventID.Event_UI_Menu_Multiplayer, OnMultiplayer); }
/// <summary> /// Loads the scene. /// </summary> protected IEnumerator LoadAsynScene(string name) { AsyncOperation asynLoad = SceneManager.LoadSceneAsync(name); while (!asynLoad.isDone) { EventMachine.SendEvent(EventID.Event_Loading, asynLoad.progress); yield return(null); } EventMachine.SendEvent(EventID.Event_Loading, 1.0f); }
public override void CustomUpdate() { if (Input.GetKeyDown(KeyCode.Space)) { EventMachine.SendEvent(EventID.Event_UI_Create, UIType.UIRank); } if (Input.GetKeyDown(KeyCode.Alpha1)) { L_RankManager.Instance.ClearData("TestRank"); } }
public override void Start() { // 清空缓存数据 MenuData.ClearChildren(); // 注册监听函数 EventMachine.Register(EventID.Event_UI_Menu_Play, OnPlay); EventMachine.Register(EventID.Event_UI_Menu_TwoPlay, OnTwoPlay); EventMachine.Register(EventID.Event_UI_Menu_Multiplayer, OnMultiplayer); // 创建一个UI EventMachine.SendEvent(EventID.Event_UI_Create, UIType.UIMenu); }
void Awake() { // 如果已经初始化了,则不执行一下内容 if (!IsSingle) { Destroy(gameObject); return; } // 主逻辑所挂接的gameObject不能在切换场景的时候删除。 DontDestroyOnLoad(gameObject); // 注册UI RegisterUIs(); // 注册事件 EventMachine.Register(EventID.Event_UI_Create, OnCreateUI); EventMachine.Register(EventID.Event_UI_Delete, OnDeleteUI); EventMachine.Register(EventID.Event_UI_DeleteAll, OnDeleteAllUI); }
public void OnSinglePlayer() { EventMachine.SendEvent(EventID.Event_UI_Menu_Play); }
public void OnTwoPlayer() { EventMachine.SendEvent(EventID.Event_UI_Menu_TwoPlay); }
public void OnMultiplayer() { EventMachine.SendEvent(EventID.Event_UI_Menu_Multiplayer); }
void Awake() { EventMachine.Register(EventID.Event_Loading, OnLoadingProgress); }
void OnDestroy() { EventMachine.Unregister(EventID.Event_Loading, OnLoadingProgress); }
/// <summary> /// 更新,控制 /// </summary> public override void CustomUpdate() { if (m_Controller == null) { CreateCharacter(); } // 控制角色 Vector3 move = Vector3.down * 5; if (m_ID == 1) { if (Input.GetKey(KeyCode.W)) { move += Vector3.forward; } if (Input.GetKey(KeyCode.S)) { move -= Vector3.forward; } if (Input.GetKey(KeyCode.A)) { move += Vector3.left; } if (Input.GetKey(KeyCode.D)) { move -= Vector3.left; } move -= Vector3.left * Input.GetAxis("Joy1_LS-x"); move -= Vector3.forward * Input.GetAxis("Joy1_LS-y"); if (Input.GetButton("Joy1_A")) { move -= Vector3.forward; } if (Input.GetButton("Joy1_B")) { move += Vector3.forward; } } else { if (Input.GetKey(KeyCode.UpArrow)) { move += Vector3.forward; } if (Input.GetKey(KeyCode.DownArrow)) { move -= Vector3.forward; } if (Input.GetKey(KeyCode.LeftArrow)) { move += Vector3.left; } if (Input.GetKey(KeyCode.RightArrow)) { move -= Vector3.left; } /* * move -= Vector3.left * Input.GetAxis("Joy2_LS-x"); * move += Vector3.forward * Input.GetAxis("Joy2_LS-y"); * * if (Input.GetButton("Joy2_A")) move -= Vector3.forward; * if (Input.GetButton("Joy2_B")) move += Vector3.forward; */ } m_Controller.Move(move.normalized * Time.deltaTime * 20); if (Input.GetMouseButtonDown(0)) { EventMachine.SendEvent(EventID.Event_Effect_CameraVibration, 0.3f, Vector3.forward, 2); } Debug.LogWarning(Input.GetAxis("Joy1_Cross-x")); }
void Start() { m_em = new EventMachine(typeof(DbgMenuControl)); m_bReady = true; }
void Start() { m_em = new EventMachine(typeof(TestControl)); m_em.Start(); }
void Awake() { EventMachine.Register(EventID.Event_Effect_CameraVibration, OnCameraVibration); EventMachine.Register(EventID.Event_Effect_CameraAnimation, OnCameraAnimation); }
public void OnBack() { EventMachine.SendEvent(EventID.Event_UI_Play_Back); }
private void Start() { V = this; m_em = new EventMachine(typeof(MainControl)); m_em.Start(); }
void OnDestroy() { EventMachine.Unregister(EventID.Event_Effect_CameraVibration, OnCameraVibration); EventMachine.Unregister(EventID.Event_Effect_CameraAnimation, OnCameraAnimation); }
void Start() { m_em = new EventMachine(typeof(UITest01Control)); m_bReady = true; }
private void OnEnable() { EventMachine.SendEvent(EventID.Event_Effect_CameraVibration, Duration, Direction, Index); }