/// <summary>
 /// Creates the new component undo command.
 /// </summary>
 /// <param name="obj">Component on which to apply the performed changes.</param>
 /// <param name="fieldPath">
 /// Optional path that controls which is the field being modified and should receive input focus when the command
 /// is executed. Note that the diffs applied have no restriction on how many fields they can modify at once, but
 /// only one field will receive focus.</param>
 /// <param name="oldToNew">
 /// Difference that can be applied to the old object in order to get the new object state.
 /// </param>
 /// <param name="newToOld">
 /// Difference that can be applied to the new object in order to get the old object state.
 /// </param>
 public RecordComponentUndo(Component obj, string fieldPath, SerializedDiff oldToNew, SerializedDiff newToOld)
 {
     this.obj       = obj;
     this.fieldPath = fieldPath;
     this.oldToNew  = oldToNew;
     this.newToOld  = newToOld;
 }
            /// <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 (obj.IsDestroyed)
                {
                    return;
                }

                SerializedObject newState = SerializedObject.Create(obj);

                SerializedDiff oldToNew = SerializedDiff.Create(orgState, newState);

                if (oldToNew == null || oldToNew.IsEmpty)
                {
                    return;
                }

                SerializedDiff newToOld = SerializedDiff.Create(newState, orgState);

                UndoRedo.Global.RegisterCommand(new RecordComponentUndo(obj, path, oldToNew, newToOld));
            }