HomeMgr.cs 1.8 KB

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