HomeView_BottomBarView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. switch (CommonConfig.OP)
  25. {
  26. case OperatingPlatform.B:
  27. DisableButtonInteractivity(actionMap, new List<string> { "IconGuider", "IconFriend", "IconRank" });
  28. break;
  29. }
  30. }
  31. void DisableButtonInteractivity(Dictionary<string, Transform> actionMap, List<string> buttonNames)
  32. {
  33. foreach (var buttonName in buttonNames)
  34. {
  35. // 检查 actionMap 中是否有该键且对应的 Transform 不为 null
  36. if (actionMap.TryGetValue(buttonName, out Transform buttonTransform) && buttonTransform != null)
  37. {
  38. Image image = buttonTransform.GetComponent<Image>();
  39. if (image != null) {
  40. image.color = new Color(200f / 255f, 200f / 255f, 200f / 255f, 130f / 255f);
  41. }
  42. Button button = buttonTransform.GetComponent<Button>();
  43. if (button != null)
  44. {
  45. button.interactable = false;
  46. }
  47. }
  48. }
  49. }
  50. void SortChildObjects(Dictionary<string, Transform> actionMap)
  51. {
  52. // 查找子对象并按名称填充 actionMap
  53. foreach (Transform child in transform)
  54. {
  55. if (actionMap.ContainsKey(child.name))
  56. {
  57. actionMap[child.name] = child;
  58. }
  59. else
  60. {
  61. // 如果子对象不在 actionMap 中,则隐藏它
  62. child.gameObject.SetActive(false);
  63. }
  64. }
  65. // 获取按字典定义顺序的子对象列表(过滤掉未找到的对象)
  66. var sortedChildren = actionMap.Values.Where(child => child != null).ToList();
  67. // 重新排列子对象
  68. for (int i = 0; i < sortedChildren.Count; i++)
  69. {
  70. sortedChildren[i].SetSiblingIndex(i);
  71. }
  72. }
  73. // Update is called once per frame
  74. //void Update()
  75. //{
  76. //}
  77. public void GoToConnect()
  78. {
  79. Debug.Log("进入连接页面");
  80. AudioMgr.ins.PlayBtn();
  81. ViewMgr.Instance.ShowView<DeviceViewInfrared>();
  82. }
  83. public void GoToSetup()
  84. {
  85. AudioMgr.ins.PlayBtn();
  86. GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_SettingsView);
  87. settingsViewObj.GetComponent<SmartBow.SettingsView>().ShowBoxSound(true);
  88. }
  89. public void GoToShop()
  90. {
  91. AudioMgr.ins.PlayBtn();
  92. if (ShopView.ins) return;
  93. ViewMgr.Instance.ShowView<ShopView>();
  94. }
  95. public void GoToGuider()
  96. {
  97. AudioMgr.ins.PlayBtn();
  98. //跳转至 设置-教程视频
  99. GameObject settingsViewObj = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_SettingsView);
  100. settingsViewObj.GetComponent<SmartBow.SettingsView>().OnClick_BtnNewUser();
  101. //NewUserGuiderManager.ins.ReviewNewUserGuide();
  102. }
  103. public void GoToNewUser()
  104. {
  105. AudioMgr.ins.PlayBtn();
  106. //ViewManager2.ShowView(ViewManager2.Path_ConnectGuidanceView);
  107. }
  108. public void GoToFriends()
  109. {
  110. Debug.Log("进入好友页面");
  111. AudioMgr.ins.PlayBtn();
  112. ViewManager2.ShowView(ViewManager2.Path_SocialView);
  113. }
  114. public void GoToRanking()
  115. {
  116. Debug.Log("进入排名页面");
  117. AudioMgr.ins.PlayBtn();
  118. ViewManager2.ShowView(ViewManager2.Path_RankingView);
  119. }
  120. }