HomeMgr.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. var mask = transform.Find("AuthLoginMask");
  49. mask.gameObject.SetActive(visiable);
  50. if (visiable) {
  51. mask.GetComponentInChildren<Text>().text = TextAutoLanguage2.GetTextByKey("home_loginAuth");
  52. }
  53. }
  54. public void SetAuthLoginText(string text) {
  55. transform.Find("AuthLoginMask").GetComponentInChildren<Text>().text = text;
  56. }
  57. public bool IsAuthLoginMaskActive() {
  58. return transform.Find("AuthLoginMask").gameObject.activeSelf;
  59. }
  60. }