using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /* 主界面右上方信息栏 */ public class TopBarView : MonoBehaviour { [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() { CheckNeedShowWhenInit(); 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 (CommonConfig.ReleaseVersion2) { Transform diamond = transform.Find("TopBar/Item"); diamond.localPosition += Vector3.right * 87; transform.Find("TopBar/IconLebo").gameObject.SetActive(false); } } 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(); // } } static HashSet _needShowItLockers = new HashSet(); public static void NeedShowIt(MonoBehaviour locker) { _needShowItLockers.Add(locker); #if UNITY_EDITOR Debug.LogWarning("NeedShowIt, NowCount=" + _needShowItLockers.Count); #endif try { ins.ResetCanvasSortOrder(); if (!ins.gameObject.activeSelf) ins.gameObject.SetActive(true); } catch (System.Exception) {} } public static void DontNeedShowIt(MonoBehaviour locker) { _needShowItLockers.Remove(locker); #if UNITY_EDITOR Debug.LogWarning("DontNeedShowIt, NowCount=" + _needShowItLockers.Count); #endif try { ins.ResetCanvasSortOrder(); if (ins.gameObject.activeSelf && _needShowItLockers.Count == 0) ins.gameObject.SetActive(false); } catch (System.Exception) {} } public void CheckNeedShowWhenInit() { if (_needShowItLockers.Count > 0) { ins.ResetCanvasSortOrder(); ins.gameObject.SetActive(true); } else { ins.gameObject.SetActive(false); } } void ResetCanvasSortOrder() { int maxOrder = 0; foreach (var item in _needShowItLockers) { int sortOrder = item.GetComponent().sortingOrder; if (sortOrder > maxOrder) maxOrder = sortOrder; } GetComponent().sortingOrder = maxOrder + 1; } public void GoToSetup() { AudioMgr.ins.PlayBtn(); GameObject o = GameObject.Instantiate(Resources.Load("Prefabs/Views/SetUpView1"), Vector3.zero, new Quaternion()); JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1); } public void GoToShop() { AudioMgr.ins.PlayBtn(); if (ShopView.ins) return; GameObject o = GameObject.Instantiate(Resources.Load("Prefabs/Views/ShopView")); JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1); } 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(SceneResMgr.ins.GetPrefab("ScreenProjectionView")); JCUnityLib.CanvasUtils.PlusSortOrder(gameObject, o, 1); } } }