Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        foreach (Socket socket in sockets)
        {
            ClearLine(socket.transform.gameObject);
        }

        if (tapASocket && tapBSocket)
        {
            Socket          connA = getConnectedTo(tapASocket);
            Socket          connB = getConnectedTo(tapBSocket);
            Socket.LEDColor color = Socket.LEDColor.Off;
            if (connA != null)
            {
                color = connA.liveColor;
            }
            else if (connB != null)
            {
                color = connB.liveColor;
            }
            tapBoxAnimator.SetBool("PortChange", color == Socket.LEDColor.Green);
            tapASocket.setLED(color);
            tapBSocket.setLED(color);
        }

        if (isHoldingAPlug())
        {
            // Draw line between mouse and plugged socket
            Vector3 from_o = from.transform.position;
            Vector3 to_o   = mousePlugInstance.GetComponent <Plug> ().getWirePos();
            LineTo(from_o, to_o, from.GetComponent <LineRenderer> ());

            if (Input.GetMouseButtonDown(0))
            {
                var mousePos = Input.mousePosition;
                //Create the PointerEventData with null for the EventSystem
                PointerEventData ped = new PointerEventData(null);
                //Set required parameters, in this case, mouse position
                ped.position = Input.mousePosition;
                //Create list to receive all results
                List <RaycastResult> results = new List <RaycastResult> ();
                //Raycast it
                gr.Raycast(ped, results);
                if (results.Count == 0)
                {
                    //	Debug.Log ("YOU MISSED");
                    from.RemovePlug();
                    ClearLine(from.transform.gameObject);
                    from = null;
                    GameObject.DestroyImmediate(mousePlugInstance);
                    cursor.GetComponent <Image> ().enabled = true;
                }
                else
                {
                    //	Debug.Log ("You didn't miss");
                }
            }
        }

        foreach (Tuple <Socket, Socket> connection in connections)
        {
            var first  = connection.First.transform.position;
            var second = connection.Second.transform.position;
            LineTo(first, second, connection.First.GetComponent <LineRenderer> ());
        }
    }
Esempio n. 2
0
    public void setLED(string socket, Socket.LEDColor color)
    {
        Socket s = getSocket(socket);

        s.setLED(color);
    }