Ejemplo n.º 1
0
            /// <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) };
            }
Ejemplo n.º 2
0
            /// <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));
                }
            }
Ejemplo n.º 3
0
            /// <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]);
                }
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the state from a scene object.
        /// </summary>
        /// <param name="so">Scene object to initialize the state from.</param>
        /// <returns>New state object.</returns>
        internal static SceneObjectState Create(SceneObject so)
        {
            SceneObjectState state = new SceneObjectState();

            state.name     = so.Name;
            state.position = so.LocalPosition;
            state.rotation = so.LocalRotation;
            state.scale    = so.LocalScale;
            state.active   = so.Active;

            return(state);
        }
Ejemplo n.º 5
0
        /// <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);
        }