Exemplo n.º 1
0
        public void Establish(SF_Editor editor, LinkingMethod linkMethod = LinkingMethod.NoUpdate)
        {
            SF_Node source = editor.GetNodeByID(sNode);
            SF_Node target = editor.GetNodeByID(tNode);

            // Debug.Log( "Linking " + target.nodeName + " <- " + source.nodeName );

            target.GetConnectorByID(tCon).LinkTo(source.GetConnectorByID(sCon), linkMethod);
        }
Exemplo n.º 2
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();
        }