123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DrawListManager : MonoBehaviour
- {
- public static DrawListManager _instance;
- private Stack<GameObject> Dlist = new Stack<GameObject>();
-
- 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();
- }
- }
- }
|