HomeMgr.cs 1.7 KB

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