| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using JCUnityLib;
- /* 主界面右上方信息栏 */
- public class TopBarView : JCUnityLib.ViewBase
- {
- [SerializeField] Text[] itemValueTexts;
- [SerializeField] Button[] itemPlusButtons;
- int[] itemValues = {-1, -1, -1};
-
- public static TopBarView ins;
-
- public void Awake()
- {
- ins = this;
- }
- public void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- void Start()
- {
- ResetSiblingIndex();
- if (CommonConfig.needToExamine) {
- Transform tf = transform.Find("TopBar");
- for (int i = 0; i < tf.childCount; i++) {
- if (tf.GetChild(i).name.StartsWith("Item")) {
- tf.GetChild(i).gameObject.SetActive(false);
- }
- }
- }
- // if (Application.platform == RuntimePlatform.IPhonePlayer) {
- Transform diamond = transform.Find("TopBar/Item");
- diamond.localPosition += Vector3.right * 87;
- transform.Find("TopBar/IconLebo").gameObject.SetActive(false);
- // }
- CheckNeewShowDiamond();
- }
- void Update()
- {
- if (itemValues[0] != LoginMgr.myUserInfo.diamond) {
- itemValues[0] = LoginMgr.myUserInfo.diamond;
- itemValueTexts[0].text = itemValues[0].ToString();
- }
- // if (itemValues[1] != LoginMgr.myUserInfo.coin) {
- // itemValues[1] = LoginMgr.myUserInfo.coin;
- // itemValueTexts[1].text = itemValues[1].ToString();
- // }
- // if (itemValues[2] != LoginMgr.myUserInfo.integral) {
- // itemValues[2] = LoginMgr.myUserInfo.integral;
- // itemValueTexts[2].text = itemValues[2].ToString();
- // }
- }
- void CheckNeewShowDiamond()
- {
- bool hasTarget = false;
- foreach (var item in _needShowItLockers)
- {
- if (typeof(ShopView) == item.GetType())
- {
- hasTarget = true;
- break;
- }
- }
- try {
- transform.Find("TopBar/Item").gameObject.SetActive(hasTarget);
- } catch (System.Exception) {}
- }
- private static HashSet<ViewBase> _needShowItLockers = new HashSet<ViewBase>();
- public static void NeedShowIt(ViewBase locker) {
- _needShowItLockers.Add(locker);
- ins?.ResetSiblingIndex();
- ins?.CheckNeewShowDiamond();
- }
- public static void DontNeedShowIt(ViewBase locker) {
- _needShowItLockers.Remove(locker);
- ins?.ResetSiblingIndex();
- ins?.CheckNeewShowDiamond();
- }
- private void ResetSiblingIndex()
- {
- //如果作为父节点的ViewMgr已OnDestroy,那再操作子节点就会报错。
- if (!ViewMgr.HasInstance()) return;
- //该节点重排序
- int maxOrder = -1;
- foreach (var item in _needShowItLockers) {
- int sortOrder = item.transform.GetSiblingIndex();
- if (sortOrder > maxOrder) maxOrder = sortOrder;
- }
- transform.SetSiblingIndex(maxOrder + 1);
- }
- public void GoToSetup() {
- AudioMgr.ins.PlayBtn();
- ViewManager2.ShowView(ViewManager2.Path_SettingsView);
- }
- public void GoToShop()
- {
- AudioMgr.ins.PlayBtn();
- if (ShopView.ins) return;
- ViewMgr.Instance.ShowView<ShopView>();
- }
- public void GoToGuider()
- {
- AudioMgr.ins.PlayBtn();
- NewUserGuiderManager.ins.ReviewNewUserGuide();
- }
- public void GoToLebo()
- {
- AudioMgr.ins.PlayBtn();
- if (ScreenProjectionView.ins) {
- GameObject o = ScreenProjectionView.ins.gameObject;
- JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1);
- o.SetActive(true);
- } else {
- GameObject o = GameObject.Instantiate(SceneResourceManager.Instance.GetPrefab("ScreenProjectionView"));
- JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1);
- }
- }
- }
|