/// <summary> /// Undocumented Unity callback to draw a button in the window tab. /// Draws the selection lock button. /// <param name="rect">The button rect.</param> /// </summary> void ShowButton(Rect rect) { // Create style? if (s_Styles == null) { s_Styles = new BehaviourWindow.Styles(); } // Shows the lock icon if (GUI.Toggle(rect, m_Lock, GUIContent.none, s_Styles.lockButton) != m_Lock) { // Ping game object ParentBehaviour parent = activeParent; if (parent != null) { EditorGUIUtility.PingObject(parent.gameObject); } // Toggle lock m_Lock = !m_Lock; // The selection is not locked? if (!m_Lock) { // Update selection OnSelectionChange(); } } }
/// <summary> /// Undocumented Unity callback to draw a button in the window tab. /// Draws the selection lock button. /// <param name="rect">The button rect.</param> /// </summary> void ShowButton (Rect rect) { // Create style? if (s_Styles == null) s_Styles = new BehaviourWindow.Styles(); // Shows the lock icon if (GUI.Toggle(rect, m_Lock, GUIContent.none, s_Styles.lockButton) != m_Lock) { // Ping game object ParentBehaviour parent = activeParent; if (parent != null) EditorGUIUtility.PingObject(parent.gameObject); // Toggle lock m_Lock = !m_Lock; // The selection is not locked? if (!m_Lock) { // Update selection OnSelectionChange(); } } }
/// <summary> /// Unity callback used to draw controls in the window. /// Draws the toolbar, the gui parent and the blackboard view. /// </summary> void OnGUI () { // Debug.Log(Event.current); // Create style? if (s_Styles == null) s_Styles = new BehaviourWindow.Styles(); // Refresh active objects during UndoRedoPerformed command if (!EditorApplication.isPlaying && Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { // Reload tree var tree = BehaviourWindow.activeTree; if (tree != null) { tree.LoadNodes(); // Force node selection update activeNodeID = activeNodeID; } // Update the active parent var lastSelectedParent = activeParent; var selectedState = Selection.activeObject as InternalStateBehaviour; if (lastSelectedParent == null || (selectedState != null && selectedState.parent != lastSelectedParent)) { var selectedParent = selectedState as ParentBehaviour; if (selectedParent != null) activeParent = selectedParent; } Refresh(); // Repaint(); return; } // Refresh window? if (InternalStateBehaviour.refresh) { // Workaround for the missing revert prefab button Unity callback... Refresh(); } // Draw toolbar DoStatusBarGUI(); // Draw the gui parent and the blackboard view GUI.BeginGroup(new Rect(0, EditorStyles.toolbar.fixedHeight - 2, position.width, position.height), ""); { if (m_ParentGUI != null && activeParent != null) { // Get the blackboard InternalBlackboard activeBlackboard = EditorUtility.InstanceIDToObject(m_ActiveBlackboardID) as InternalBlackboard; // Get the blackboard view rect and height float blackboardHeight = BlackboardGUIUtility.GetHeight(activeBlackboard) + 2f; float blackboardViewHeight = GetBlackboardViewHeight(blackboardHeight); Rect blackboardViewRect = new Rect (0f, position.height - blackboardViewHeight - 17f, 260f, blackboardViewHeight); // Show Scroll View? if (BehaviourMachinePrefs.showScrollView) blackboardViewRect.y -= 16f; // Get event type EventType eventType = Event.current.type; // Should ignore event? if (ShouldIgnoreEvent(blackboardViewRect)) { Event.current.type = EventType.Ignore; } m_ParentGUI.OnGUIBeforeWindows(); BeginWindows(); m_ParentGUI.OnGUIWindows(); EndWindows(); m_ParentGUI.OnGUIAfterWindows(); // Restore event? if (Event.current.type != EventType.Used) Event.current.type = eventType; // Draw variables if (activeBlackboard != null) DrawBlackboardView(blackboardViewRect, activeBlackboard, blackboardHeight); } // Show notification message else if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { ShowNotification(new GUIContent("Select a Game Object and right click in this window")); } } GUI.EndGroup(); // Show context menu? if (Event.current.type == EventType.ContextClick) { OnContextMenu(); Event.current.Use(); } }
/// <summary> /// Unity callback used to draw controls in the window. /// Draws the toolbar, the gui parent and the blackboard view. /// </summary> void OnGUI() { // Debug.Log(Event.current); // Create style? if (s_Styles == null) { s_Styles = new BehaviourWindow.Styles(); } // Refresh active objects during UndoRedoPerformed command if (!EditorApplication.isPlaying && Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") { // Reload tree var tree = BehaviourWindow.activeTree; if (tree != null) { tree.LoadNodes(); // Force node selection update activeNodeID = activeNodeID; } // Update the active parent var lastSelectedParent = activeParent; var selectedState = Selection.activeObject as InternalStateBehaviour; if (lastSelectedParent == null || (selectedState != null && selectedState.parent != lastSelectedParent)) { var selectedParent = selectedState as ParentBehaviour; if (selectedParent != null) { activeParent = selectedParent; } } Refresh(); // Repaint(); return; } // Refresh window? if (InternalStateBehaviour.refresh) { // Workaround for the missing revert prefab button Unity callback... Refresh(); } // Draw toolbar DoStatusBarGUI(); DrawSearch(); // Draw the gui parent and the blackboard view GUI.BeginGroup(new Rect(0, EditorStyles.toolbar.fixedHeight - 2 + 25, position.width, position.height), ""); { if (m_ParentGUI != null && activeParent != null) { // Get the blackboard InternalBlackboard activeBlackboard = EditorUtility.InstanceIDToObject(m_ActiveBlackboardID) as InternalBlackboard; // Get the blackboard view rect and height float blackboardHeight = BlackboardGUIUtility.GetHeight(activeBlackboard) + 2f; float blackboardViewHeight = GetBlackboardViewHeight(blackboardHeight); Rect blackboardViewRect = new Rect(0f, position.height - blackboardViewHeight - 17f, 260f, blackboardViewHeight); // Show Scroll View? if (BehaviourMachinePrefs.showScrollView) { blackboardViewRect.y -= 16f; } // Get event type EventType eventType = Event.current.type; // Should ignore event? if (ShouldIgnoreEvent(blackboardViewRect)) { Event.current.type = EventType.Ignore; } m_ParentGUI.OnGUIBeforeWindows(); BeginWindows(); m_ParentGUI.OnGUIWindows(); EndWindows(); m_ParentGUI.OnGUIAfterWindows(); // Restore event? if (Event.current.type != EventType.Used) { Event.current.type = eventType; } // Draw variables if (activeBlackboard != null) { DrawBlackboardView(blackboardViewRect, activeBlackboard, blackboardHeight); } } // Show notification message else if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { ShowNotification(new GUIContent("Select a Game Object and right click in this window")); } } GUI.EndGroup(); // Show context menu? if (Event.current.type == EventType.ContextClick) { OnContextMenu(); Event.current.Use(); } }