void DrawToolbarGUI(float width) { Rect rect = new Rect(0, 0, width, Styles.toolbarHeight); Rect toggleRect = new Rect(0, 0, 90, rect.height); Rect clearGraphUndoRect = new Rect(toggleRect.xMax + 1, 0, 45, rect.height); Rect clearAllUndoRect = new Rect(clearGraphUndoRect.xMax - 1, 0, 60, rect.height); Rect plusRect = new Rect(rect.width - 20 - Styles.scrollbarWidth, 0, 20, rect.height); Rect minusRect = new Rect(plusRect.x - 20 - 1, 0, 20, rect.height); EditorGUI.Toolbar(rect, false, true, false, true); m_showUnityRecords = EditorGUI.Toggle(toggleRect, m_showUnityRecords, "Unity Records"); GUI.enabled = GraphUndo.hasUndo || GraphUndo.hasRedo; if (EditorGUI.Button(clearGraphUndoRect, "Clear")) { GraphUndo.Clear(); } GUI.enabled = GraphUndo.hasUnityUndo || GraphUndo.hasUnityRedo; if (EditorGUI.Button(clearAllUndoRect, "Clear All", Styles.clearAllButtonHoverColor)) { if (EditorUtility.DisplayDialog(clearUnityHistoryTitle, clearUnityHistoryMessage, "Clear", "Don't Clear")) { GraphUndo.ClearAll(); } } GUI.enabled = GraphUndo.hasUnityUndo; if (EditorGUI.Button(minusRect, "<")) { UnityEditor.Undo.PerformUndo(); } GUI.enabled = GraphUndo.hasUnityRedo; if (EditorGUI.Button(plusRect, ">")) { UnityEditor.Undo.PerformRedo(); } GUI.enabled = true; }
void EditorApplicationOnPlayModeStateChanged(PlayModeStateChange state) { switch (state) { case PlayModeStateChange.EnteredEditMode: #if GRAPH_DEBUG Debug.Log("[AI Graph]: Enter edit mode"); #endif // If the graph enters edit mode. // Try to load the current selected controller // Load the controller before the edit mode was exited. // Set the last toggle index if it was node parameter or exposed parameter, // and the current isn't for the history. if (!TryLoadSelectedController()) { LoadController(controllerBeforeEditModeExited, aiBehaviourBeforeEditModeExited, true); } if (m_leftPanelSelectedToggleIndexBeforeEditModeExited == 0 || m_leftPanelSelectedToggleIndexBeforeEditModeExited == 1 && m_leftPanelSelectedToggleIndex != 2) { m_leftPanelSelectedToggleIndex = m_leftPanelSelectedToggleIndexBeforeEditModeExited; } break; case PlayModeStateChange.ExitingEditMode: #if GRAPH_DEBUG Debug.Log("[AI Graph]: Exit edit mode: Save current controller"); #endif // If the graph wants to exiting the edit mode, // save the current controller and left panel toggle index. controllerBeforeEditModeExited = controller; aiBehaviourBeforeEditModeExited = aiBehaviour; m_leftPanelSelectedToggleIndexBeforeEditModeExited = m_leftPanelSelectedToggleIndex; // We need to clear the undo list because of unity's serialization, // we are not able to serialize the anonymous action delegates. GraphUndo.Clear(); // Save and cleanup all modified controllers. // Same problem of serialization. We cannot go back to a further point. Serializer.CleanupAll(); break; case PlayModeStateChange.EnteredPlayMode: #if GRAPH_DEBUG Debug.Log("[AI Graph]: Enter play mode"); #endif // If the graph entered play mode, // try to load the current selected controller. // If no controller is selected check if the loaded // ai has a runtimeController and load that. // Else load the loaded controller or null if no one is loaded. if (!TryLoadSelectedController()) { if (aiBehaviour != null) { if (aiBehaviour.runtimeController != null) { LoadController(aiBehaviour.runtimeController, aiBehaviour, true); } } else { LoadController(controller, null, true); } } break; case PlayModeStateChange.ExitingPlayMode: #if GRAPH_DEBUG Debug.Log("[AI Graph]: Exit play mode"); #endif // If we modified runtimeController, // clear the undo-list because they are not persistent and we cannot go back. GraphUndo.Clear(); break; } }