HomeMgr.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class HomeMgr : MonoBehaviour
  5. {
  6. public static HomeMgr ins;
  7. void Awake()
  8. {
  9. ins = this;
  10. }
  11. void Start() {
  12. ResumeCacheViews();
  13. }
  14. void OnDestroy()
  15. {
  16. if (ins == this) ins = null;
  17. }
  18. #region 从主页到游戏场景,再回来时,恢复之前的页面
  19. static HashSet<MonoBehaviour> curCacheViews = new HashSet<MonoBehaviour>();
  20. public static void CacheView(MonoBehaviour view) {
  21. GameObject.DontDestroyOnLoad(view);
  22. curCacheViews.Add(view);
  23. }
  24. public static void RemoveCacheView(MonoBehaviour view) {
  25. curCacheViews.Remove(view);
  26. }
  27. public static void HideCacheViews() {
  28. foreach (var item in curCacheViews) item.gameObject.SetActive(false);
  29. }
  30. public void ResumeCacheViews() {
  31. foreach (var item in curCacheViews) item.gameObject.SetActive(true);
  32. }
  33. #endregion
  34. }