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;
        }
Beispiel #2
0
        //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);
        }
Beispiel #3
0
 public bool ValidlyPendingChild()
 {
     return(IsChild() && visControlParent.IsConnected() && CanConnectToPending() && enableState == EnableState.Enabled);
 }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #6
0
        void UpdateOutput()
        {
            // Set proper value types and component count
            UpdateOutCompCount();
            texture.CompCount = outCompCount;
            switch (outCompCount)
            {
            case 1:
                connectors[0].valueType = ValueType.VTv1;
                break;

            case 2:
                connectors[0].valueType = ValueType.VTv2;
                break;

            case 3:
                connectors[0].valueType = ValueType.VTv3;
                break;

            case 4:
                connectors[0].valueType = ValueType.VTv4;
                break;

            default:
                connectors[0].valueType = ValueType.VTvPending;
                texture.CompCount       = 4;
                break;
            }



            // Rename the label

            string label = "";

            if (connectors[0].valueType == ValueType.VTvPending)
            {
                label = "-";
            }
            else
            {
                for (int i = 0; i < outCompCount; i++)                    // Build component string
                {
                    int id = (int)components[i];
                    label += compLabels[3][id + 1];
                }
            }
            connectors[0].label = label;

            connectors[0].color = outCompCount == 1 ? outputChanColors[Mathf.Clamp((int)components[0], 0, 3)] : SF_NodeConnector.colorEnabledDefault;


            SF_NodeConnector inCon = GetConnectorByStringID("IN");

            if (inCon.IsConnected())
            {
                for (int i = 0; i < 4; i++)
                {
                    if (i < outCompCount && outCompCount > 1)
                    {
                        connectors[i + 2].enableState = EnableState.Enabled;
                    }
                    else
                    {
                        connectors[i + 2].enableState = EnableState.Hidden;
                        connectors[i + 2].Disconnect();
                    }


                    int id = (int)components[i];
                    connectors[i + 2].label = compLabels[3][id + 1];

                    connectors[i + 2].color = outputChanColors[Mathf.Clamp(id, 0, 3)];
                }
            }
        }