void UpdateConnectorVisibility() { SF_NodeConnector z = GetConnectorByID("Z"); SF_NodeConnector w = GetConnectorByID("W"); if (!useAsFloat4) { if (z.IsConnected()) { for (int i = 0; i < z.outputCons.Count; i++) { Undo.RecordObject(z.outputCons[i], "disconnect"); } Undo.RecordObject(z, "disconnect"); z.Disconnect(); } if (w.IsConnected()) { for (int i = 0; i < w.outputCons.Count; i++) { Undo.RecordObject(w.outputCons[i], "disconnect"); } Undo.RecordObject(w, "disconnect"); w.Disconnect(); } } EnableState enableState = useAsFloat4 ? EnableState.Enabled : EnableState.Disabled; z.enableState = enableState; w.enableState = enableState; }
public void StopCutting() { List <SF_NodeConnector> disconnectors = new List <SF_NodeConnector>(); for (int i = 0; i < editor.nodes.Count; i++) { SF_Node n = editor.nodes[i]; for (int j = 0; j < n.connectors.Length; j++) { SF_NodeConnector con = n.connectors[j]; if (con.IsConnected() && con.conType == ConType.cInput) { if (con.conLine.aboutToBeDeleted) { disconnectors.Add(con); } } } } if (disconnectors.Count == 0) { isCutting = false; return; } UnmarkDeleteHighlights(); //Undo.RecordObject((Object)con, "cut" string undoMsg = "cut "; if (disconnectors.Count > 1) { undoMsg += disconnectors.Count + " "; undoMsg += "connections"; } else { undoMsg += "connection: "; undoMsg += disconnectors[0].node.nodeName; undoMsg += "[" + disconnectors[0].label + "]"; undoMsg += " <--- "; undoMsg += "[" + disconnectors[0].inputCon.label + "]"; undoMsg += disconnectors[0].inputCon.node.nodeName; } // = disconnectors.Count > 1 ? "cut "+disconnectors.Count+" connections" : "cut connection " + disconnectors[i].node.name + "[" + foreach (SF_NodeConnector con in disconnectors) { Undo.RecordObject(con, undoMsg); } foreach (SF_NodeConnector con in disconnectors) { con.Disconnect(); } isCutting = false; }
public void DrawTypecastButton(Rect r, SF_NodeConnector con, bool isInput = false) { Rect closeRect = r.ClampWidth(0, (int)r.height); if (isInput) { GUI.color = new Color(1f, 0.7f, 0.7f, 1f); if (GUI.Button(closeRect, "-")) { RemoveConnector(con, undoRecord: true); return; } GUI.color = Color.white; r.xMin += closeRect.width; Rect dropdownRect = r; dropdownRect.xMax -= 50; r.xMin += dropdownRect.width; int cvtccBef = SF_Tools.ComponentCountOf(con.CustomValueType); //con.CustomValueType = (CustomValueType)EditorGUI.EnumPopup(dropdownRect, con.CustomValueType); con.CustomValueType = (CustomValueType)UndoableEnumPopup(dropdownRect, con.CustomValueType, "set input " + con.label + " value type"); if (cvtccBef != SF_Tools.ComponentCountOf(con.CustomValueType)) { con.Disconnect(); } string before = con.label; con.label = EditorGUI.TextField(r, con.label); if (con.label != before && con.label.Length > 0) { con.label = SF_ShaderProperty.FormatInternalName(con.label); UpdateExtraInputWidth(); OnUpdateNode(NodeUpdateType.Soft); } } else { int cvtccBef = SF_Tools.ComponentCountOf(con.CustomValueType); //con.CustomValueType = (CustomValueType)EditorGUI.EnumPopup(r, con.CustomValueType); con.CustomValueType = (CustomValueType)UndoableEnumPopup(r, con.CustomValueType, "set output value type"); if (cvtccBef != SF_Tools.ComponentCountOf(con.CustomValueType)) { con.Disconnect(); } } }
public void SetVisChildVisible(bool visible) { if (visControlChild == null) { return; } EnableState targetState = visible ? EnableState.Enabled : EnableState.Hidden; if (visControlChild.enableState == targetState) { return; // Don't do anything if unchanged } if (!visible) { visControlChild.Disconnect(true, false); // Disconnect if it goes invisible when linked } visControlChild.enableState = targetState; }
public void RemoveConnector(SF_NodeConnector con, bool undoRecord) { string undoString = ""; if (undoRecord) { undoString = "remove input from " + functionName; Undo.RecordObject(con, undoString); UndoRecord(undoString); } con.Disconnect(); List <SF_NodeConnector> conList = new List <SF_NodeConnector>(); foreach (SF_NodeConnector c in connectors) { if (c != con) { conList.Add(c); } } if (undoRecord) { Undo.DestroyObjectImmediate(con); } else { DestroyImmediate(con); } connectors = conList.ToArray(); RefreshConnectorStringIDs(); UpdateMinHeight(); OnUpdateNode(NodeUpdateType.Hard, false); }
public void LinkTo(SF_NodeConnector other, LinkingMethod linkMethod = LinkingMethod.Default, bool registerUndo = false) { if (this.conType == other.conType) { Debug.Log("Invalid IO linking: " + other.node.nodeName + " con: " + other.label + " thisnode: " + node.nodeName + " con: " + this.label); return; } if (conType == ConType.cInput) { other.LinkTo(this, linkMethod, registerUndo); // Reverse connection if dragged other way return; } if (this.node.isGhost) { linkMethod = LinkingMethod.NoUpdate; } // Other is the input node // [other] <---- [this] bool registeredUndo = false; // Verify, if default. Not if it's without update if (linkMethod == LinkingMethod.Default) { if (!SFNCG_Arithmetic.CompatibleTypes(other.valueTypeDefault, this.valueType)) { Debug.LogError("Incompatible types: Type A: " + other.valueTypeDefault + " Type B: " + this.valueType); //ThrowLinkError(); //other.ResetValueType(); return; } if (registerUndo && !registeredUndo) { string undoMsg = "connect " + other.node.nodeName + "[" + other.label + "] <-- [" + this.label + "]" + this.node.nodeName; this.node.UndoRecord(undoMsg); other.node.UndoRecord(undoMsg); //Undo.RecordObject(this,undoMsg); //Undo.RecordObject(other,undoMsg); registeredUndo = true; } // In case there's an existing one if (other.IsConnected()) { other.Disconnect(true, false, reconnection: true); } } if (registerUndo && !registeredUndo) { string undoMsg = "connect " + other.node.nodeName + "[" + other.label + "] <-- [" + this.label + "]" + this.node.nodeName; this.node.UndoRecord(undoMsg); other.node.UndoRecord(undoMsg); //Undo.RecordObject(this,undoMsg); //Undo.RecordObject(other,undoMsg); registeredUndo = true; } //Debug.Log("Linking " + other.node.nodeName + "["+other.label+"] <--- ["+ this.label +"]" + this.node.nodeName ); // Connect other.valueType = this.valueType; other.inputCon = this; // TODO: Force types in connector group! //if( linkMethod == LinkingMethod.Default ) { if (other.node.conGroup != null) { other.node.conGroup.Refresh(); } //} this.outputCons.Add(other); other.SetVisChildVisible(true); if (linkMethod == LinkingMethod.Default) { node.RefreshValue(); // OnUpdateNode( NodeUpdateType.Soft, false ); // Update this value other.node.OnUpdateNode(); // Update other, and following } other.conLine.ReconstructShapes(); }
public void DeleteSelected() { if (Selection.Contains(editor.mainNode)) { editor.mainNode.Deselect(registerUndo: false); // Deselect main node if you press delete } int selCount = Selection.Count; // Debug.Log("Delete selected, count = " + selCount); if (selCount == 0) { return; } string undoMsg = ""; if (selCount == 1) { undoMsg = "delete " + Selection[0].nodeName; } else { undoMsg = "delete " + selCount + " nodes"; } //Debug.Log("Selection delete initiated - " + undoMsg ); Undo.RecordObject(editor, undoMsg); Undo.RecordObject(editor.nodeView.treeStatus, undoMsg); foreach (SF_Node node in editor.nodes) { node.UndoRecord(undoMsg); // Undo.RecordObject(node, undoMsg); } Undo.RecordObject(this, undoMsg); // Undo recording is weird :( for (int i = editor.nodes.Count - 1; i >= 0; i--) { SF_Node n = editor.nodes[i]; if (n.selected) { if (n is SFN_Relay) { SF_NodeConnector inCon = n["IN"]; SF_NodeConnector outCon = n["OUT"]; if (inCon.IsConnected() && outCon.IsConnected()) { // Relink all outputs to the incoming connectors for (int ir = outCon.outputCons.Count - 1; ir >= 0; ir--) { outCon.outputCons[ir].LinkTo(inCon.inputCon); } inCon.Disconnect(); } } foreach (SF_NodeConnector con in editor.nodes[i].connectors) { if (con.conType == ConType.cOutput) { con.Disconnect(); } } if (editor.nodeView.treeStatus.propertyList.Contains(editor.nodes[i])) { editor.nodeView.treeStatus.propertyList.Remove(editor.nodes[i]); } editor.nodes[i].Deselect(registerUndo: false); editor.nodes.RemoveAt(i); //editor.nodes[i].Delete(registerUndo:false, undoMsg:undoMsg); } } }