예제 #1
0
        private static void RegisterCommandInGroup(IRevertableCommand revertableCommand, string commandGroup)
        {
            if (groupedCommands.ContainsKey(commandGroup) == false)
            {
                groupedCommands.Add(commandGroup, new List <IRevertableCommand>());
            }

            groupedCommands[commandGroup].Add(revertableCommand);
        }
예제 #2
0
        private static bool UndoCommand(IRevertableCommand revertableCommand)
        {
            try
            {
                revertableCommand.Undo();
            }
            catch (Exception e)
            {
                logger.Error("Can't undo the command.", e);
                Panic();
                return(false);
            }

            return(true);
        }
예제 #3
0
        private static bool UndoCommand(IRevertableCommand revertableCommand)
        {
            try
            {
                revertableCommand.Undo();
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("Can't undo the command.\n{0}", e);
                Panic();
                return(false);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Registers <paramref name="revertableCommand"/> and executes it.
        /// </summary>
        /// <remarks>
        /// If <typeparamref name="commandGroup"/> is empty, <paramref name="revertableCommand"/> will be added to the main stack, otherwise,
        /// it will remind in a group called as <typeparamref name="commandGroup"/> content until <seealso cref="CollapseUndoOperations"/> is called.
        /// </remarks>
        public static void Do(IRevertableCommand revertableCommand, string commandGroup = "")
        {
            if (revertableCommand == null)
            {
                logger.Error("Command can't be null, ignoring.");
                return;
            }

            if (string.IsNullOrEmpty(commandGroup))
            {
                RegisterCommand(revertableCommand);
            }
            else
            {
                RegisterCommandInGroup(revertableCommand, commandGroup);
            }

            DoCommand(revertableCommand);
        }
예제 #5
0
        private static void RegisterCommand(IRevertableCommand revertableCommand)
        {
            if (serialized == null)
            {
                FlushStack();
            }

            UnityEditor.Undo.IncrementCurrentGroup();
            UnityEditor.Undo.RecordObject(serialized, "");

            // Flush outdated.
            if (commands.Count > commandIndex)
            {
                commands.RemoveRange(commandIndex, commands.Count - commandIndex);
            }

            commands.Add(revertableCommand);
            commandIndex++;
            serialized.CommandIndex = commandIndex;
        }