HeavenStudioPlus/Assets/Scripts/LevelEditor/Commands/CommandManager.cs
ThePurpleAnon 8d275a9e89 Cleaning up those dang warnings (#826)
* done i think

wahoo

* this one too

lol
2024-04-07 21:25:54 +00:00

70 lines
No EOL
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Editor.Commands;
namespace HeavenStudio.Editor
{
public class CommandManager : MonoBehaviour
{
public static CommandManager Instance { get; private set; }
private Stack<ICommand> historyStack = new Stack<ICommand>();
private Stack<ICommand> redoHistoryStack = new Stack<ICommand>();
public int HistoryCount => historyStack.Count;
//private int maxItems = 128; Unused value - Marc
private void Awake()
{
Instance = this;
}
public void AddCommand(ICommand command)
{
command.Execute();
historyStack.Push(command);
redoHistoryStack.Clear();
}
public void UndoCommand()
{
if (!CanUndo() || Conductor.instance.NotStopped()) return;
if (historyStack.Count > 0)
{
redoHistoryStack.Push(historyStack.Peek());
historyStack.Pop().Undo();
}
}
public void RedoCommand()
{
if (!CanRedo() || Conductor.instance.NotStopped()) return;
if (redoHistoryStack.Count > 0)
{
historyStack.Push(redoHistoryStack.Peek());
redoHistoryStack.Pop().Execute();
}
}
public void Clear()
{
historyStack.Clear();
redoHistoryStack.Clear();
}
public bool CanUndo()
{
return historyStack.Count > 0;
}
public bool CanRedo()
{
return redoHistoryStack.Count > 0;
}
}
}