HomeViewBottomBar.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using AppUI.Bluetooth;
  2. using AppUI.Localization;
  3. using AppUI.Manager;
  4. using AppUI.Manager.View;
  5. using AppUI.Util.TabSwitcher;
  6. using AppUI.View.Home.UserCenter;
  7. using InfraredManager;
  8. using SmartBowSDK;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using UnityEngine;
  13. using UnityEngine.UI;
  14. namespace AppUI.View.Home.Main
  15. {
  16. public class HomeViewBottomBar : MonoBehaviour
  17. {
  18. void Start()
  19. {
  20. Dictionary<string, Transform> actionMap = new Dictionary<string, Transform>
  21. {
  22. { "IconConnect", null },
  23. { "IconScreen", null },
  24. //{ "IconGuider", null },
  25. //{ "IconShop", null },
  26. //{ "IconNewUser", null },
  27. //{ "IconFriend", null },
  28. { "IconRank", null },
  29. { "IconSetUp", null }
  30. };
  31. SortChildObjects(actionMap);
  32. // 按条件禁用特定按钮的交互性
  33. if (CommonConfig.StandaloneMode)
  34. {
  35. DisableButtonInteractivity(actionMap, new List<string> { "IconGuider", "IconFriend", "IconRank" });
  36. }
  37. }
  38. void DisableButtonInteractivity(Dictionary<string, Transform> actionMap, List<string> buttonNames)
  39. {
  40. foreach (var buttonName in buttonNames)
  41. {
  42. // 检查 actionMap 中是否有该键且对应的 Transform 不为 null
  43. if (actionMap.TryGetValue(buttonName, out Transform buttonTransform) && buttonTransform != null)
  44. {
  45. Image image = buttonTransform.GetComponent<Image>();
  46. if (image != null)
  47. {
  48. image.color = new Color(200f / 255f, 200f / 255f, 200f / 255f, 130f / 255f);
  49. }
  50. Button button = buttonTransform.GetComponent<Button>();
  51. if (button != null)
  52. {
  53. button.interactable = false;
  54. button.gameObject.SetActive(false);
  55. }
  56. }
  57. }
  58. }
  59. void SortChildObjects(Dictionary<string, Transform> actionMap)
  60. {
  61. // 查找子对象并按名称填充 actionMap
  62. foreach (Transform child in transform)
  63. {
  64. if (actionMap.ContainsKey(child.name))
  65. {
  66. actionMap[child.name] = child;
  67. }
  68. else
  69. {
  70. // 如果子对象不在 actionMap 中,则隐藏它
  71. child.gameObject.SetActive(false);
  72. }
  73. }
  74. // 获取按字典定义顺序的子对象列表(过滤掉未找到的对象)
  75. var sortedChildren = actionMap.Values.Where(child => child != null).ToList();
  76. // 重新排列子对象
  77. for (int i = 0; i < sortedChildren.Count; i++)
  78. {
  79. sortedChildren[i].SetSiblingIndex(i);
  80. }
  81. }
  82. // Update is called once per frame
  83. //void Update()
  84. //{
  85. //}
  86. public void GoToConnect()
  87. {
  88. Debug.Log("进入连接页面");
  89. AudioMgr.ins.PlayBtn();
  90. //ViewMgr.Instance.ShowView<DeviceViewInfrared>();
  91. ViewManager.ShowView(UIViewType.DeviceView);
  92. }
  93. public void GoToScreen()
  94. {
  95. AudioMgr.ins.PlayBtn();
  96. if (CommonConfig.bLimitTip && !HomeView.ins.IsConnectSuccess()) {
  97. ModuleViewMgr.ins.ShowDeviceConnect();
  98. return;
  99. }
  100. if (!IsInfraredHardwareConnected())
  101. {
  102. ModuleViewMgr.ins.ShowDeviceConnectInfrared();
  103. return;
  104. }
  105. //如果没有屏幕定位,则直接启动屏幕定位
  106. if (HomeView.ins.IsScreenPositioned())
  107. {
  108. ViewManager.ShowView(UIViewType.PositioningView);
  109. }
  110. else {
  111. ViewManager.ShowView(UIViewType.InfraredView);
  112. }
  113. }
  114. static bool IsInfraredHardwareConnected()
  115. {
  116. SmartBowDeviceHub hub = SmartBowDeviceHub.ins;
  117. if (hub == null || !hub.IsConnected(BluetoothPlayer.FIRST_PLAYER))
  118. return false;
  119. return hub.IsMainConnectToInfraredDevice() || hub.IsMainConnectToGun();
  120. }
  121. public void GoToSetup()
  122. {
  123. AudioMgr.ins.PlayBtn();
  124. GameObject settingsViewObj = ViewManager.ShowView(UIViewType.SettingsView);
  125. //settingsViewObj.GetComponent<SmartBow.SettingsView>().ShowBoxSound(true);
  126. UITabSwitcher tab = settingsViewObj.GetComponent<UITabSwitcher>();
  127. tab.SetDefaultTab("BtnCommon");
  128. }
  129. public void GoToShop()
  130. {
  131. AudioMgr.ins.PlayBtn();
  132. //if (ShopView.ins) return;
  133. //ViewMgr.Instance.ShowView<ShopView>();
  134. }
  135. public void GoToGuider()
  136. {
  137. AudioMgr.ins.PlayBtn();
  138. //跳转至 设置-教程视频
  139. //GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_SettingsView);
  140. //settingsViewObj.GetComponent<SmartBow.SettingsView>().OnClick_BtnNewUser();
  141. //NewUserGuiderManager.ins.ReviewNewUserGuide();
  142. }
  143. public void GoToNewUser()
  144. {
  145. AudioMgr.ins.PlayBtn();
  146. //ViewManager2.ShowView(ViewManager2.Path_ConnectGuidanceView);
  147. }
  148. public void GoToFriends()
  149. {
  150. Debug.Log("进入好友页面");
  151. AudioMgr.ins.PlayBtn();
  152. //ViewManager2.ShowView(ViewManager2.Path_SocialView);
  153. }
  154. public void GoToRanking()
  155. {
  156. Debug.Log("进入排名页面");
  157. AudioMgr.ins.PlayBtn();
  158. ViewManager.ShowView(UIViewType.RankingView);
  159. }
  160. public void GoToUserCenterView()
  161. {
  162. if (CommonConfig.StandaloneMode) return;
  163. AudioMgr.ins.PlayBtn();
  164. ViewManager.ShowView(UIViewType.UserCenterView);
  165. }
  166. }
  167. }