/// <summary> Record an action that can be reversed </summary> /// <param name="window"> Source window </param> /// <param name="objects"> What objects need to be saved for undo purposes </param> /// <param name="message"> Undo message describing the action that can be reversed if performing this undo </param> public void RecordUndo(NodyWindow window, List <Object> objects, string message) { if (m_cachedUndoObjects == null || //check that the cache is not null m_undoObjectsCount != (objects == null ? 0 : objects.Count) || //check the undo steps ArrayUtility.Contains(m_cachedUndoObjects, null)) //make sure this step is not null { UpdateUndoCacheObject(window, objects); //add this step to the undo cache } if (m_cachedUndoObjects != null) { Undo.RecordObjects(m_cachedUndoObjects, message); //add this undo to the UnityEditor } }
/// <summary> Add and undo step to the undo cache </summary> /// <param name="window"> Source window </param> /// <param name="objects"> What objects need to be saved for undo purposes </param> private void UpdateUndoCacheObject(NodyWindow window, List <Object> objects) { m_objects.Clear(); //clear any previous entries in the objects list if (window != null) { m_objects.Add(window); //sanity check and add this window to the cache } m_objects.Add(WindowSettings); //add the editor settings to the undo cache if (objects != null) //check that at lease one object was sent with this undo step { foreach (Object obj in objects) //add all the sent objects (that need to be saved) to the objects list { if (obj != null) { m_objects.Add(obj); } } } m_cachedUndoObjects = m_objects.ToArray(); //update the undo cache m_undoObjectsCount = objects == null ? 0 : objects.Count; //update the undo steps count }