HomeMgr.cs 1.8 KB

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