HomeView_BottomBarView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using JCUnityLib;
  5. using System.Linq;
  6. using UnityEngine.UI;
  7. public class HomeView_BottomBarView : MonoBehaviour
  8. {
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. Dictionary<string, Transform> actionMap = new Dictionary<string, Transform>
  13. {
  14. { "IconConnect", null },
  15. { "IconGuider", null },
  16. //{ "IconShop", null },
  17. //{ "IconNewUser", null },
  18. { "IconFriend", null },
  19. { "IconRank", null },
  20. { "IconSetUp", null }
  21. };
  22. SortChildObjects(actionMap);
  23. // 按条件禁用特定按钮的交互性
  24. if (CommonConfig.StandaloneMode) {
  25. DisableButtonInteractivity(actionMap, new List<string> { "IconGuider", "IconFriend", "IconRank" });
  26. }
  27. }
  28. void DisableButtonInteractivity(Dictionary<string, Transform> actionMap, List<string> buttonNames)
  29. {
  30. foreach (var buttonName in buttonNames)
  31. {
  32. // 检查 actionMap 中是否有该键且对应的 Transform 不为 null
  33. if (actionMap.TryGetValue(buttonName, out Transform buttonTransform) && buttonTransform != null)
  34. {
  35. Image image = buttonTransform.GetComponent<Image>();
  36. if (image != null) {
  37. image.color = new Color(200f / 255f, 200f / 255f, 200f / 255f, 130f / 255f);
  38. }
  39. Button button = buttonTransform.GetComponent<Button>();
  40. if (button != null)
  41. {
  42. button.interactable = false;
  43. }
  44. }
  45. }
  46. }
  47. void SortChildObjects(Dictionary<string, Transform> actionMap)
  48. {
  49. // 查找子对象并按名称填充 actionMap
  50. foreach (Transform child in transform)
  51. {
  52. if (actionMap.ContainsKey(child.name))
  53. {
  54. actionMap[child.name] = child;
  55. }
  56. else
  57. {
  58. // 如果子对象不在 actionMap 中,则隐藏它
  59. child.gameObject.SetActive(false);
  60. }
  61. }
  62. // 获取按字典定义顺序的子对象列表(过滤掉未找到的对象)
  63. var sortedChildren = actionMap.Values.Where(child => child != null).ToList();
  64. // 重新排列子对象
  65. for (int i = 0; i < sortedChildren.Count; i++)
  66. {
  67. sortedChildren[i].SetSiblingIndex(i);
  68. }
  69. }
  70. // Update is called once per frame
  71. //void Update()
  72. //{
  73. //}
  74. public void GoToConnect()
  75. {
  76. Debug.Log("进入连接页面");
  77. AudioMgr.ins.PlayBtn();
  78. ViewMgr.Instance.ShowView<DeviceViewInfrared>();
  79. }
  80. public void GoToSetup()
  81. {
  82. AudioMgr.ins.PlayBtn();
  83. GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_SettingsView);
  84. settingsViewObj.GetComponent<SmartBow.SettingsView>().ShowBoxSound(true);
  85. }
  86. public void GoToShop()
  87. {
  88. AudioMgr.ins.PlayBtn();
  89. if (ShopView.ins) return;
  90. ViewMgr.Instance.ShowView<ShopView>();
  91. }
  92. public void GoToGuider()
  93. {
  94. AudioMgr.ins.PlayBtn();
  95. //跳转至 设置-教程视频
  96. GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_SettingsView);
  97. settingsViewObj.GetComponent<SmartBow.SettingsView>().OnClick_BtnNewUser();
  98. //NewUserGuiderManager.ins.ReviewNewUserGuide();
  99. }
  100. public void GoToNewUser()
  101. {
  102. AudioMgr.ins.PlayBtn();
  103. //ViewManager2.ShowView(ViewManager2.Path_ConnectGuidanceView);
  104. }
  105. public void GoToFriends()
  106. {
  107. Debug.Log("进入好友页面");
  108. AudioMgr.ins.PlayBtn();
  109. ViewManager2.ShowView(ViewManager2.Path_SocialView);
  110. }
  111. public void GoToRanking()
  112. {
  113. Debug.Log("进入排名页面");
  114. AudioMgr.ins.PlayBtn();
  115. ViewManager2.ShowView(ViewManager2.Path_RankingView);
  116. }
  117. }