/// <summary> /// Generates the diff from the previously recorded state and the current state. If there is a difference /// an undo command is recorded. /// </summary> internal void RecordCommand() { if (objs == null) { return; } List <SceneObjectHeaderUndo> headers = new List <SceneObjectHeaderUndo>(); for (int i = 0; i < objs.Length; i++) { SceneObject obj = objs[i]; SceneObjectState orgState = orgStates[i]; if (obj.IsDestroyed) { continue; } SceneObjectDiff oldToNew = SceneObjectDiff.Create(orgState, SceneObjectState.Create(obj)); if (oldToNew.flags == 0) { continue; } SceneObjectDiff newToOld = SceneObjectDiff.Create(SceneObjectState.Create(obj), orgState); headers.Add(new SceneObjectHeaderUndo(obj, newToOld, oldToNew)); } if (headers.Count > 0) { UndoRedo.Global.RegisterCommand(new RecordSceneObjectHeaderUndo(headers, path)); } }
/// <summary> /// Creates a new object instance, recording the current state of the scene object header. /// </summary> /// <param name="obj">Scene object to record the state of.</param> /// <param name="path"> /// Path to the field which should be focused when performing the undo/redo operation. /// </param> internal SceneObjectHeaderToRecord(SceneObject obj, string path) { this.objs = new [] { obj }; this.path = path; orgStates = new [] { SceneObjectState.Create(obj) }; }
/// <summary> /// Creates a new object instance, recording the current state of the scene object header for multiple scene /// objects. /// </summary> /// <param name="objs">Scene objects to record the state of.</param> /// <param name="path"> /// Path to the field which should be focused when performing the undo/redo operation. /// </param> internal SceneObjectHeaderToRecord(SceneObject[] objs, string path) { this.objs = objs; this.path = path; orgStates = new SceneObjectState[objs.Length]; for (int i = 0; i < orgStates.Length; i++) { orgStates[i] = SceneObjectState.Create(objs[i]); } }