ProcedureMenu.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using GameFramework.Event;
  8. using UnityGameFramework.Runtime;
  9. using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
  10. namespace MetaClient
  11. {
  12. public class ProcedureMenu : ProcedureBase
  13. {
  14. private bool m_StartGame = false;
  15. private MenuForm m_MenuForm = null;
  16. public override bool UseNativeDialog
  17. {
  18. get
  19. {
  20. return false;
  21. }
  22. }
  23. public void StartGame()
  24. {
  25. m_StartGame = true;
  26. }
  27. protected override void OnEnter(ProcedureOwner procedureOwner)
  28. {
  29. base.OnEnter(procedureOwner);
  30. GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
  31. m_StartGame = false;
  32. GameEntry.UI.OpenUIForm(UIFormId.MenuForm, this);
  33. }
  34. protected override void OnLeave(ProcedureOwner procedureOwner, bool isShutdown)
  35. {
  36. base.OnLeave(procedureOwner, isShutdown);
  37. GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
  38. if (m_MenuForm != null)
  39. {
  40. m_MenuForm.Close(isShutdown);
  41. m_MenuForm = null;
  42. }
  43. }
  44. protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
  45. {
  46. base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
  47. if (m_StartGame)
  48. {
  49. procedureOwner.SetData<VarInt32>("NextSceneId", GameEntry.Config.GetInt("Scene.Main"));
  50. procedureOwner.SetData<VarByte>("GameMode", (byte)GameMode.Survival);
  51. ChangeState<ProcedureChangeScene>(procedureOwner);
  52. }
  53. }
  54. private void OnOpenUIFormSuccess(object sender, GameEventArgs e)
  55. {
  56. OpenUIFormSuccessEventArgs ne = (OpenUIFormSuccessEventArgs)e;
  57. if (ne.UserData != this)
  58. {
  59. return;
  60. }
  61. m_MenuForm = (MenuForm)ne.UIForm.Logic;
  62. }
  63. }
  64. }