ModuleViewMgr.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using AppUI.Localization;
  2. using AppUI.Manager.View;
  3. using AppUI.View.Component;
  4. using SmartBowSDK;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. namespace AppUI.Manager
  8. {
  9. /// <summary>
  10. /// 参考 <see cref="PopupMgr"/>:全局入口单例,按需创建常驻节点并统一从 Resources 弹出 <see cref="ModuleView"/>。
  11. /// </summary>
  12. public class ModuleViewMgr : MonoBehaviour
  13. {
  14. static ModuleViewMgr _ins;
  15. public static ModuleViewMgr ins
  16. {
  17. get
  18. {
  19. if (_ins == null)
  20. {
  21. var go = new GameObject("ModuleViewMgr");
  22. DontDestroyOnLoad(go);
  23. _ins = go.AddComponent<ModuleViewMgr>();
  24. }
  25. return _ins;
  26. }
  27. }
  28. void OnDestroy()
  29. {
  30. if (_ins == this)
  31. _ins = null;
  32. }
  33. /// <summary>弹出对话框;在返回后设置各字段,本帧结束前会执行 <see cref="ModuleView.Start"/>。</summary>
  34. public void Show( string bodyText, UnityAction onAgree = null, bool dontDestroyOnLoad = false)
  35. {
  36. ModuleView m = ModuleView.Show();
  37. if (dontDestroyOnLoad)
  38. DontDestroyOnLoad(m.gameObject);
  39. m.text = bodyText;
  40. m.onAgree = onAgree;
  41. }
  42. /// <summary>正文使用多语言 key(走 <see cref="AppUILocalization"/>)。</summary>
  43. public ModuleView ShowLocalized(
  44. string bodyTextKey,
  45. object[] formatArgs,
  46. UnityAction onAgree = null,
  47. bool dontDestroyOnLoad = false)
  48. {
  49. ModuleView m = ModuleView.Show();
  50. if (dontDestroyOnLoad)
  51. DontDestroyOnLoad(m.gameObject);
  52. m.textKey = bodyTextKey;
  53. m.textFormatArgs = formatArgs ?? new object[] { };
  54. m.onAgree = onAgree;
  55. return m;
  56. }
  57. /// <summary>弹出侧滑面板(<see cref="ModuleSideSlip"/>)。</summary>
  58. public ModuleSideSlip ShowSideSlip(bool dontDestroyOnLoad = false, AimDeviceType? guideDeviceType = null)
  59. {
  60. return ModuleSideSlip.Show(dontDestroyOnLoad, guideDeviceType);
  61. }
  62. public ModuleViewHorizontal ShowDeviceConnectInfrared(bool dontDestroyOnLoad = false)
  63. {
  64. ModuleViewHorizontal m = ModuleViewHorizontal.Show();
  65. if (dontDestroyOnLoad)
  66. DontDestroyOnLoad(m.gameObject);
  67. m.text = AppUILocalization.GetTextByKey("appui-home-tip-infrared-required");
  68. m.onRejectTextKey = "appui-common-cancel";
  69. m.onAgreeTextKey = "appui-module-confirm";
  70. return m;
  71. }
  72. public ModuleViewHorizontal ShowDeviceConnect(bool dontDestroyOnLoad = false)
  73. {
  74. ModuleViewHorizontal m = ModuleViewHorizontal.Show();
  75. if (dontDestroyOnLoad)
  76. DontDestroyOnLoad(m.gameObject);
  77. m.text = AppUILocalization.GetTextByKey("appui-module-device-not-connect");
  78. m.onAgree = () => {
  79. ViewManager.ShowView(UIViewType.DeviceView);
  80. };
  81. //m.onAgree = onAgree;
  82. //m.onReject = onReject;
  83. m.onRejectTextKey = "appui-common-cancel";
  84. m.onAgreeTextKey = "appui-common-connect";
  85. return m;
  86. }
  87. public ModuleViewHorizontal ShowPositioning(bool dontDestroyOnLoad = false)
  88. {
  89. ModuleViewHorizontal m = ModuleViewHorizontal.Show();
  90. if (dontDestroyOnLoad)
  91. DontDestroyOnLoad(m.gameObject);
  92. m.text = AppUILocalization.GetTextByKey("appui-module-positioning-text");
  93. m.onAgree = () => {
  94. ViewManager.ShowView(UIViewType.InfraredView);
  95. };
  96. //m.onReject = onReject;
  97. m.onRejectTextKey = "appui-common-cancel";
  98. m.onAgreeTextKey = "appui-module-positioning";
  99. return m;
  100. }
  101. public ModuleViewHorizontal ShowResetScreenPositioning(bool dontDestroyOnLoad = false)
  102. {
  103. ModuleViewHorizontal m = ModuleViewHorizontal.Show();
  104. if (dontDestroyOnLoad)
  105. DontDestroyOnLoad(m.gameObject);
  106. m.text = AppUILocalization.GetTextByKey("appui-module-positioning-reset-text");
  107. m.onAgree = ()=> {
  108. ViewManager.ShowView(UIViewType.InfraredView);
  109. };
  110. //m.onReject = onReject;
  111. m.onRejectTextKey = "appui-common-cancel";
  112. m.onAgreeTextKey = "appui-module-confirm";
  113. return m;
  114. }
  115. }
  116. }