/// <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 diff object storing the difference between two <see cref="SceneObjectState"/> objects.
        /// </summary>
        /// <param name="oldState">State of the scene object to compare from.</param>
        /// <param name="newState">State of the scene object to compare to.</param>
        /// <returns>Difference between the two scene object states.</returns>
        internal static SceneObjectDiff Create(SceneObjectState oldState, SceneObjectState newState)
        {
            SceneObjectDiff diff = new SceneObjectDiff();

            diff.state = new SceneObjectState();

            if (oldState.name != newState.name)
            {
                diff.state.name = newState.name;
                diff.flags     |= SceneObjectDiffFlags.Name;
            }

            if (oldState.position != newState.position)
            {
                diff.state.position = newState.position;
                diff.flags         |= SceneObjectDiffFlags.Position;
            }

            if (oldState.rotation != newState.rotation)
            {
                diff.state.rotation = newState.rotation;
                diff.flags         |= SceneObjectDiffFlags.Rotation;
            }

            if (oldState.scale != newState.scale)
            {
                diff.state.scale = newState.scale;
                diff.flags      |= SceneObjectDiffFlags.Scale;
            }

            if (oldState.active != newState.active)
            {
                diff.state.active = newState.active;
                diff.flags       |= SceneObjectDiffFlags.Active;
            }

            return(diff);
        }
 internal SceneObjectHeaderUndo(SceneObject obj, SceneObjectDiff newToOld, SceneObjectDiff oldToNew)
 {
     this.obj      = obj;
     this.newToOld = newToOld;
     this.oldToNew = oldToNew;
 }