public Connection(WorkflowCanvas canvas, RenderNode startPoint, RenderNode endPoint, ConnectingLine line) { this.Canvas = canvas; Line = line; if (startPoint.Node.GetConnectionType() == INodeConnectionType.OUTPUT && endPoint.Node.GetConnectionType() == INodeConnectionType.INPUT) { Input = (BaseInputNode)endPoint.Node; Output = (BaseOutputNode)startPoint.Node; Start = startPoint; End = endPoint; } else if (startPoint.Node.GetConnectionType() == INodeConnectionType.INPUT && endPoint.Node.GetConnectionType() == INodeConnectionType.OUTPUT) { Input = (BaseInputNode)startPoint.Node; Output = (BaseOutputNode)endPoint.Node; Start = endPoint; End = startPoint; } contextMenu = new ContextMenu(); MenuItem item = new MenuItem(); item.Header = "Disconnect"; contextMenu.Items.Add(item); item.Click += delegate { Disconnect(); }; }
public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; selectedConnection = null; pos.x -= windowRect.x; pos.y -= windowRect.y; for (int i = 0; i < inputNodeRects.Length; i++) { if (inputNodeRects[i].Contains(pos)) { /*GenericMenu menu = new GenericMenu(); * for(int i = 0; i < inputNodes.Count; i++) * { * menu.AddItem(new GUIContent(""+ i), false, RemoveConnection, i); * } * menu.ShowAsContext(); * Debug.Log("calling method"); * retVal = selectedConnection; * inputNodes.Remove(retVal);*/ retVal = inputNodes; inputNodes = null; somethingChanged = true; AssetDatabase.SaveAssets(); } } return(retVal); }
public override void SetInput(BaseInputNode input, Vector2 clickPos) { clickPos.x -= windowRect.x; clickPos.y -= windowRect.y; for (int i = 0; i < inputNodeRects.Length; i++) { if (inputNodeRects[i].Contains(clickPos)) { //inputNodes[i].Add(input); if (!input.IsInInfiniteLoop(this)) { inputNodes[i].nodes.Add(input); if (!input.outputNodes.Contains(this)) { input.outputNodes.Add(this); } outputIsCalculated = false; iHaveBeenRecalculated(); } else { EditorUtility.DisplayDialog("Infinite Loop Error", "An infinite loop would be created by making that connection", "Okay"); } } } AssetDatabase.SaveAssets(); }
//we call it when we want to delete this node and checks if the deleted node is it's input and if it is, removes the input public override void NodeDeleted(BaseNode node) { if (node.Equals(inputNode)) { inputNode = null; } }
public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; selectedConnection = null; pos.x -= windowRect.x; pos.y -= windowRect.y; for (int i = 0; i < inputNodeRects.Length; i++) { if (inputNodeRects[i].Contains(pos) && inputNodes[i] != null) { /*GenericMenu menu = new GenericMenu(); * for(int i = 0; i < inputNodes.Count; i++) * { * menu.AddItem(new GUIContent(""+ i), false, RemoveConnection, i); * } * menu.ShowAsContext(); * Debug.Log("calling method"); * retVal = selectedConnection; * inputNodes.Remove(retVal);*/ /* * retVal = inputNodes[i][0]; * inputNodes[i] = new List<BaseInputNode>();*/ retVal = (BaseInputNode)inputNodes[i]; inputNodes[i] = null; variableNames[i] = "Var " + i; outputIsCalculated = false; iHaveBeenRecalculated(); } } return(retVal); }
public override void NodeDeleted(BaseNode node) { // if a node is deleted, we pass it to every node and see if the one that was deleted was our node, if so we delete it. if (node.Equals(inputNode)) { inputNode = null; } }
public override void NodeDeleted(BaseNode node) { if (node.Equals(inputNodes)) { inputNodes = null; AssetDatabase.SaveAssets(); } }
private Field GetSchemaOrNull(BaseInputNode node) { if (node == null || node.Connector == null) { return(null); } return(((OutputNode)node.Connector).State?.Schema); }
//is called when the window is clicked during a transition, if the click happens on top of a input label //it associates the passed node with that input public override void SetInput(BaseInputNode input, Vector2 clickPos) { clickPos.x -= WindowRect.x; clickPos.y -= WindowRect.y; if (_inputNodeRect.Contains(clickPos)) { _inputNode = input; } }
public override void SetInput(BaseInputNode input, Vector2 clickpos) { clickpos.x -= windowRect.x; clickpos.y -= windowRect.y; if (input1Rect.Contains(clickpos)) { input1 = input; } }
//same as before public override void NodeDeleted(BaseNode node) { if (node.Equals(input1)) { input1 = null; } if (node.Equals(input2)) { input2 = null; } }
void OnDisable() { foreach (BaseNode n in nodes) { if (n.GetType() == typeof(BaseInputNode)) { BaseInputNode temp = (BaseInputNode)n; temp.outputIsCalculated = false; } } AssetDatabase.SaveAssets(); }
void OnDestroy() { foreach (BaseNode n in nodes) { if (n.GetType() == typeof(NoiseNode) || n.GetType() == typeof(CalculationNode)) { BaseInputNode temp = (BaseInputNode)n; temp.outputIsCalculated = false; } } AssetDatabase.SaveAssets(); }
public override void NodeDeleted(BaseNode node) { if (node.Equals(_inputOne)) { _inputOne = null; } if (node.Equals(_inputTwo)) { _inputTwo = null; } }
public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; pos.x = windowRect.x; pos.y = windowRect.y; if (inputNodeRect.Contains(pos)) { retVal = inputNode; inputNode = null; } return(retVal); }
//Is called when a click happens in the window public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; //convert the global input position to local space pos.x -= windowRect.x; pos.y -= windowRect.y; //if the click is on top of the input label it returns the associated input if (inputNodeRect.Contains(pos)) { retVal = inputNode; inputNode = null; } return(retVal); }
public override void SetInput(BaseInputNode input, Vector2 clickPos) { clickPos.x -= windowRect.x; clickPos.y -= windowRect.y; for (int i = 0; i < inputNodeRects.Length; i++) { if (inputNodeRects[i].Contains(clickPos)) { inputNodes = input; if (!input.outputNodes.Contains(this)) { input.outputNodes.Add(this); } somethingChanged = true; iHaveBeenRecalculated(); AssetDatabase.SaveAssets(); } } }
public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; pos.x -= windowRect.x; pos.y -= windowRect.y; if (input1Rect.Contains(pos)) { retVal = input1; input1 = null; } else if (input2Rect.Contains(pos)) { retVal = input2; input2 = null; } return(retVal); }
public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; selectedConnection = null; pos.x -= windowRect.x; pos.y -= windowRect.y; for (int i = 0; i < inputNodeRects.Length; i++) { if (inputNodeRects[i].Contains(pos) && inputNodes[i].nodes.Count > 0) { retVal = (BaseInputNode)inputNodes[i].nodes[0]; inputNodes[i].nodes = new List <BaseNode>(); outputIsCalculated = false; iHaveBeenRecalculated(); } } return(retVal); }
public override BaseInputNode ClickedOnInput(Vector2 pos) { BaseInputNode retVal = null; pos.x -= WindowRect.x; pos.y -= WindowRect.y; if (_inputOneRect.Contains(pos)) { retVal = _inputOne; _inputOne = null; } else { if (_inputTwoRect.Contains(pos)) { retVal = _inputTwo; _inputTwo = null; } } return(retVal); }
private void OnGUI() { Event e = Event.current; mousePos = e.mousePosition; if (e.button == 1 && !makeTransitionMode) { if (e.type == EventType.MouseDown) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (!clickedOnWindow) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Add Input Node"), false, ContextCallback, "inputNode"); menu.AddItem(new GUIContent("Add Output Node"), false, ContextCallback, "outputNode"); menu.AddItem(new GUIContent("Add Calculation Node"), false, ContextCallback, "calcNode"); menu.AddItem(new GUIContent("Add Comparison NOde"), false, ContextCallback, "compNode"); menu.ShowAsContext(); e.Use(); } else { // we still want a menu GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, "makeTransition"); menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode"); menu.ShowAsContext(); e.Use(); } } } else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow && !windows[selectIndex].Equals(selectedNode)) { windows[selectIndex].SetInput((BaseInputNode)selectedNode, mousePos); makeTransitionMode = false; selectedNode = null; } if (!clickedOnWindow) { makeTransitionMode = false; selectedNode = null; } e.Use(); } else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { BaseInputNode nodeToChange = windows[selectIndex].ClickedOnInput(mousePos); if (nodeToChange != null) { selectedNode = nodeToChange; makeTransitionMode = true; } } } if (makeTransitionMode && selectedNode != null) { Rect mouseRect = new Rect(e.mousePosition.x, e.mousePosition.y, 10, 10); DrawNodeCurve(selectedNode.windowRect, mouseRect); Repaint(); } foreach (BaseNode n in windows) { n.DrawCurves(); } BeginWindows(); for (int i = 0; i < windows.Count; i++) { windows[i].windowRect = GUI.Window(i, windows[i].windowRect, DrawNodeWindow, windows[i].windowTitle); } EndWindows(); }
void CreateInstructionBuffer() { instructionBuffer = new List <float>(); for (int i = 0; i < PriorityQueue.Count; i++) { BaseInputNode node = PriorityQueue[i]; if (node.priority == 0) { instructionBuffer.Add(-1f); instructionBuffer.Add(i); } else if (node.HasInputs()) { if (node.GetType() == typeof(NoiseNode)) { NoiseNode noiseNode = (NoiseNode)node; instructionBuffer.Add(-3); instructionBuffer.Add(i); for (int j = 0; j < noiseNode.inputNodes.Count; j++) { foreach (BaseInputNode node1 in noiseNode.inputNodes[j].nodes) { instructionBuffer.Add(PriorityQueue.IndexOf(node1) + j / 100); } } instructionBuffer.Add(i); } if (node.GetType() == typeof(CalculationNode)) { CalculationNode calcNode = (CalculationNode)node; switch (calcNode.calcType) { case CalcType.Adition: instructionBuffer.Add(-2.1f); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[0])); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[1])); break; case CalcType.Subtraction: instructionBuffer.Add(-2.2f); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[0])); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[1])); break; case CalcType.Division: instructionBuffer.Add(-2.3f); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[0])); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[1])); break; case CalcType.Multiplication: instructionBuffer.Add(-2.4f); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[0])); instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[1])); break; case CalcType.SingleNumber: instructionBuffer.Add(-2.5f); break; case CalcType.Clamp: instructionBuffer.Add(-2.6f); if (calcNode.inputNodes[0] != null) { instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[0])); } else if (calcNode.inputNodes[1] != null) { instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[1])); } instructionBuffer.Add(calcNode.clampValues.x); instructionBuffer.Add(calcNode.clampValues.y); break; case CalcType.ReScale: instructionBuffer.Add(-2.7f); if (calcNode.inputNodes[0] != null) { instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[0])); } else if (calcNode.inputNodes[1] != null) { instructionBuffer.Add(PriorityQueue.IndexOf(calcNode.inputNodes[1])); } instructionBuffer.Add(calcNode.numberScale.x); instructionBuffer.Add(calcNode.numberScale.y); break; } } } } }
void OnGUI() { //check event Event e = Event.current; //check mouse position mousePos = e.mousePosition; if (e.button == 1 && !makeTransitionMode) { if (e.type == EventType.MouseDown) { bool clickedOnWindow = false; int selectedIndex = -1; //check to see if he clicked inside a window for (int i = 0; i < windows.Count; i++) { if (windows[i].WindowRect.Contains(mousePos)) { //if he clicked store the i selectedIndex = i; //we clicked on a window clickedOnWindow = true; //we have a window so we don't need to check for another one break; } } //if we didn't clicked a window if (!clickedOnWindow) { //make a new menu for every different case GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Utility/Add Input Node"), false, ContextCallback, "inputNode"); menu.AddItem(new GUIContent("Utility/Add Output Node"), false, ContextCallback, "outputNode"); menu.AddItem(new GUIContent("Math/Add Calculation Node"), false, ContextCallback, "calcNode"); menu.AddItem(new GUIContent("Math/Add Comparison Node"), false, ContextCallback, "compNode"); //menu.AddItem(new GUIContent("Math/Add Number Node"), false, ContextCallback, "numNode"); menu.AddSeparator(""); menu.AddItem(new GUIContent("GameObject/Add GameObject Node"), false, ContextCallback, "goObj"); menu.AddItem(new GUIContent("GameObject/Add GameObject Active Node"), false, ContextCallback, "goActive"); menu.AddItem(new GUIContent("GameObject/Add GameObject Distance Node"), false, ContextCallback, "goDistance"); menu.AddItem(new GUIContent("Utility/Add Timer Node"), false, ContextCallback, "timerNode"); menu.AddItem(new GUIContent("Utility/Add Bool Node"), false, ContextCallback, "boolNode"); menu.AddSeparator(""); menu.AddItem(new GUIContent("Clear All Nodes"), false, ContextCallback, "clearAll"); menu.AddItem(new GUIContent("Reset"), false, ContextCallback, "reset"); menu.ShowAsContext(); e.Use(); } else { //if it clicked on a window add items to make transition or delete node GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, "makeTransition"); menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode"); //we use it so that it will show menu.ShowAsContext(); //consumes the event e.Use(); } } } //if we are in a transition mode and there is a left click else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode) { bool clickedOnWindow = false; int selectedIndex = -1; //find which window was clicked for (int i = 0; i < windows.Count; i++) { if (windows[i].WindowRect.Contains(mousePos)) { selectedIndex = i; clickedOnWindow = true; break; } } //if there is a click on a window and it's not the window that the transition started from if (clickedOnWindow && !windows[selectedIndex].Equals(selectedNode)) { //call the set Input on the selected window in order to evaluate if the selected node will be used as input windows[selectedIndex].SetInput((BaseInputNode)selectedNode, mousePos); makeTransitionMode = false; selectedNode = null; } //if we didn't clicked on a window if (!clickedOnWindow) { //then stop the transition makeTransitionMode = false; selectedNode = null; } e.Use(); } //if there is a left click and we are not in a transition mode else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode) { bool clickedOnWindow = false; int selectedIndex = -1; //same as above for (int i = 0; i < windows.Count; i++) { if (windows[i].WindowRect.Contains(mousePos)) { selectedIndex = i; clickedOnWindow = true; break; } } //if we clicked on a window if (clickedOnWindow) { //evaluate if an input of the node was clicked BaseInputNode nodeToChange = windows[selectedIndex].ClickedOnInput(mousePos); //if node to change is not null means that an input was clicked if (nodeToChange != null) { //so set the node to the transition mode selectedNode = nodeToChange; makeTransitionMode = true; } } } //if we are in a transition mode and there is a selected node if (makeTransitionMode && selectedNode != null) { //draw the curve from the selected node to the mouse position Rect mouseRect = new Rect(e.mousePosition.x, e.mousePosition.y, 10, 10); DrawNodeCurve(selectedNode.WindowRect, mouseRect); Repaint(); } GUI.BeginGroup(new Rect(PanX, PanY, 100000, 100000)); //draw each curve for every node foreach (BaseNode n in windows) { n.DrawCurves(); } //draw the actual windows BeginWindows(); for (int i = 0; i < windows.Count; i++) { windows[i].WindowRect = GUI.Window(i , new Rect(windows[i].WindowRect.x + PanX, windows[i].WindowRect.y + PanY, windows[i].WindowRect.size.x, windows[i].WindowRect.size.y) , DrawNodeWindow , windows[i].WindowTitle); } EndWindows(); GUI.EndGroup(); // Middle mouse scrolling that doesn't work //if(e.keyCode == KeyCode.A && e.type == EventType.KeyDown) { // if(scrollWindow == true) { scrollWindow = false; } else { // scrollStartMousePos = e.mousePosition; // scrollWindow = true; // } //} //if(e.button == 2) { // if(e.type == EventType.MouseDown) { // scrollStartMousePos = e.mousePosition; // scrollWindow = true; // } else if(e.type == EventType.MouseUp) { scrollWindow = false; } //} //if(scrollWindow) { // mouseDiff = e.mousePosition - scrollStartMousePos; // PanX += mouseDiff.x / 100; // PanY += mouseDiff.y / 100; //} bool topButton = GUI.RepeatButton(new Rect(position.width / 2 - (position.width / 10) / 2, 5, position.width / 10, 20), "^"); bool leftButton = GUI.RepeatButton(new Rect(5, position.height / 2 - (position.height / 10) / 2, 20, position.height / 10), "<"); bool rightButton = GUI.RepeatButton(new Rect(position.width - 25, position.height / 2 - (position.height / 10) / 2, 20, position.height / 10), ">"); bool bottomButton = GUI.RepeatButton(new Rect(position.width / 2 - (position.width / 10) / 2, position.height - 25, position.width / 10, 20), "v"); if (topButton) { PanY -= PANSPEED; Repaint(); } else if (leftButton) { PanX -= PANSPEED; Repaint(); } else if (rightButton) { PanX += PANSPEED; Repaint(); } else if (bottomButton) { PanY += PANSPEED; Repaint(); } else { PanX = PanY = 0; } if ((Event.current.rawType == EventType.MouseUp) && (GUIUtility.hotControl != _mainwindowID)) { GUIUtility.hotControl = 0; } }
public virtual void SetInput(BaseInputNode input, Vector2 clickPos) { }
//Chequea los clics del mouse void MouseActions() { Event e = Event.current; mousePos = e.mousePosition; if (e.button == 1 && !makeTransitionMode) { if (e.type == EventType.MouseDown) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (!clickedOnWindow) { ContextMenu(); e.Use(); } else { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Make Transition"), false, ContextCallBack, "makeTransition"); menu.AddSeparator(""); if (!windows[0].windowRect.Contains(mousePos)) { menu.AddItem(new GUIContent("Delete Node"), false, ContextCallBack, "deleteNode"); } menu.ShowAsContext(); e.Use(); } } } else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow && !windows[selectIndex].Equals(selectedNode)) { windows[selectIndex].SetInput((BaseInputNode)selectedNode, mousePos); makeTransitionMode = false; selectedNode = null; } if (!clickedOnWindow) { makeTransitionMode = false; selectedNode = null; } e.Use(); } else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode) { bool clickedOnWindow = false; int selectIndex = -1; for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectIndex = i; clickedOnWindow = true; break; } } if (clickedOnWindow) { BaseInputNode nodeToChange = windows[selectIndex].ClickedOnInput(mousePos); if (nodeToChange != null) { selectedNode = nodeToChange; makeTransitionMode = true; } } } if (makeTransitionMode && selectedNode != null) { Rect mouseRect = new Rect(e.mousePosition.x, e.mousePosition.y, 10, 10); DrawNodeCurve(selectedNode.windowRect, mouseRect, Color.black); Repaint(); } }
void OnGUI() { //scrollPos = EditorGUILayout.BeginScrollView(scrollPos,true, true); if (editor == null) { editor = EditorWindow.GetWindow <NodeEditor>(); } Event e = Event.current; mousePos = e.mousePosition; if (e.button == 1 && !makeTransitionMode) { if (e.type == EventType.MouseDown) { bool clickedOnWindow = false; BaseNode tempSelectedNode = null; foreach (BaseNode node in nodes) { if (node.windowRect.Contains(mousePos)) { tempSelectedNode = node; clickedOnWindow = true; break; } } if (!clickedOnWindow) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Add Noise Node"), false, ContextCallback, "noiseNode"); menu.AddItem(new GUIContent("Add Output Node"), false, ContextCallback, "outputNode"); menu.AddItem(new GUIContent("Add Calculation Node"), false, ContextCallback, "calculationNode"); menu.AddItem(new GUIContent("Add Wave Node"), false, ContextCallback, "waveNode"); menu.ShowAsContext(); e.Use(); } else { GenericMenu menu = new GenericMenu(); if (tempSelectedNode.GetType() != typeof(OutputNode)) { menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, "makeTransition"); } if (tempSelectedNode.GetType() == typeof(NoiseNode)) { menu.AddItem(new GUIContent("Call Method"), false, ContextCallback, "callMethod"); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode"); menu.ShowAsContext(); e.Use(); } } } else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode) { bool clickedOnWindow = false; BaseNode tempSelectedNode = null; foreach (BaseNode node in nodes) { if (node.windowRect.Contains(mousePos)) { tempSelectedNode = node; clickedOnWindow = true; break; } } if (clickedOnWindow && !tempSelectedNode.Equals(selectedNode)) { tempSelectedNode.SetInput((BaseInputNode)selectedNode, mousePos); makeTransitionMode = false; selectedNode = null; } if (!clickedOnWindow) { makeTransitionMode = false; selectedNode = null; } } else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode) { bool clickedOnWindow = false; BaseNode tempSelectedNode = null; foreach (BaseNode node in nodes) { if (node.windowRect.Contains(mousePos)) { tempSelectedNode = node; clickedOnWindow = true; break; } } if (clickedOnWindow) { BaseInputNode nodeToChange = tempSelectedNode.ClickedOnInput(mousePos); if (nodeToChange != null) { makeTransitionMode = true; selectedNode = nodeToChange; } } } if (makeTransitionMode && selectedNode != null) { Rect mouseRect = new Rect(mousePos.x, mousePos.y, 10, 10); DrawNodeCurve(selectedNode.outputRect, mouseRect); Repaint(); } for (int i = nodes.Count - 1; i >= 0; i--) { if (nodes[i] == null) { nodes.Remove(nodes[i]); } } foreach (BaseNode n in nodes) { if (n != null) { n.DrawCurves(); } } scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPos, new Rect(0, 0, 1000, 1000)); BeginWindows(); for (int i = 0; i < nodes.Count; i++) { nodes[i].windowRect = GUILayout.Window(i, nodes[i].windowRect, DrawNodeWindow, nodes[i].windowTitle); nodes[i].id = i; } EndWindows(); GUI.EndScrollView(); }
void OnGUI() { //check event Event e = Event.current; //check mouse position mousePos = e.mousePosition; if (e.button == 1 && !makeTransitionMode) { if (e.type == EventType.MouseDown) { bool clickedOnWindow = false; int selectedIndex = -1; //check to see if he clicked inside a window for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { //if he clicked store the i selectedIndex = i; //we clicked on a window clickedOnWindow = true; //we have a window so we don't need to check for another one break; } } //if we didn't clicked a window if (!clickedOnWindow) { //make a new menu for every different case GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Add Input Node"), false, ContextCallback, "inputNode"); menu.AddItem(new GUIContent("Add Output Node"), false, ContextCallback, "outputNode"); menu.AddItem(new GUIContent("Add Calculation Node"), false, ContextCallback, "calcNode"); menu.AddItem(new GUIContent("Add Comparison Node"), false, ContextCallback, "compNode"); menu.AddSeparator(""); menu.AddItem(new GUIContent("Add GameObject Active Node"), false, ContextCallback, "goActive"); menu.AddItem(new GUIContent("Add GameObject Distance Node"), false, ContextCallback, "goDistance"); menu.AddItem(new GUIContent("Add Timer Node"), false, ContextCallback, "timerNode"); menu.ShowAsContext(); e.Use(); } else { //if it clicked on a window add items to make transition or delete node GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Make Transition"), false, ContextCallback, "makeTransition"); menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode"); //we use it so that it will show menu.ShowAsContext(); //consumes the event e.Use(); } } } //if we are in a transition mode and there is a left click else if (e.button == 0 && e.type == EventType.MouseDown && makeTransitionMode) { bool clickedOnWindow = false; int selectedIndex = -1; //find which window was clicked for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectedIndex = i; clickedOnWindow = true; break; } } //if there is a click on a window and it's not the window that the transition started from if (clickedOnWindow && !windows[selectedIndex].Equals(selectedNode)) { //call the set Input on the selected window in order to evaluate if the selected node will be used as input windows[selectedIndex].SetInput((BaseInputNode)selectedNode, mousePos); makeTransitionMode = false; selectedNode = null; } //if we didn't clicked on a window if (!clickedOnWindow) { //then stop the transition makeTransitionMode = false; selectedNode = null; } e.Use(); } //if there is a left click and we are not in a transition mode else if (e.button == 0 && e.type == EventType.MouseDown && !makeTransitionMode) { bool clickedOnWindow = false; int selectedIndex = -1; //same as above for (int i = 0; i < windows.Count; i++) { if (windows[i].windowRect.Contains(mousePos)) { selectedIndex = i; clickedOnWindow = true; break; } } //if we clicked on a window if (clickedOnWindow) { //evaluate if an input of the node was clicked BaseInputNode nodeToChange = windows[selectedIndex].ClickedOnInput(mousePos); //if node to change is not null means that an input was clicked if (nodeToChange != null) { //so set the node to the transition mode selectedNode = nodeToChange; makeTransitionMode = true; } } } //if we are in a transition mode and there is a selected node if (makeTransitionMode && selectedNode != null) { //draw the curve from the selected node to the mouse position Rect mouseRect = new Rect(e.mousePosition.x, e.mousePosition.y, 10, 10); DrawNodeCurve(selectedNode.windowRect, mouseRect); Repaint(); } GUI.BeginGroup(new Rect(PanX, PanY, 100000, 100000)); //draw each curve for every node foreach (BaseNode n in windows) { n.DrawCurves(); } //draw the actual windows BeginWindows(); for (int i = 0; i < windows.Count; i++) { windows[i].windowRect = GUI.Window(i, windows[i].windowRect, DrawNodeWindow, windows[i].windowTitle); } EndWindows(); GUI.EndGroup(); if (e.keyCode == KeyCode.A && e.type == EventType.KeyDown) { if (scrollWindow == true) { scrollWindow = false; } else { scrollStartMousePos = e.mousePosition; scrollWindow = true; } } if (e.button == 2) { if (e.type == EventType.MouseDown) { scrollStartMousePos = e.mousePosition; scrollWindow = true; } else if (e.type == EventType.MouseUp) { scrollWindow = false; } } if (scrollWindow) { Vector2 mouseDiff = e.mousePosition - scrollStartMousePos; PanX += mouseDiff.x / 100; PanY += mouseDiff.y / 100; } }