private void PaintSort(BehaviorWindow window, Event currentEvent) { if (GUILayout.Button(GC_SORT, EditorStyles.toolbarButton)) { List <BehaviorSort.Data> datas = BehaviorSort.Sort( window.behaviorGraph.root, window.behaviorGraphEditor ); if (datas.Count > 0) { Vector2 offset = new Vector2( datas[0].blockWidth / 2f, 100f ); for (int i = 0; i < datas.Count; ++i) { BehaviorSort.Data data = datas[i]; NodeEditor editor = window.behaviorGraphEditor.nodeEditors[data.nodeID]; editor.SetEditorPosition(data.position - offset); } } } }
private void UpdateMouseDown(BehaviorWindow window, Event currentEvent) { if (currentEvent.button != 0) { return; } if (HOVER_IS_BLACKBOARD || HOVER_IS_TOOLBAR) { return; } if (HOVER_IS_OUTPUT) { this.draggingPort = true; DRAGGED_NODE_OUTPUT = HOVER_NODE; } else if (HOVER_NODE != null) { this.draggingNode = true; List <UnityEngine.Object> selection = new List <UnityEngine.Object>(); selection.AddRange(Selection.objects); if (!currentEvent.control && !currentEvent.shift && !currentEvent.command && !selection.Contains(HOVER_NODE)) { selection.Clear(); } selection.Add(HOVER_NODE); Selection.objects = selection.ToArray(); } this.RecalculateDragOffsets(window, currentEvent); }
private void PaintCreateNode(BehaviorWindow window, Event currentEvent) { if (GUILayout.Button(GC_CREATE, EditorStyles.toolbarPopup)) { window.behaviorGraphEditor.ShowCreateMenu(); } }
private void PaintNodeOutputConnections(BehaviorWindow window) { Rect rectA = this.GetNodeOutputRect(window, this.node); Vector2 pointA = rectA.position + new Vector2(rectA.width / 2f, rectA.height / 2f); for (int i = 0; i < this.node.outputs.Count; ++i) { if (this.node.outputs[i] == null) { continue; } Rect rectB = this.GetNodeInputRect(window, this.node.outputs[i]); Vector2 pointB = rectB.position + new Vector2(rectB.width / 2f, rectB.height / 2f); Texture2D texture = BehaviorResources.GetTexture( BehaviorResources.Name.Noodle, BehaviorResources.Format.LowRes ); int outputID = this.node.outputs[i].GetInstanceID(); Handles.color = this.GetCurrentStateColor(COLOR_NOODLE, outputID); Handles.DrawAAPolyLine(texture, 2, pointA, pointB); } }
public Rect PaintNodeOutput(BehaviorWindow window) { if (!this.HasOutput()) { return(Rect.zero); } Rect outputRect = this.GetNodeOutputRect(window, this.node); Texture2D texture = BehaviorResources.GetTexture( BehaviorResources.Name.OutputEmpty, BehaviorResources.Format.Auto ); if (this.node.outputs.Count > 0) { texture = BehaviorResources.GetTexture( BehaviorResources.Name.OutputLink, BehaviorResources.Format.Auto ); } Color color = this.GetCurrentStateColor( (this.node.outputs.Count == 0 ? Color.white : COLOR_OUTPUT) ); GUI.DrawTexture( outputRect, texture, ScaleMode.StretchToFill, true, 1.0f, color, 0f, 0f ); return(outputRect); }
private void UpdateDragNode(BehaviorWindow window, Event currentEvent) { Vector2 mousePosition = window.WindowToGridPosition(currentEvent.mousePosition); for (int i = 0; i < Selection.objects.Length; ++i) { if (Selection.objects[i] is Node) { Node node = Selection.objects[i] as Node; int nodeID = node.GetInstanceID(); NodeEditor nodeEditor = window.behaviorGraphEditor.nodeEditors[nodeID]; Vector2 nodePosition = mousePosition + dragOffsets[i]; if (GRID_SNAP) { nodePosition = new Vector2( Mathf.Round(nodePosition.x), Mathf.Round(nodePosition.y) ); } nodeEditor.SetEditorPosition(nodePosition); window.behaviorGraphEditor.RearrangeExecutionIndexes(node.input); } } window.Repaint(); }
private void PaintFullscreen(BehaviorWindow window, Event currentEvent) { string text = (window.maximized ? "Minimize" : "Maximize"); window.maximized = GUILayout.Toggle( window.maximized, text, EditorStyles.toolbarButton ); }
private void RemoveSelectedNodes(BehaviorWindow window) { for (int i = Selection.objects.Length - 1; i >= 0; --i) { if (Selection.objects[i] is Node) { Node node = Selection.objects[i] as Node; window.behaviorGraphEditor.RemoveNode(node); } } }
// PRIVATE METHODS: ----------------------------------------------------------------------- private void PaintBlackboard(BehaviorWindow window, Event currentEvent) { bool show = GUILayout.Toggle( window.windowBlackboard.GetShow(), GC_BLACKBOARD, EditorStyles.toolbarButton ); window.windowBlackboard.Show(show); window.Repaint(); }
private Rect GetNodeOutputRect(BehaviorWindow window, Node node) { Rect nodeRect = this.GetNodeRect(window, node); return(new Rect( nodeRect.x + nodeRect.width / 2.0f - IO_SIZE / 2f, nodeRect.y + nodeRect.height + IO_PADDING, IO_SIZE, IO_SIZE )); }
private Rect GetNodeRect(BehaviorWindow window, Node node) { Vector2 position = window.GridToWindowPositionNoClipped(node.position); int nodeID = node.GetInstanceID(); return(new Rect( position.x, position.y, window.behaviorGraphEditor.nodeEditors[nodeID].GetNodeWidth(), window.behaviorGraphEditor.nodeEditors[nodeID].GetNodeHeight() )); }
// PRIVATE METHODS: ----------------------------------------------------------------------- private void PaintHeader(BehaviorWindow window, Event currentEvent) { Rect rect = GUILayoutUtility.GetRect(0f, 4000f, 30f, 30f); GUI.DrawTexture( new Rect(rect.x, rect.y + rect.height - 1f, rect.width, 1f), Texture2D.whiteTexture, ScaleMode.StretchToFill, true, 1.0f, COLOR_SEPARATOR, 0f, 0f ); GUI.Box(rect, "Blackboard", BehaviorStyles.GetBlackboardHeader()); }
// INSPECTOR PAINT METHOD: ---------------------------------------------------------------- public override void OnInspectorGUI() { if (GUILayout.Button("Open")) { if (this.target == null) { return; } int instanceID = this.target.GetInstanceID(); BehaviorWindow.OnOpenAsset(instanceID, 0); } }
// INITIALIZERS: -------------------------------------------------------------------------- public BehaviorWindowEvents(BehaviorWindow window) { this.zoom = MIN_ZOOM; this.pan = Vector2.zero; if (window.behaviorGraph != null) { this.zoom = window.behaviorGraph.zoom; this.pan = window.behaviorGraph.position; } this.draggingNode = false; this.draggingPort = false; }
public void PaintDragConnection(BehaviorWindow window) { Rect rectA = this.GetNodeOutputRect(window, this.node); Vector2 pointA = rectA.position + new Vector2(rectA.width / 2f, rectA.height / 2f); Vector2 pointB = UnityEngine.Event.current.mousePosition; Texture2D texture = BehaviorResources.GetTexture( BehaviorResources.Name.Noodle, BehaviorResources.Format.LowRes ); Handles.color = COLOR_N_DRAG * new Color(1, 1, 1, 0.5f); Handles.DrawAAPolyLine(texture, 2, pointA, pointB); }
public void Update(BehaviorWindow window, Event currentEvent) { window.wantsMouseMove = true; switch (currentEvent.type) { case EventType.ScrollWheel: this.UpdateZoom(window, currentEvent); break; case EventType.MouseDrag: if (currentEvent.button == 0) { if (this.draggingNode) { this.UpdateDragNode(window, currentEvent); } else if (this.draggingPort) { this.UpdateDragPort(window, currentEvent); } } else if (currentEvent.button == 1 || currentEvent.button == 2) { this.UpdatePan(window, currentEvent); } break; case EventType.MouseDown: this.UpdateMouseDown(window, currentEvent); window.Repaint(); break; case EventType.MouseUp: this.UpdateMouseUp(window, currentEvent); window.Repaint(); break; case EventType.ValidateCommand: case EventType.ExecuteCommand: this.UpdateCommands(window, currentEvent); break; } if (!HOVER_IS_TOOLBAR && !HOVER_IS_BLACKBOARD) { Vector2 position = currentEvent.mousePosition; MOUSE_POSITION = window.WindowToGridPosition(position); } }
// PAINT NODE METHODS: -------------------------------------------------------------------- public Rect PaintNode(BehaviorWindow window) { if (target == null || serializedObject == null) { return(Rect.zero); } serializedObject.Update(); Rect nodeRect = this.GetNodeRect(window, this.node); GUI.DrawTexture( nodeRect, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1f, COLOR_NODE, 0f, UI_BORDER_RADIUS ); GUILayout.BeginArea(nodeRect); this.PaintHead(); this.PaintBody(); GUILayout.EndArea(); if (Selection.Contains(this.node)) { Rect nodeSelectRect = new Rect( nodeRect.x - SELECT_BORDER_OFFSET, nodeRect.y - SELECT_BORDER_OFFSET, nodeRect.width + (SELECT_BORDER_OFFSET * 2), nodeRect.height + (SELECT_BORDER_OFFSET * 2) ); this.PaintNodeHighlight(nodeSelectRect, SELECT_COLOR, SELECT_BORDER_RADIUS); } if (EditorApplication.isPlaying) { this.PaintRuntimeState(nodeRect); } this.PaintNodeOutputConnections(window); GUI.DrawTexture( nodeRect, Texture2D.whiteTexture, ScaleMode.StretchToFill, true, 1f, COLOR_NODE_BORDER, 1f, UI_BORDER_RADIUS ); serializedObject.ApplyModifiedPropertiesWithoutUndo(); return(nodeRect); }
private void PaintZoom(BehaviorWindow window, Event currentEvent) { float zoom = GUILayout.HorizontalSlider( window.windowEvents.zoom, BehaviorWindowEvents.MIN_ZOOM, BehaviorWindowEvents.MAX_ZOOM, GUILayout.Width(ZOOM_WIDTH) ); if (!Mathf.Approximately(zoom, window.windowEvents.zoom)) { window.windowEvents.SetZoom(zoom); window.Repaint(); } }
// PRIVATE METHODS: ----------------------------------------------------------------------- private void RecalculateDragOffsets(BehaviorWindow window, Event currentEvent) { this.dragOffsets = new Vector2[Selection.objects.Length]; for (int i = 0; i < Selection.objects.Length; i++) { if (Selection.objects[i] is Node) { Node node = Selection.objects[i] as Node; this.dragOffsets[i] = node.position - window.WindowToGridPosition(currentEvent.mousePosition); } else { this.dragOffsets[i] = Vector2.zero; } } }
private void UpdatePan(BehaviorWindow window, Event currentEvent) { if (HOVER_IS_BLACKBOARD || HOVER_IS_TOOLBAR) { return; } Vector2 tmpOffset = this.pan; tmpOffset += currentEvent.delta * zoom; tmpOffset.x = Mathf.Round(tmpOffset.x); tmpOffset.y = Mathf.Round(tmpOffset.y); this.pan = tmpOffset; window.behaviorGraphEditor.UpdateGraph(this.pan, this.zoom); window.Repaint(); }
// PUBLIC METHODS: ------------------------------------------------------------------------ public void Update(BehaviorWindow window, Event currentEvent) { GUILayout.BeginArea(new Rect( 0f, window.position.height - 18f, window.position.width, 18f )); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); int index = 0; if (window.stackBehaviorGraphs != null) { foreach (BehaviorGraph behaviorGraph in window.stackBehaviorGraphs) { if (behaviorGraph == null) { continue; } this.PaintBreadcrumb( index, behaviorGraph.name, behaviorGraph ); ++index; } } BehaviorGraph currentGraph = window.behaviorGraph; if (currentGraph != null) { this.PaintBreadcrumb( index, currentGraph.name, currentGraph, true ); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.EndArea(); }
// UPDATE METHODS: ------------------------------------------------------------------------ private void UpdateZoom(BehaviorWindow window, Event currentEvent) { if (HOVER_IS_BLACKBOARD || HOVER_IS_TOOLBAR) { return; } if (currentEvent.delta.y > 0) { this.SetZoom(zoom + 0.1f * zoom); } else { this.SetZoom(zoom - 0.1f * zoom); } window.behaviorGraphEditor.UpdateGraph(this.pan, this.zoom); window.Repaint(); }
private void UpdateCommands(BehaviorWindow window, Event currentEvent) { bool isDeleteCommand = (currentEvent.commandName == "SoftDelete"); isDeleteCommand |= ( SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX && currentEvent.commandName == "Delete" ); if (isDeleteCommand) { if (currentEvent.type == EventType.ExecuteCommand) { this.RemoveSelectedNodes(window); } currentEvent.Use(); window.Repaint(); } }
public void Update(BehaviorWindow window, Event currentEvent) { if (this.isOpen.faded < 0.0001) { return; } Rect rect = new Rect( (this.isOpen.faded * WINDOW_WIDTH) - WINDOW_WIDTH, EditorStyles.toolbar.fixedHeight + WNDOW_MARGIN_TOP, WINDOW_WIDTH, window.position.height - (WNDOW_MARGIN_TOP + WINDOW_BOTTOM) ); if (Event.current.type != EventType.Layout) { BehaviorWindowEvents.HOVER_IS_BLACKBOARD = rect.Contains(currentEvent.mousePosition); } Color color = (EditorGUIUtility.isProSkin ? BehaviorStyles.COLOR_BG_PRO : BehaviorStyles.COLOR_BG_PERSONAL ); GUI.DrawTexture( rect, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1.0f, color, 0f, 0f ); GUILayout.BeginArea(rect, BehaviorStyles.GetBlackboard()); window.behaviorGraphEditor.serializedObject.Update(); this.PaintHeader(window, currentEvent); this.PaintWindow(window, currentEvent); window.behaviorGraphEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo(); GUILayout.EndArea(); }
public Rect PaintNodeInput(BehaviorWindow window) { if (!this.HasInput()) { return(Rect.zero); } Rect inputRect = this.GetNodeInputRect(window, this.node); Texture2D texture = BehaviorResources.GetTexture( BehaviorResources.Name.InputEmpty, BehaviorResources.Format.Auto ); if (this.node.input != null) { texture = BehaviorResources.GetTexture( BehaviorResources.Name.InputLink, BehaviorResources.Format.Auto ); } Color color = this.GetCurrentStateColor( (this.node.input == null ? Color.white : COLOR_INPUT) ); GUI.DrawTexture( inputRect, texture, ScaleMode.StretchToFill, true, 1.0f, color, 0f, 0f ); if (this.node.input != null) { int value = this.node.input.outputs.FindIndex(node => node == this.node) + 1; EditorGUI.LabelField(inputRect, value.ToString(), BehaviorStyles.GetNodeInput()); } return(inputRect); }
// PUBLIC METHODS: ------------------------------------------------------------------------ public void Update(BehaviorWindow window, Event currentEvent) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); this.PaintBlackboard(window, currentEvent); this.PaintZoom(window, currentEvent); this.PaintSort(window, currentEvent); this.PaintCreateNode(window, currentEvent); GUILayout.FlexibleSpace(); this.PaintFullscreen(window, currentEvent); EditorGUILayout.EndHorizontal(); Rect rectToolbar = GUILayoutUtility.GetLastRect(); if (Event.current.type != EventType.Layout) { bool isHover = rectToolbar.Contains(currentEvent.mousePosition); BehaviorWindowEvents.HOVER_IS_TOOLBAR = isHover; } }
// INITIALIZERS: -------------------------------------------------------------------------- public BehaviorWindowBlackboard(BehaviorWindow window) { if (window.behaviorGraphEditor == null || window.behaviorGraphEditor.target == null || window.behaviorGraphEditor.serializedObject == null) { return; } this.isOpen = new AnimBool(false); this.isOpen.valueChanged.AddListener(window.Repaint); this.isOpen.speed = 3f; this.scroll = Vector2.zero; this.list = new ReorderableList( window.behaviorGraphEditor.serializedObject, window.behaviorGraphEditor.spBlackboardList, true, true, true, true ); this.list.drawHeaderCallback = DrawHeaderCallback; this.list.drawElementCallback = DrawElementCallback; this.list.elementHeight = EditorGUIUtility.singleLineHeight + 10f; }
private void UpdateMouseUp(BehaviorWindow window, Event currentEvent) { if (HOVER_IS_BLACKBOARD || HOVER_IS_TOOLBAR) { this.draggingNode = false; this.draggingPort = false; return; } if (currentEvent.button == 0) { if (this.draggingPort) { if (HOVER_IS_INPUT) { DRAGGED_NODE_INPUT = HOVER_NODE; if (DRAGGED_NODE_INPUT != null && DRAGGED_NODE_OUTPUT != null) { window.behaviorGraphEditor.CreateConnection( DRAGGED_NODE_OUTPUT, DRAGGED_NODE_INPUT ); window.behaviorGraphEditor.RearrangeExecutionIndexes( DRAGGED_NODE_OUTPUT ); } } else { Node parent = DRAGGED_NODE_OUTPUT; window.behaviorGraphEditor.ShowCreateMenu(parent); } } else if (HOVER_NODE == null) { Selection.objects = new Node[0]; Selection.activeObject = null; } } else if (currentEvent.button == 1) { if (HOVER_NODE != null) { if (HOVER_IS_INPUT) { window.behaviorGraphEditor.DisconnectInput(HOVER_NODE); } else if (HOVER_IS_OUTPUT) { window.behaviorGraphEditor.DisconnectOutput(HOVER_NODE); } else { window.behaviorGraphEditor.ShowNodeMenu(HOVER_NODE); } } } this.draggingNode = false; this.draggingPort = false; }
private void UpdateDragPort(BehaviorWindow window, Event currentEvent) { window.Repaint(); }
private void PaintWindow(BehaviorWindow window, Event currentEvent) { this.scroll = EditorGUILayout.BeginScrollView(this.scroll, BehaviorStyles.GetBlackboardBody()); this.list.DoLayoutList(); EditorGUILayout.EndScrollView(); }