示例#1
0
    public static HandDetails deserialize(byte[] b)
    {
        Debug.Log("datasv");
        BinaryFormatter formatter = new BinaryFormatter();
        HandDetails     cd        = (HandDetails)formatter.Deserialize(new MemoryStream(b));

        return(cd);
    }
 public void sendHandDetails(string hostname, HandDetails details)
 {
     if (hostname != null)
     {
         Debug.Log(remoteep);
         remoteep = new IPEndPoint(IPAddress.Parse(hostname), port);
         Debug.Log(remoteep);
     }
     byte[] data = details.serialize();
     Debug.Log(hostname);
     udpClient.Send(data, data.Length, remoteep);
 }
    }        // Wait for a message toarrive. Set thatas last messagereceived.

    private void udpReceive(IAsyncResult res)
    {
        IPEndPoint from = new IPEndPoint(0, 0);

        byte[]      buffer  = udpClient.Receive(ref from);
        HandDetails details = HandDetails.deserialize(buffer);

        lastHand     = details;
        controlValid = true;
        Debug.Log("datagramnul");
        udpClient.BeginReceive(new AsyncCallback(udpReceive), null);
    }
示例#4
0
    void Update()// decay hiss so it stops if no button is pressed.
    {
        Debug.Log("gug");
        if (hiss != null)
        {
            hiss.volume *= 0.9f;
        }
        HandDetails cd = dc.receiveHandDetails();

        if (cd != null)
        {
            hand.SetLeapHand(cd.hand);
            hand.UpdateHand();
            Debug.Log("werwr");
            laserBeam.SetActive(beamActive);
            if (beamActive)
            {
                Debug.Log("activeandgesture");
                Finger  f          = hand.GetLeapHand().Fingers[(int)Finger.FingerType.TYPE_INDEX];// index finger.
                Bone    b          = f.Bone(Bone.BoneType.TYPE_DISTAL);
                Vector3 bCenter    = new Vector3(b.Center.x, b.Center.y, b.Center.z);
                Vector3 bDirection = new Vector3(b.Direction.x, b.Direction.y, b.Direction.z);
                laserBeam.transform.position = bCenter;
                laserBeam.transform.forward  = bDirection;       // Raycast, inflate, explode.
                RaycastHit hit;
                if ((Physics.Raycast(bCenter, bDirection, out hit, Mathf.Infinity)) && (hit.collider.gameObject.tag == "Inflatable"))
                {        // Inflate the objectby manipulating scale
                    hit.collider.gameObject.transform.localScale *= 1.0f + (inflationRate * Time.deltaTime);
                    // Play the inflation sound.
                    if (hiss != null)
                    {
                        hiss.volume = 1.0f; if (!hiss.isPlaying)
                        {
                            hiss.Play();
                        }
                    }
                    // Pop the object if it gets too big.
                    if (hit.collider.gameObject.transform.localScale.magnitude > 1.5)
                    {
                        Destroy(hit.collider.gameObject);
                        if (pop != null)
                        {
                            pop.Play();
                        }
                    }
                }
            }
        }
    }