You've already forked UniversalViewer
Initial files
This commit is contained in:
55
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs
Normal file
55
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public class CommandGroup : ICommand
|
||||
{
|
||||
List<ICommand> commands = new List<ICommand>();
|
||||
|
||||
public CommandGroup() {}
|
||||
public CommandGroup(List<ICommand> commands)
|
||||
{
|
||||
this.commands.AddRange(commands);
|
||||
}
|
||||
|
||||
public void Set(List<ICommand> commands)
|
||||
{
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public void Add(ICommand command)
|
||||
{
|
||||
commands.Add(command);
|
||||
}
|
||||
|
||||
public void Remove(ICommand command)
|
||||
{
|
||||
commands.Remove(command);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
commands.Clear();
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
for(int i = 0; i < commands.Count; i++)
|
||||
{
|
||||
Debug.Log("Executing " + commands[i].GetType().Name);
|
||||
commands[i].Execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnExecute()
|
||||
{
|
||||
for(int i = commands.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Debug.Log("Executing " + commands[i].GetType().Name);
|
||||
commands[i].UnExecute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da819dbd08b38eb45a35dbdb0fe78711
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs
Normal file
51
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public class DropoutStack<T> : LinkedList<T>
|
||||
{
|
||||
int _maxLength = int.MaxValue;
|
||||
public int maxLength {get {return _maxLength;} set {SetMaxLength(value);}}
|
||||
|
||||
public DropoutStack() {}
|
||||
public DropoutStack(int maxLength)
|
||||
{
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
if(this.Count > 0 && this.Count + 1 > maxLength)
|
||||
{
|
||||
this.RemoveLast();
|
||||
}
|
||||
|
||||
if(this.Count + 1 <= maxLength)
|
||||
{
|
||||
this.AddFirst(item);
|
||||
}
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
T item = this.First.Value;
|
||||
this.RemoveFirst();
|
||||
return item;
|
||||
}
|
||||
|
||||
void SetMaxLength(int max)
|
||||
{
|
||||
_maxLength = max;
|
||||
|
||||
if(this.Count > _maxLength)
|
||||
{
|
||||
int leftover = this.Count - _maxLength;
|
||||
for(int i = 0; i < leftover; i++)
|
||||
{
|
||||
this.RemoveLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c376afccd664f4e42b36d3a99300037d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoManager.asmdef
Normal file
16
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoManager.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "UndoManager",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:aee7fa92e14bf364ebccdd24623e1764"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee695b84b4c90104b9367eebc6b0d70d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs
Normal file
65
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public class UndoRedo
|
||||
{
|
||||
public int maxUndoStored {get {return undoCommands.maxLength;} set {SetMaxLength(value);}}
|
||||
|
||||
DropoutStack<ICommand> undoCommands = new DropoutStack<ICommand>();
|
||||
DropoutStack<ICommand> redoCommands = new DropoutStack<ICommand>();
|
||||
|
||||
public UndoRedo() {}
|
||||
public UndoRedo(int maxUndoStored)
|
||||
{
|
||||
this.maxUndoStored = maxUndoStored;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
undoCommands.Clear();
|
||||
redoCommands.Clear();
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if(undoCommands.Count > 0)
|
||||
{
|
||||
ICommand command = undoCommands.Pop();
|
||||
command.UnExecute();
|
||||
redoCommands.Push(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
if(redoCommands.Count > 0)
|
||||
{
|
||||
ICommand command = redoCommands.Pop();
|
||||
command.Execute();
|
||||
undoCommands.Push(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(ICommand command)
|
||||
{
|
||||
if(maxUndoStored <= 0) return;
|
||||
|
||||
undoCommands.Push(command);
|
||||
redoCommands.Clear();
|
||||
}
|
||||
|
||||
public void Execute(ICommand command)
|
||||
{
|
||||
command.Execute();
|
||||
Insert(command);
|
||||
}
|
||||
|
||||
void SetMaxLength(int max)
|
||||
{
|
||||
undoCommands.maxLength = max;
|
||||
redoCommands.maxLength = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ed1af1a5fc734b49894376597a9c723
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs
Normal file
36
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public static class UndoRedoManager
|
||||
{
|
||||
static UndoRedo undoRedo = new UndoRedo();
|
||||
|
||||
public static int maxUndoStored {get {return undoRedo.maxUndoStored;} set {undoRedo.maxUndoStored = value;}}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
undoRedo.Clear();
|
||||
}
|
||||
|
||||
public static void Undo()
|
||||
{
|
||||
undoRedo.Undo();
|
||||
}
|
||||
|
||||
public static void Redo()
|
||||
{
|
||||
undoRedo.Redo();
|
||||
}
|
||||
|
||||
public static void Insert(ICommand command)
|
||||
{
|
||||
undoRedo.Insert(command);
|
||||
}
|
||||
|
||||
public static void Execute(ICommand command)
|
||||
{
|
||||
undoRedo.Execute(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ace2ece517a3a1c4f898c0fc635a5dd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user