Example #1
0
        private void Connect(PortModel p)
        {
            //test if the port that you are connecting too is not the start port or the end port
            //of the current connector
            if (p.Equals(Start) || p.Equals(End))
            {
                return;
            }

            //if the selected connector is also an output connector, return false
            //output ports can't be connected to eachother
            if (p.PortType == PortType.Output)
            {
                return;
            }

            //test if the port that you are connecting to is an input and
            //already has other connectors
            if (p.PortType == PortType.Input && p.Connectors.Count > 0)
            {
                p.Disconnect(p.Connectors[0]);
            }

            //turn the line solid
            End = p;

            if (End != null)
            {
                p.Connect(this);
            }

            return;
        }
    public void AddConnection(PortModel start, PortModel end)
    {
        var realConnector = new GameObject("Connector");

        if (end.GetType() == typeof(ExecutionPortModel))
        {
            realConnector.AddComponent <ExecutionConnectorModel>();
        }
        else
        {
            realConnector.AddComponent <ConnectorModel>();
        }

        //TODO fix logic so that we reoder the inputs correctly... outputs should go first, then inputs are the end, can just check types
        realConnector.GetComponent <ConnectorModel>().init(start, end);
        end.Connect(realConnector.GetComponent <ConnectorModel>());
        Connectors.Add(realConnector.GetComponent <ConnectorModel>());
    }