Exemplo n.º 1
0
            public static UndoableModification Create([NotNull] LinkedMemberInfo setMemberInfo, [NotNull] object[] setValuesTo)
            {
                UndoableModification created;

                if (!pool.TryGet(out created))
                {
                    created = new UndoableModification();
                }
                created.Setup(setMemberInfo, setValuesTo);
                return(created);
            }
Exemplo n.º 2
0
            public static UndoableModification Create([NotNull] LinkedMemberInfo setMemberInfo, object setValueTo)
            {
                UndoableModification created;

                if (!pool.TryGet(out created))
                {
                    created = new UndoableModification();
                }
                created.Setup(setMemberInfo, ArrayPool <object> .CreateWithContent(setValueTo));
                return(created);
            }
Exemplo n.º 3
0
        /// <summary>
        /// Use this for adding Undo support for changes that are not serialized by Unity and Unity
        /// can't handle undoing the action
        /// </summary>
        /// <param name="memberInfo"> The LinkedMemberInfo for the member which is being modified. This cannot be null. </param>
        /// <param name="valueTo"> The value to which the member will be set. </param>
        /// <param name="menuItemText"> Message describing the undo. </param>
        /// <param name="unityObject"> The UnityEngine.Object which holds the member which is being modified. </param>
        /// <param name="registerCompleteObjectUndo"> Set to true if full object hierarchy should be serialized for the Undo. This is needed for undoing changes to array size fields to function properly. </param>
        /// <returns> True if should call EditorUtility.SetDirty after value has changed. </returns>
        public static bool RegisterUndoableAction([CanBeNull] Object unityObject, [NotNull] LinkedMemberInfo memberInfo, object valueTo, [NotNull] string menuItemText, bool registerCompleteObjectUndo)
        {
            if (disabled)
            {
                                #if DEV_MODE && DEBUG_UNDO
                Debug.Log("RegisterUndoableAction with undoText=" + StringUtils.ToString(menuItemText) + " " + StringUtils.Red("ABORTING..."));
                                #endif
                return(false);
            }

                        #if UNITY_EDITOR
            if (unityObject != null && memberInfo.IsUnitySerialized)
            {
                                #if DEV_MODE && DEBUG_UNDO
                Debug.Log("RegisterUndoableSetValue " + StringUtils.Green("IsUnitySerialized") + " field=" + memberInfo + ", unityObject=" + StringUtils.ToString(unityObject.name) + ", valueTo=" + StringUtils.ToString(valueTo) + ", undoText=" + StringUtils.ToString(menuItemText) + ", registerCompleteObjectUndo=" + StringUtils.ToColorizedString(registerCompleteObjectUndo) + ", IsUnitySerialized=" + StringUtils.ToColorizedString(true) + ", registeredForUndoThisFrame.Contains(unityObject)=" + StringUtils.ToColorizedString(registeredForUndoThisFrame.Contains(unityObject)), unityObject);
                                #endif

                Instance().DoRegisterUndoableActionInternal(unityObject, memberInfo.DisplayName, registerCompleteObjectUndo);
                return(true);
            }
                        #endif

                        #if DEV_MODE && DEBUG_UNDO
            Debug.Log("RegisterUndoableSetValue " + StringUtils.Red("!IsUnitySerialized") + " field=" + memberInfo + ", unityObject=" + StringUtils.ToString(unityObject != null ? unityObject.name : "") + ", valueTo=" + StringUtils.ToString(valueTo) + ", undoText=" + StringUtils.ToString(menuItemText) + ", registerCompleteObjectUndo=" + StringUtils.ToColorizedString(registerCompleteObjectUndo) + ", IsUnitySerialized=" + StringUtils.ToColorizedString(false) + ", registeredForUndoThisFrame.Contains(unityObject)=" + (unityObject == null ? StringUtils.Null : StringUtils.ToColorizedString(registeredForUndoThisFrame.Contains(unityObject))), unityObject);
                        #endif

            Instance().DoRegisterUndoableActionInternal(instance, menuItemText, registerCompleteObjectUndo);

            UndoableModification modification;
            try
            {
                modification = UndoableModification.Create(memberInfo, valueTo);
            }
                        #if DEV_MODE
            catch (SerializationException e)
            {
                Debug.LogError(e);
                        #else
            catch (SerializationException)
            {
                        #endif
                return(false);
            }

            instance.AddNewUndoableModification(modification);

                        #if SET_DIRTY_WHEN_NON_SERIALIZED_FIELDS_MODIFIED
            return(true);
                        #else
            return(false);
                        #endif
        }
Exemplo n.º 4
0
        /// <summary>
        /// Use this for adding Undo support for changes that are not serialized by Unity when Unity can't handle undoing the action
        /// </summary>
        /// <param name="targets"> The UnityEngine.Object targets which contain the members which are being modified. </param>
        /// <param name="memberInfo"> The LinkedMemberInfo for the members which are being modified. This cannot be null. </param>
        /// <param name="valuesTo"> The value to which the members will be set. </param>
        /// <param name="menuItemText"> Message describing the undo. </param>
        /// <param name="registerCompleteObjectUndo"> Set to true if full object hierarchy should be serialized for the Undo. This is needed for undoing changes to array size fields to function properly. </param>
        /// <returns> True if should call EditorUtility.SetDirty after value has changed. </returns>
        public static bool RegisterUndoableAction(Object[] targets, [NotNull] LinkedMemberInfo memberInfo, object[] valuesTo, [NotNull] string menuItemText, bool registerCompleteObjectUndo)
        {
            if (disabled)
            {
                                #if DEV_MODE && DEBUG_UNDO
                Debug.Log("RegisterUndoableAction with undoText=" + StringUtils.ToString(menuItemText) + " " + StringUtils.Red("ABORTING..."));
                                #endif
                return(false);
            }

                        #if UNITY_EDITOR
            if (targets.Length > 0 && memberInfo.IsUnitySerialized)
            {
                                #if DEV_MODE && DEBUG_UNDO
                Debug.Log("RegisterUndoableAction with " + StringUtils.Green("IsUnitySerialized") + " field=" + memberInfo + ", unityObject=" + StringUtils.ToString(targets[0].name) + ", valuesTo=" + StringUtils.ToString(valuesTo) + ", undoText=" + StringUtils.ToString(menuItemText) + ", registerCompleteObjectUndo=" + StringUtils.ToColorizedString(registerCompleteObjectUndo) + ", IsUnitySerialized=" + StringUtils.ToColorizedString(true) + ", registeredForUndoThisFrame.Contains(targets[0])=" + StringUtils.ToColorizedString(registeredForUndoThisFrame.Contains(targets[0])), targets[0]);
                                #endif

                Instance().DoRegisterUndoableActionInternal(targets, menuItemText, registerCompleteObjectUndo);
                return(true);
            }
                        #endif

                        #if DEV_MODE && DEBUG_UNDO
            Debug.Log(StringUtils.ToColorizedString("RegisterUndoableAction with IsUnitySerialized=", memberInfo.IsUnitySerialized, " memberInfo=", memberInfo.ToString(), ", targets=", StringUtils.ToString(targets), ", valuesTo=", StringUtils.ToString(valuesTo), ", menuItemText=" + StringUtils.ToString(menuItemText), ", registerCompleteObjectUndo=", registerCompleteObjectUndo, ", registeredForUndoThisFrame.Contains(targets[0])=", (targets.Length == 0 ? "n/a" : StringUtils.ToColorizedString(registeredForUndoThisFrame.Contains(targets[0])))));
                        #endif

            Instance().DoRegisterUndoableActionInternal(instance, menuItemText);             //register full undo or not?
            UndoableModification modification;
            try
            {
                modification = UndoableModification.Create(memberInfo, valuesTo);
            }
                        #if DEV_MODE
            catch (SerializationException e)
            {
                Debug.LogError(e);
                        #else
            catch (SerializationException)
            {
                        #endif
                return(false);
            }

            instance.AddNewUndoableModification(modification);

                        #if SET_DIRTY_WHEN_NON_SERIALIZED_FIELDS_MODIFIED
            return(true);
                        #else
            return(false);
                        #endif
        }
Exemplo n.º 5
0
        private void AddNewUndoableModification(UndoableModification modification)
        {
            // Make sure that undoIndexNonSerialized and undoIndexSerialized are in sync.
            // They could perhaps be out of sync e.g. an assembly reload reset undoIndexNonSerialized to its default
            // value but did not reset undoIndexSerialized.
            if (undoIndexNonSerialized != undoIndexSerialized)
            {
                undoIndexSerialized = undoIndexNonSerialized;
            }

            // After a new undo command, discard all modifications that were undone by the user.
            // After this they can no longer be redone.
            int modificationsCount = modifications.Count;

            while (modificationsCount > UndoIndex)
            {
                modificationsCount--;
                modifications.RemoveAt(modificationsCount);
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(modificationsCount == UndoIndex);
            Debug.Assert(modifications.Count == UndoIndex);
            Debug.Assert(undoIndexSerialized == undoIndexNonSerialized);
            Debug.Assert(undoIndexSerialized == UndoIndex);
                        #endif

            if (modifications.Count >= MaxUndoableActions)
            {
                var oldestUndoable = modifications[0];
                Dispose(ref oldestUndoable);
                modifications.RemoveAt(0);
            }

            modifications.Add(modification);
            UndoIndex = modifications.Count;

                        #if DEV_MODE && DEBUG_UNDO
            Debug.Log("New undoable registered: " + modification);
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(modifications.Count <= MaxUndoableActions);
            Debug.Assert(UndoIndex == modifications.Count);
                        #endif
        }
Exemplo n.º 6
0
 private static void Dispose(ref UndoableModification disposing)
 {
     disposing.Dispose();
     pool.Dispose(ref disposing);
 }