Beispiel #1
0
    void Awake()
    {
        instance = this;

        try
        {
            NetworkTransport.Init();

            clientConfig    = new ConnectionConfig();
            clientChannelId = clientConfig.AddChannel(QosType.StateUpdate);              // QosType.UnreliableFragmented

            // add client host
            clientTopology = new HostTopology(clientConfig, 1);
            clientHostId   = NetworkTransport.AddHost(clientTopology, clientPort);

            if (clientHostId < 0)
            {
                throw new UnityException("AddHost failed for client port " + clientPort);
            }

            if (broadcastPort > 0)
            {
                // add broadcast host
                bcastHostId = NetworkTransport.AddHost(clientTopology, broadcastPort);

                if (bcastHostId < 0)
                {
                    throw new UnityException("AddHost failed for broadcast port " + broadcastPort);
                }

                // start broadcast discovery
                byte error = 0;
                NetworkTransport.SetBroadcastCredentials(bcastHostId, 8888, 1, 0, out error);
            }

            // construct keep-alive data
            keepAliveData[0] = "ka,kb,km,kh";              // index 0
            sendKeepAlive[0] = true;

//			faceManager = GetComponent<FacetrackingManager>();
//			if(faceManager != null && faceManager.isActiveAndEnabled)
//			{
//				keepAliveData[1] = "ka,fp,";  // index 1
//				sendKeepAlive[1] = true;
//
//				if(faceManager.getFaceModelData)
//				{
//					keepAliveData[2] = "ka,fv,";  // index 2
//					sendKeepAlive[2] = true;
//
//					if(faceManager.texturedModelMesh == FacetrackingManager.TextureType.FaceRectangle)
//					{
//						keepAliveData[2] += "fu,";  // request uvs
//					}
//
//					keepAliveData[3] = "ka,ft,";  // index 3
//					sendKeepAlive[3] = true;
//				}
//			}

            keepAliveCount = keepAliveData.Length;
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message + "\n" + ex.StackTrace);

            if (statusText)
            {
                statusText.text = ex.Message;
            }
        }
    }
Beispiel #2
0
    private void HandRaycast()
    {
        // get raycast position and direction
        isLeftHandInteracting  = (intetactionListener && leftWristTrans) ? intetactionListener.IsLeftHandInteracting() : false;
        isRightHandInteracting = (intetactionListener && rightWristTrans) ? intetactionListener.IsRightHandInteracting() : false;
        bool isInteracting = isLeftHandInteracting || isRightHandInteracting;

        isShooting = isLeftHandInteracting ? (makeFistToShoot ? (intetactionListener.GetLeftHandEvent() == InteractionManager.HandEventType.Grip) : !makeFistToShoot) :
                     isRightHandInteracting ? (makeFistToShoot ? (intetactionListener.GetRightHandEvent() == InteractionManager.HandEventType.Grip) : !makeFistToShoot) : false;

        if (raycastSource)
        {
            raycastPos    = raycastSource.position;
            raycastDir    = raycastSource.forward;
            isInteracting = true;              // eye interaction - always true

            if (!makeFistToShoot)
            {
                isShooting = true;
            }
        }
        else if (isInteracting)
        {
            // left or right arm
            raycastPos = isLeftHandInteracting ? leftWristTrans.position : rightWristTrans.position;
            raycastDir = isLeftHandInteracting ? (leftWristTrans.position - leftElbowTrans.position).normalized :
                         (rightWristTrans.position - rightElbowTrans.position).normalized;
        }


//        // Show the debug ray if required
//        if (m_ShowDebugRay)
//        {
//			Debug.DrawRay(raycastPos, raycastDir * m_DebugRayLength, Color.blue, m_DebugRayDuration);
//        }

        if (infoText)
        {
            KinectDataClient dataClient          = KinectDataClient.Instance;
            bool             dataClientConnected = dataClient ? dataClient.IsConnected : false;

            if (dataClientConnected && intetactionListener)
            {
                if (isShooting)
                {
                    if (raycastSource && !makeFistToShoot)
                    {
                        string sMessage = "Eyes shooting";
                        infoText.text = sMessage;
                    }
                    else if (isLeftHandInteracting || isRightHandInteracting)
                    {
                        string sMessage = (isLeftHandInteracting ? "Left" : "Right") + " hand shooting";
                        infoText.text = sMessage;
                    }
                }
                else if (isLeftHandInteracting || isRightHandInteracting)
                {
                    string sMessage = (isLeftHandInteracting ? "Left" : "Right") + (!raycastSource ? " hand pointing" : " hand ready");
                    infoText.text = sMessage;
                }
                else
                {
                    string sMessage = !raycastSource ? "Point at snowflakes with your hand" : "Look at the snowflakes";
                    sMessage     += (makeFistToShoot ? "\nClose your hand to shoot them" : "\nto shoot them");
                    infoText.text = sMessage;
                }
            }
        }

        // Create a ray that points forwards from the camera.
        bool raySuccess = false;

        if (isInteracting)
        {
            Ray ray = new Ray(raycastPos, raycastDir);
            //raySuccess = Physics.Raycast (ray, out raycastHit, m_RayLength, ~m_ExclusionLayers);
            raySuccess = Physics.SphereCast(ray, 0.5f, out raycastHit, m_RayLength, ~m_ExclusionLayers);
        }

        // Do the raycast forweards to see if we hit an interactive item
        if (raySuccess)
        {
            VRInteractiveItem interactible = raycastHit.collider.GetComponent <VRInteractiveItem>();            //attempt to get the VRInteractiveItem on the hit object
            m_CurrentInteractible = interactible;

            // If we hit an interactive item and it's not the same as the last interactive item, then call Over
            if (interactible && interactible != m_LastInteractible)
            {
                interactible.Over();
            }

            // Deactive the last interactive item
            if (interactible != m_LastInteractible)
            {
                DeactiveLastInteractible();

                if (interactible && isShooting)
                {
                    // instantiate the laser beam
                    if (laserPrefab)
                    {
                        laser = Instantiate(laserPrefab) as LineRenderer;
                        laser.transform.parent = transform;

                        Vector3 laserStartPos = isLeftHandInteracting ? leftWristTrans.position : rightWristTrans.position;
                        if (raycastSource && !makeFistToShoot)
                        {
                            laserStartPos = raycastPos;
                        }

                        laser.SetPosition(0, laserStartPos);
                        laser.SetPosition(1, raycastHit.point);
                    }

                    interactible.Click();
                }
            }

            m_LastInteractible = interactible;

            // Something was hit, set at the hit position.
            if (m_Reticle)
            {
                m_Reticle.SetPosition(raycastHit);
            }

            if (OnRaycasthit != null)
            {
                OnRaycasthit(raycastHit);
            }
        }
        else
        {
            // Nothing was hit, deactive the last interactive item.
            DeactiveLastInteractible();
            m_CurrentInteractible = null;

            // Position the reticle at default distance.
            if (m_Reticle)
            {
                m_Reticle.SetPosition(raycastPos, raycastDir);
            }
        }
    }