using System.Collections; using System.Collections.Generic; using UnityEngine; public class DrawListManager : MonoBehaviour { public static DrawListManager _instance; private Stack Dlist = new Stack(); private void Awake() { _instance = this; MessageCenterController.Instance.Register(GameEnum.MESSAGE_DRAW_UNDO_PREVIOUS, RemoveLast); MessageCenterController.Instance.Register(GameEnum.MESSAGE_DRAW_UNDO_ALL, RemoveAll); } private void OnDestroy() { RemoveAll(); MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_DRAW_UNDO_PREVIOUS, RemoveLast); MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_DRAW_UNDO_ALL, RemoveAll); } public void AddBrush(GameObject g) { g.transform.parent = transform; Dlist.Push(g); } public void RemoveLast(object o = null) { if (Dlist.Count > 0) { GameObject g = Dlist.Pop(); Destroy(g); } } public void RemoveAll(object o = null) { while (Dlist.Count > 0) { Destroy(Dlist.Pop()); } Dlist.Clear(); } private void Update() { if (Input.GetKeyUp(KeyCode.H)) { RemoveLast(); } else if (Input.GetKeyUp(KeyCode.J)) { RemoveAll(); } } }