예제 #1
0
        private void Awake()
        {
            container = GetComponentInParent <Block>();
            container.Bind(this);

            outPin = GetComponentInChildren <Connectable>();
            Debug.Assert(outPin, "No Connectable component");

            inTab = GetComponentInChildren <Receivable>();
            Debug.Assert(inTab, "No Receivable component");

            outPin.CallOnClick   = CallOnClick;
            outPin.CallOnRelease = CallOnRelease;
            outPin.CallOnDrop    = CallOnDrop;

            PinPosition = outPin.transform.position;

            connectionLine = GetComponent <LineRenderer>();

            controlPoints = new Vector3[3];
            pointCount    = CalcPointsForIterations(iterations);
            points        = new Vector3[pointCount];
            buffer        = new Vector3[pointCount];
            connectionLine.positionCount = pointCount;
            if (cableWidth != 0f)
            {
                connectionLine.startWidth = connectionLine.endWidth = cableWidth;
            }
        }
예제 #2
0
        private void CallOnClick(Connectable c)
        {
            Debug.Assert(!(From && to), "Only From or to should be set");

            if (From)
            {
                From.ClearOutgoingConnection();
                From = null;
            }
            else if (to)
            {
                to.From = null;
            }

            ClearLine();
            draggingPin = true;
        }
예제 #3
0
        /// <summary>
        /// We've asked our outgoing connection pin
        /// to notify us when it's dropped. We confirm
        /// it's a Connectable (which should be a given)
        /// then check if it's dropped on a ConnectionReceiver.
        /// If so, clear any existing connection from either
        /// terminal and form a new connection. If it's
        /// dropped outside of a receiver proximity,
        /// clear the outgoing connection if any and
        /// remove connection line.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="r"></param>
        /// <param name="inProximity"></param>
        private void CallOnDrop(Placeable p, Receivable r, bool inProximity)
        {
            Connectable conn = p as Connectable;

            if (conn)
            {
                Debug.Log("Dropped connector");

                ConnectionReceiver receiver = r as ConnectionReceiver;

                if (receiver && inProximity)
                {
                    SetConnection(receiver.connection);
                }
                else
                {
                    ClearOutgoingConnection();
                }
            }

            p.ReturnToInitialPosition();
        }
예제 #4
0
 private void CallOnRelease(Connectable c)
 {
     draggingPin = false;
     OnConnectionChanged?.Invoke(this);
 }