private void HandleClick() { if (m_CurrentInteractible != null) { m_CurrentInteractible.Click(); } }
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); } } }