TopBarView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /* 主界面右上方信息栏 */
  6. public class TopBarView : MonoBehaviour
  7. {
  8. [SerializeField] Text[] itemValueTexts;
  9. [SerializeField] Button[] itemPlusButtons;
  10. int[] itemValues = {-1, -1, -1};
  11. public static TopBarView ins;
  12. public void Awake()
  13. {
  14. ins = this;
  15. }
  16. public void OnDestroy()
  17. {
  18. if (ins == this) ins = null;
  19. }
  20. void Start()
  21. {
  22. CheckNeedShowWhenInit();
  23. if (CommonConfig.needToExamine) {
  24. Transform tf = transform.Find("TopBar");
  25. for (int i = 0; i < tf.childCount; i++) {
  26. if (tf.GetChild(i).name.StartsWith("Item")) {
  27. tf.GetChild(i).gameObject.SetActive(false);
  28. }
  29. }
  30. }
  31. if (CommonConfig.ReleaseVersion2) {
  32. Transform diamond = transform.Find("TopBar/Item");
  33. diamond.localPosition += Vector3.right * 87;
  34. transform.Find("TopBar/IconLebo").gameObject.SetActive(false);
  35. }
  36. }
  37. void Update()
  38. {
  39. if (itemValues[0] != LoginMgr.myUserInfo.diamond) {
  40. itemValues[0] = LoginMgr.myUserInfo.diamond;
  41. itemValueTexts[0].text = itemValues[0].ToString();
  42. }
  43. // if (itemValues[1] != LoginMgr.myUserInfo.coin) {
  44. // itemValues[1] = LoginMgr.myUserInfo.coin;
  45. // itemValueTexts[1].text = itemValues[1].ToString();
  46. // }
  47. // if (itemValues[2] != LoginMgr.myUserInfo.integral) {
  48. // itemValues[2] = LoginMgr.myUserInfo.integral;
  49. // itemValueTexts[2].text = itemValues[2].ToString();
  50. // }
  51. }
  52. static HashSet<MonoBehaviour> _needShowItLockers = new HashSet<MonoBehaviour>();
  53. public static void NeedShowIt(MonoBehaviour locker) {
  54. _needShowItLockers.Add(locker);
  55. #if UNITY_EDITOR
  56. Debug.LogWarning("NeedShowIt, NowCount=" + _needShowItLockers.Count);
  57. #endif
  58. try {
  59. ins.ResetCanvasSortOrder();
  60. if (!ins.gameObject.activeSelf) ins.gameObject.SetActive(true);
  61. }
  62. catch (System.Exception) {}
  63. }
  64. public static void DontNeedShowIt(MonoBehaviour locker) {
  65. _needShowItLockers.Remove(locker);
  66. #if UNITY_EDITOR
  67. Debug.LogWarning("DontNeedShowIt, NowCount=" + _needShowItLockers.Count);
  68. #endif
  69. try {
  70. ins.ResetCanvasSortOrder();
  71. if (ins.gameObject.activeSelf && _needShowItLockers.Count == 0) ins.gameObject.SetActive(false);
  72. }
  73. catch (System.Exception) {}
  74. }
  75. public void CheckNeedShowWhenInit() {
  76. if (_needShowItLockers.Count > 0) {
  77. ins.ResetCanvasSortOrder();
  78. ins.gameObject.SetActive(true);
  79. } else {
  80. ins.gameObject.SetActive(false);
  81. }
  82. }
  83. void ResetCanvasSortOrder()
  84. {
  85. int maxOrder = 0;
  86. foreach (var item in _needShowItLockers) {
  87. int sortOrder = item.GetComponent<Canvas>().sortingOrder;
  88. if (sortOrder > maxOrder) maxOrder = sortOrder;
  89. }
  90. GetComponent<Canvas>().sortingOrder = maxOrder + 1;
  91. }
  92. public void GoToSetup() {
  93. AudioMgr.ins.PlayBtn();
  94. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/SetUpView1"), Vector3.zero, new Quaternion());
  95. JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1);
  96. }
  97. public void GoToShop()
  98. {
  99. AudioMgr.ins.PlayBtn();
  100. if (ShopView.ins) return;
  101. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/ShopView"));
  102. JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1);
  103. }
  104. public void GoToLebo()
  105. {
  106. AudioMgr.ins.PlayBtn();
  107. if (ScreenProjectionView.ins) {
  108. GameObject o = ScreenProjectionView.ins.gameObject;
  109. JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1);
  110. o.SetActive(true);
  111. } else {
  112. GameObject o = GameObject.Instantiate(SceneResMgr.ins.GetPrefab("ScreenProjectionView"));
  113. JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1);
  114. }
  115. }
  116. }