| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HomeMgr : MonoBehaviour
- {
- public static HomeMgr ins;
- void Awake()
- {
- ins = this;
- }
- void Start() {
- ResumeCacheViews();
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- #region 从主页到游戏场景,再回来时,恢复之前的页面
- static HashSet<MonoBehaviour> curCacheViews = new HashSet<MonoBehaviour>();
- public static void CacheView(MonoBehaviour view) {
- GameObject.DontDestroyOnLoad(view);
- curCacheViews.Add(view);
- }
- public static void RemoveCacheView(MonoBehaviour view) {
- curCacheViews.Remove(view);
- }
- public static void HideCacheViews() {
- foreach (var item in curCacheViews) item.gameObject.SetActive(false);
- }
- public void ResumeCacheViews() {
- foreach (var item in curCacheViews) item.gameObject.SetActive(true);
- }
- #endregion
- }
|