Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Face
- {
- List<Vertex> vertices;
- }
- public class Vertex : ValueLog<Vertex>
- {
- Vector3 _position;
- public Vector3 Position
- {
- set { Log(); _position = value; }
- get { return _position; }
- }
- public Vertex(Vector3 position)
- {
- _position = position;
- }
- protected override void Restore(Vertex value)
- {
- _position = value._position;
- }
- protected override Vertex GetLogValue()
- {
- return new Vertex(_position);
- }
- }
- public abstract class ValueLog<T> : ICmd
- {
- Stack<T> undoStack;
- Stack<T> redoStack;
- bool logged = false;
- public ValueLog()
- {
- undoStack = new Stack<T>();
- redoStack = new Stack<T>();
- }
- protected abstract void Restore(T value);
- protected abstract T GetLogValue();
- protected void Log()
- {
- if (!logged && !Logger.Instance.logPaused)
- {
- logged = true;
- redoStack.Clear();
- undoStack.Push(GetLogValue());
- // add log operation to a list of operations that happen at once
- Logger.Instance.AddCmd(this);
- Logger.Instance.OnCollect += OnCollect;
- }
- }
- public override void Undo()
- {
- if (undoStack.Count > 0)
- {
- T current = GetLogValue();
- redoStack.Push(current);
- T restore = undoStack.Pop();
- Restore(restore);
- }
- }
- public override void Redo()
- {
- if (redoStack.Count > 0)
- {
- T current = GetLogValue();
- undoStack.Push(current);
- T restore = redoStack.Pop();
- Restore(restore);
- }
- }
- void OnCollect()
- {
- // called when operation finished (On Mouse Up)
- logged = false;
- Logger.Instance.OnCollect -= OnCollect;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement