HomeMgr.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class HomeMgr : MonoBehaviour
  6. {
  7. public static HomeMgr ins;
  8. void Awake()
  9. {
  10. ins = this;
  11. }
  12. void Start() {
  13. ResumeCacheViews();
  14. UserPlayer.ConnectServer();
  15. }
  16. void OnDestroy()
  17. {
  18. if (ins == this) ins = null;
  19. }
  20. #region 从主页到游戏场景,再回来时,恢复之前的页面
  21. static HashSet<MonoBehaviour> curCacheViews = new HashSet<MonoBehaviour>();
  22. public static void CacheView(MonoBehaviour view) {
  23. GameObject.DontDestroyOnLoad(view);
  24. curCacheViews.Add(view);
  25. }
  26. public static void RemoveCacheView(MonoBehaviour view) {
  27. curCacheViews.Remove(view);
  28. }
  29. public static void DestroyCacheViews() {
  30. foreach (var item in curCacheViews) {
  31. if (item && item.gameObject) {
  32. Destroy(item.gameObject);
  33. }
  34. }
  35. }
  36. public static void HideCacheViews() {
  37. foreach (var item in curCacheViews) item.gameObject.SetActive(false);
  38. }
  39. public void ResumeCacheViews() {
  40. foreach (var item in curCacheViews) item.gameObject.SetActive(true);
  41. }
  42. #endregion
  43. //登录认证的Mask
  44. public void ShowAuthLoginMask(bool visiable) {
  45. transform.Find("AuthLoginMask").gameObject.SetActive(visiable);
  46. }
  47. public void SetAuthLoginText(string text) {
  48. transform.Find("AuthLoginMask").GetComponentInChildren<Text>().text = text;
  49. }
  50. public bool IsAuthLoginMaskActive() {
  51. return transform.Find("AuthLoginMask").gameObject.activeSelf;
  52. }
  53. }