public void RemoveConnection() { if (connection == null) { return; } NodeEditorCallbacks.IssueOnRemoveConnection(this); connection.connections.Remove(this); connection = null; NodeEditor.RecalculateFrom(body); }
public void ClearCalculation() { if (BeginRecursiveSearchLoop()) { return; } calculated = false; for (int outCnt = 0; outCnt < Outputs.Count; outCnt++) { NodeOutput output = Outputs[outCnt]; for (int conCnt = 0; conCnt < output.connections.Count; conCnt++) { output.connections[conCnt].body.ClearCalculation(); } } EndRecursiveSearchLoop(); }
public bool CanApplyConnection(NodeOutput output) { if (output == null || body == output.body || connection == output || !typeData.Type.IsAssignableFrom(output.typeData.Type)) { return(false); } if (output.body.isChildOf(body)) { if (!output.body.allowsLoopRecursion(body)) { Debug.LogWarning("Cannot apply connection: Recursion detected!"); return(false); } } return(true); }
internal bool isInLoop() { if (BeginRecursiveSearchLoop()) { return(this == startRecursiveSearchNode); } for (int cnt = 0; cnt < Inputs.Count; cnt++) { NodeOutput connection = Inputs[cnt].connection; if (connection != null && connection.body.isInLoop()) { StopRecursiveSearchLoop(); return(true); } } EndRecursiveSearchLoop(); return(false); }
protected static void ReassignOutputType(ref NodeOutput output, Type newOutputType) { Node body = output.body; string outputName = output.name; // Store all valid connections that are not affected by the type change IEnumerable <NodeInput> validConnections = output.connections.Where((NodeInput connection) => connection.typeData.Type.IsAssignableFrom(newOutputType)); // Delete the output of the old type output.Delete(); // Create Output with new type NodeEditorCallbacks.IssueOnAddNodeKnob(NodeOutput.Create(body, outputName, newOutputType.AssemblyQualifiedName)); output = body.Outputs[body.Outputs.Count - 1]; // Restore the valid connections foreach (NodeInput input in validConnections) { input.ApplyConnection(output); } }
private static bool ContinueCalculation(Node node) { if (node.calculated) { return(false); } if ((node.descendantsCalculated() || node.isInLoop()) && node.Calculate()) { node.calculated = true; calculationCount++; workList.Remove(node); if (node.ContinueCalculation && calculationCount < 1000) { for (int outCnt = 0; outCnt < node.Outputs.Count; outCnt++) { NodeOutput output = node.Outputs[outCnt]; if (!output.calculationBlockade) { for (int conCnt = 0; conCnt < output.connections.Count; conCnt++) { ContinueCalculation(output.connections[conCnt].body); } } } } else if (calculationCount >= 1000) { Debug.LogError("Stopped calculation, to many node ! max 1000!"); } return(true); } else if (!workList.Contains(node)) { workList.Add(node); } return(false); }
protected static void ReassignInputType(ref NodeInput input, Type newInputType) { Node body = input.body; string inputName = input.name; // Store the valid connection if it's not affected by the type change NodeOutput validConnection = null; if (input.connection != null && newInputType.IsAssignableFrom(input.connection.typeData.Type)) { validConnection = input.connection; } // Delete the input of the old type input.Delete(); // Create Output with new type NodeEditorCallbacks.IssueOnAddNodeKnob(NodeInput.Create(body, inputName, newInputType.AssemblyQualifiedName)); input = body.Inputs[body.Inputs.Count - 1]; // Restore the valid connections if (validConnection != null) { input.ApplyConnection(validConnection); } }
protected internal virtual void DrawConnections() { CheckNodeKnobMigration(); if (Event.current.type != EventType.Repaint) { return; } for (int outCnt = 0; outCnt < Outputs.Count; outCnt++) { NodeOutput output = Outputs[outCnt]; Vector2 startPos = output.GetGUIKnob().center; Vector2 startDir = output.GetDirection(); for (int conCnt = 0; conCnt < output.connections.Count; conCnt++) { NodeInput input = output.connections[conCnt]; NodeEditorGUI.DrawConnection(startPos, startDir, input.GetGUIKnob().center, input.GetDirection(), output.typeData.Color); } } }
public void Validate() { if (nodes == null) { nodes = new List <Node>(); } for (int nodeCnt = 0; nodeCnt < nodes.Count; nodeCnt++) { Node node = nodes[nodeCnt]; if (node == null) { nodes.RemoveAt(nodeCnt); nodeCnt--; continue; } for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++) { NodeKnob nodeKnob = node.nodeKnobs[knobCnt]; if (nodeKnob == null) { node.nodeKnobs.RemoveAt(knobCnt); knobCnt--; continue; } if (nodeKnob is NodeInput) { NodeInput input = nodeKnob as NodeInput; if (input.connection != null && input.connection.body == null) { input.connection = null; } } else if (nodeKnob is NodeOutput) { NodeOutput output = nodeKnob as NodeOutput; for (int conCnt = 0; conCnt < output.connections.Count; conCnt++) { NodeInput con = output.connections[conCnt]; if (con == null || con.body == null) { output.connections.RemoveAt(conCnt); conCnt--; } } } } } if (editorStates == null) { editorStates = new NodeEditorState[0]; } editorStates = editorStates.Where((NodeEditorState state) => state != null).ToArray(); foreach (NodeEditorState state in editorStates) { if (!nodes.Contains(state.selectedNode)) { state.selectedNode = null; } } }
public NodeOutput CreateOutput(string outputName, string outputType, NodeSide nodeSide, float sidePosition) { return(NodeOutput.Create(this, outputName, outputType, nodeSide, sidePosition)); }
public NodeOutput CreateOutput(string outputName, string outputType, NodeSide nodeSide) { return(NodeOutput.Create(this, outputName, outputType, nodeSide)); }
protected internal virtual void OnAddOutputConnection(NodeOutput output) { }
private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState) { if (!editorState.drawing) { return; } NodeCanvas prevNodeCanvas = curNodeCanvas; NodeEditorState prevEditorState = curEditorState; curNodeCanvas = nodeCanvas; curEditorState = editorState; if (Event.current.type == EventType.Repaint) { float width = curEditorState.zoom / NodeEditorGUI.Background.width; float height = curEditorState.zoom / NodeEditorGUI.Background.height; Vector2 offset = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom; Rect uvDrawRect = new Rect(-offset.x * width, (offset.y - curEditorState.canvasRect.height) * height, curEditorState.canvasRect.width * width, curEditorState.canvasRect.height * height); GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, uvDrawRect); } NodeEditorInputSystem.HandleInputEvents(curEditorState); if (Event.current.type != EventType.Layout) { curEditorState.ignoreInput = new List <Rect>(); } Rect canvasRect = curEditorState.canvasRect; curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, false); if (curEditorState.navigate) { Vector2 startPos = (curEditorState.selectedNode != null ? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust; Vector2 endPos = Event.current.mousePosition; RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3); RepaintClients(); } if (curEditorState.connectOutput != null) { NodeOutput output = curEditorState.connectOutput; Vector2 startPos = output.GetGUIKnob().center; Vector2 startDir = output.GetDirection(); Vector2 endPos = Event.current.mousePosition; Vector2 endDir = NodeEditorGUI.GetSecondConnectionVector(startPos, endPos, startDir); NodeEditorGUI.DrawConnection(startPos, startDir, endPos, endDir, output.typeData.Color); RepaintClients(); } if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null) { curNodeCanvas.nodes.Remove(curEditorState.selectedNode); curNodeCanvas.nodes.Add(curEditorState.selectedNode); } for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++) { curNodeCanvas.nodes[nodeCnt].DrawConnections(); } for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++) { Node node = curNodeCanvas.nodes[nodeCnt]; node.DrawNode(); if (Event.current.type == EventType.Repaint) { node.DrawKnobs(); } } GUIScaleUtility.EndScale(); GUI.DrawTexture(new Rect(12, 12, NodeEditorGUI.GuiShadero.width / 2, NodeEditorGUI.GuiShadero.height / 2), NodeEditorGUI.GuiShadero); GUIStyle g = new GUIStyle(); g.fontSize = 26; g.normal.textColor = Color.white; if (Node.ShaderNameX == "") { Node.ShaderNameX = "Default"; } g = new GUIStyle(); g.fontSize = 22; if (FlagIsLoadedMaterial) { FlagIsLoadedMaterial = false; } if (FlagIsSavedMaterial) { FlagIsSavedMaterial = false; } g = new GUIStyle(); g.fontSize = 18; g.normal.textColor = Color.white; Texture2D preview = ResourceManager.LoadTexture("Textures/previews/shadero_firstscreen.jpg"); g = new GUIStyle(); g.fontSize = 18; g.fontStyle = FontStyle.Italic; Color yellow = new Color(0, 1, 1, UpdatePreview); UpdatePreview -= Time.deltaTime * 0.2f; if (UpdatePreview < 0) { UpdatePreview = 0; } g.normal.textColor = yellow; Rect position = _ShaderoShaderEditorFramework.Standard.NodeEditorWindow.editor.position; GUI.Label(new Rect(position.width - 320, position.height - 50, 150, 50), "*Updated*", g); Node.ShaderNameX = NodeEditor.curEditorState.ShaderName; if (curNodeCanvas.nodes.Count == 0) { preview = ResourceManager.LoadTexture("Textures/previews/shadero_firstscreen.jpg"); Vector2 scr = new Vector2(position.width / 2 - 120, position.height / 2); Vector2 size = new Vector2(1365 / 2, 781 / 2); GUI.DrawTexture(new Rect(scr.x - size.x / 2, scr.y - size.y / 2, size.x, size.y), preview); } NodeEditorInputSystem.HandleLateInputEvents(curEditorState); curNodeCanvas = prevNodeCanvas; curEditorState = prevEditorState; }
protected internal override void CopyScriptableObjects(System.Func <ScriptableObject, ScriptableObject> replaceSerializableObject) { connection = replaceSerializableObject.Invoke(connection) as NodeOutput; }
public T GetValue <T>() { return(connection != null?connection.GetValue <T>() : NodeOutput.GetDefault <T>()); }