HomeMgr.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using JCUnityLib;
  5. /* Home场景管理者 */
  6. public class HomeMgr : MonoBehaviour
  7. {
  8. public static HomeMgr ins;
  9. void Awake()
  10. {
  11. ins = this;
  12. PersistenHandler.Init();
  13. ViewMgr.Instance.ShowView<TopBarView>();
  14. ViewMgr.Instance.ShowView<HomeView>();
  15. ViewMgr.Instance.ShowView<HomeFrameView>();
  16. Instantiate(SceneResourceManager.Instance.GetPrefab("DeviceBatteryView"));
  17. Instantiate(SceneResourceManager.Instance.GetPrefab("AuthLoginMask"));
  18. Instantiate(SceneResourceManager.Instance.GetPrefab("RenderBowCamera"));
  19. Instantiate(SceneResourceManager.Instance.GetPrefab("NewUserGuiderManager"));
  20. //标记某些界面不需要销毁
  21. ViewMgr.Instance.SetViewDontDestroy<GameStartView>();
  22. ViewMgr.Instance.SetViewDontDestroy<ChallengeOptionView>();
  23. ViewMgr.Instance.SetViewDontDestroy<RoleSelectView>();
  24. ViewMgr.Instance.SetViewDontDestroy<PKGameOptionView>();
  25. ViewMgr.Instance.SetViewDontDestroy<PKMatchView>();
  26. //显示缓存的隐藏页面
  27. ViewMgr.Instance.ResumeView<GameStartView>();
  28. ViewMgr.Instance.ResumeView<ChallengeOptionView>();
  29. ViewMgr.Instance.ResumeView<RoleSelectView>();
  30. ViewMgr.Instance.ResumeView<PKGameOptionView>();
  31. ViewMgr.Instance.ResumeView<PKMatchView>();
  32. }
  33. void Start()
  34. {
  35. Time.timeScale = 1; //保证时间缩放为1
  36. if (CommonConfig.StandaloneMode)
  37. {
  38. DoTweenUtil.CallDelay(0.1f, () => new UserPlayer());
  39. if (StandaloneAPI.InitTimeCounter())
  40. {
  41. //生成支付相关的SerialPortObj
  42. GameObject obj = Instantiate(SceneResourceManager.Instance.GetPrefab("SerialPortObj"));
  43. obj.name = "SerialPortObj";
  44. obj.GetComponent<PayGameMode>().setQRPlanObjActive(true);
  45. }
  46. }
  47. else UserPlayer.ConnectServer();
  48. }
  49. void OnDestroy()
  50. {
  51. if (ins == this) ins = null;
  52. ViewMgr.Instance.DestroyAllViewsExcludeDontDestroy();
  53. //隐藏可缓存的页面
  54. ViewMgr.Instance.HideView<GameStartView>();
  55. ViewMgr.Instance.HideView<ChallengeOptionView>();
  56. ViewMgr.Instance.HideView<RoleSelectView>();
  57. ViewMgr.Instance.HideView<PKGameOptionView>();
  58. ViewMgr.Instance.HideView<PKMatchView>();
  59. }
  60. }