public void RemoveGraph(IBehaviourContext context) { foreach (BehaviourNode node in Nodes) { BehaviourNode behaviourNode = (BehaviourNode)node; behaviourNode.RemoveContext(context); foreach (OutputSocket data in node.Outputs) { if (data == null) { continue; } data.RemoveContext(context); } foreach (InputSocket data in node.Inputs) { if (data == null) { continue; } data.RemoveContext(context); } } }
private void AddNodeCallback(object type, Vector2 mousePosition) { BehaviourNode node = (BehaviourNode)AddAction((Type)type); node.Position = (mousePosition - dragging_Position) - (node.GetDiamentions() * 0.5f); Repaint(); }
private void DuplicateNode(BehaviourNode original) { BehaviourNode node = (BehaviourNode)DuplicateAction(original); Vector2 diamentions = rightClickedNode.GetDiamentions(); node.Position += new Vector2(diamentions.x * 0.25f, diamentions.y * 0.5f); Repaint(); }
private void DrawConnections() { if (Event.current.type == EventType.MouseMove) { return; } if (Event.current.type != EventType.Repaint) { return; } for (int i = 0; i < targetGraph.Nodes.Count; i++) { BehaviourNode node = targetGraph.Nodes[i]; if (node == null) { continue; } foreach (InputSocket inputSocket in node.Inputs) { if (inputSocket == null) { continue; } OutputSocket outputSocket = inputSocket.SourceSocket; if (outputSocket == null) { continue; } Rect inputSocketRect = new Rect( inputSocket.socketRect.x + node.Position.x + dragging_Position.x, inputSocket.socketRect.y + node.Position.y + dragging_Position.y, inputSocket.socketRect.width, inputSocket.socketRect.height); Rect outputSocketRect = new Rect( outputSocket.socketRect.x + inputSocket.SourceNode.Position.x + dragging_Position.x, outputSocket.socketRect.y + inputSocket.SourceNode.Position.y + dragging_Position.y, outputSocket.socketRect.width, outputSocket.socketRect.height); inputSocket.DrawConnection(new Vector3(inputSocketRect.xMax, inputSocketRect.center.y), new Vector3(outputSocketRect.xMin, outputSocketRect.center.y), Vector3.left, Vector3.right); } } }
private void DrawNodes() { if (Event.current.type == EventType.MouseMove) { return; } if (drawNodeGUI == null) { drawNodeGUI = new GUI.WindowFunction(DrawNodeWindow); } Color originalColor = GUI.color; BeginWindows(); for (int i = 0; i < targetGraph.Nodes.Count; i++) { BehaviourNode node = targetGraph.Nodes[i]; if (node == null) { targetGraph.Nodes.RemoveAt(i); EndWindows(); return; } if (dragging_IsDragging && Event.current.type == EventType.MouseDrag) { return; } Vector2 contentSize = node.GetDiamentions(); GUI.color = originalColor; Rect newRect = GUI.Window(i, new Rect(node.Position.x + dragging_Position.x, node.Position.y + dragging_Position.y, contentSize.x, contentSize.y + 22), drawNodeGUI, new GUIContent(node.name)); node.LastRect = newRect; node.Position.x = newRect.x - dragging_Position.x; node.Position.y = newRect.y - dragging_Position.y; } GUI.color = originalColor; EndWindows(); GUI.color = originalColor; }
private void DrawSockets() { Color originalColor = GUI.color; for (int i = 0; i < targetGraph.Nodes.Count; i++) { BehaviourNode node = targetGraph.Nodes[i]; if (node == null) { continue; } foreach (InputSocket thisInput in node.Inputs) { if (thisInput == null) { continue; } Rect socketRect = thisInput.socketRect; socketRect = new Rect(socketRect.x + node.Position.x + dragging_Position.x, socketRect.y + node.Position.y + dragging_Position.y, socketRect.width, socketRect.height); thisInput.DrawSocket(socketRect); #if HOVER_EFFECTS if (connection_CanEdit) { OutputSocket linkedSocket = thisInput.SourceSocket; if (connection_Start != null) { if (IsValidAttach(connection_Start, thisInput)) { if (linkedSocket == null) { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } else { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowMinus); } } } else { if (linkedSocket == null) { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } else { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowMinus); } } } #endif if (connection_CanEdit && (currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseUp) && socketRect.Contains(currentEvent.mousePosition)) { if (currentEvent.button == 0) { if (connection_Start != null || currentEvent.type != EventType.MouseUp) { connection_End = thisInput; } if (connection_Start != null) { Attach(connection_Start, connection_End); connection_End = null; connection_Start = null; currentEvent.Use(); } } else if (currentEvent.button == 1) { Detatch(thisInput); } currentEvent.Use(); } } foreach (OutputSocket thisOutput in node.Outputs) { if (thisOutput == null) { continue; } Rect socketRect = thisOutput.socketRect; socketRect = new Rect(socketRect.x + node.Position.x + dragging_Position.x, socketRect.y + node.Position.y + dragging_Position.y, socketRect.width, socketRect.height); thisOutput.DrawSocket(socketRect); if (connection_CanEdit) { #if HOVER_EFFECTS if (connection_End != null) { if (IsValidAttach(thisOutput, connection_End)) { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } } else { EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus); } #endif if ((currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseUp) && socketRect.Contains(currentEvent.mousePosition)) { if (currentEvent.button == 0) { if (connection_End != null || currentEvent.type != EventType.MouseUp) { connection_Start = thisOutput; } if (connection_End != null) { Attach(connection_Start, connection_End); connection_End = null; connection_Start = null; } currentEvent.Use(); } else if (currentEvent.button == 1) { Detatch(thisOutput); Repaint(); currentEvent.Use(); } } } } } GUI.color = originalColor; }
private void DrawNodeWindow(int id) { if (Event.current.type == EventType.Layout) { return; } BehaviourNode node = targetGraph.Nodes[id]; if (EventType.MouseDown == currentEvent.type || EventType.MouseUp == currentEvent.type || EventType.MouseDrag == currentEvent.type || EventType.MouseMove == currentEvent.type) { selectedWindow = id; EditorUtility.SetDirty(node); } if (!node.LastRect.Overlaps(screenRect)) { return; } Rect settingsRect = new Rect(node.LastRect.width - 20, 5, 20, 20); Rect iconRect = new Rect(0, 0, 18, 18); if (GUI.Button(settingsRect, "", BehaviourGUIStyles.Instance.settingsStyle)) { rightClickedNode = node; BasicNodeMenu.ShowAsContext(); } Color originalColour = GUI.color; GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.65f); EditorGUI.LabelField(iconRect, new GUIContent(AssetPreview.GetMiniThumbnail(node))); GUI.color = originalColour; if (currentEvent.type == EventType.MouseDown) { if (iconRect.Contains(currentEvent.mousePosition)) { if (currentEvent.button == 0) { if (currentEvent.clickCount == 1) { rightClickedNode = node; PingSourceCallback(); } else { rightClickedNode = node; OpenScriptCallback(); } currentEvent.Use(); } } } SerializedObject serializedObject = SerializedObjectPool.Grab(node); //Undo.RecordObject (node, "Edit Node"); float originalLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = node.LastRect.width / 2; serializedObject.FindProperty("Position").vector2Value = node.Position; //EditorGUI.BeginChangeCheck (); //string newName = EditorGUILayout.DelayedTextField (node.name); //if (EditorGUI.EndChangeCheck ()) //{ // RenameAction (node, newName); //} Rect contentRect = BehaviourGraphResources.Instance.NodeStyle.padding.Remove(node.LastRect); node.DrawGUI(serializedObject, new Rect(contentRect.x - node.Position.x - dragging_Position.x, contentRect.y - node.Position.y - dragging_Position.y, contentRect.width, contentRect.height)); serializedObject.ApplyModifiedProperties(); if (currentEvent.type == EventType.MouseDown) { if (currentEvent.button == 1) { rightClickedNode = node; BasicNodeMenu.ShowAsContext(); } } EditorGUIUtility.labelWidth = originalLabelWidth; #if HOVER_EFFECTS if (connection_Start == null && connection_End == null) { EditorGUIUtility.AddCursorRect(new Rect(node.LastRect.x - node.Position.x - dragging_Position.x, node.LastRect.y - node.Position.y - dragging_Position.y, node.LastRect.width, node.LastRect.height), MouseCursor.MoveArrow); } #endif if (currentEvent.button != 2) { GUI.DragWindow(); } }