| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /*
- 项目名称:
- 功能:1.实现隐藏功能
- 2.撤销隐藏功能
- 3.一键还原功能
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DeviceStateManager : MonoBehaviour
- {
- #region 单例
- private static DeviceStateManager _instance;
- public DeviceStateManager() { }
- public static DeviceStateManager Instance
- {
- get
- {
- if (_instance != null)
- {
- return _instance;
- }
- else
- {
- _instance = new GameObject().AddComponent<DeviceStateManager>();
- return _instance;
- }
- }
- }
- #endregion
- #region 变量声明
- //全部隐藏管理栈
- private Stack<GameObject> _Pool;
- //模式栈
- private Stack<Mode> _ModePool;
- //用于存放所有Material
- private Dictionary<string, Material> Material_dic;
- #endregion
- #region 公开方法
- /// <summary>
- /// 隐藏Obj并添加到栈中
- /// </summary>
- /// <param name="obj"></param>
- public void AddObjToPool(GameObject obj)
- {
- obj.SetActive(false);
- _Pool.Push(obj);
- }
- /// <summary>
- /// 撤销上一步隐藏的obj
- /// </summary>
- public void RemoveObjToPool()
- {
- if (_Pool.Count != 0)
- {
- _Pool.Pop().SetActive(true);
- }
- }
- /// <summary>
- ///撤销所有步骤
- /// </summary>
- public void RemoveAllFromPool()
- {
- Debug.Log("撤销所有步骤");
- while (_Pool.Count != 0)
- {
- Debug.Log(_Pool.Count);
- _Pool.Pop().SetActive(true);
- }
- }
- #endregion
- #region 私有
- void Awake()
- {
- _instance = this;
- _Pool = new Stack<GameObject>();
- }
- #endregion
- }
|