//public void OnDroppedSubstance(ProceduralMaterial procMat){ // Texture diffuse = TryGetProceduralTexture(procMat, "_MainTex"); // Texture normal = TryGetProceduralTexture(procMat, "_BumpMap"); // //Texture parallax = TryGetProceduralTexture(procMat, "_ParallaxMap"); // //Texture emission = TryGetProceduralTexture(procMat, "_Illum"); // //TryGetProceduralTexture("_MainTex"); // SF_Node prevNode = TryLinkIfExistsAndOpenSlotAvailable(diffuse, "MainTex", editor.mainNode.diffuse, "RGB"); // TryLinkIfExistsAndOpenSlotAvailable(normal, "BumpMap", editor.mainNode.normal, "RGB", prevNode); //} // For connecting procedural materials to the main node public SF_Node TryLinkIfExistsAndOpenSlotAvailable(Texture tex, string propertyName, SF_NodeConnector connector, string outChannel, SF_Node prevNode = null) { if (tex) { SFN_Tex2d tNode = editor.AddNode <SFN_Tex2d>(); if (prevNode != null) { Rect r = tNode.rect; r = r.MovedDown(1); r.y += 64; tNode.rect = r; } tNode.TextureAsset = tex; tNode.property.SetName(propertyName); tNode.OnAssignedTexture(); if (connector.enableState == EnableState.Enabled && connector.availableState == AvailableState.Available && !connector.IsConnected()) { connector.LinkTo(tNode[outChannel]); } return(tNode); } return(null); }
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(); }