Example #1
0
 protected void HandleTriggerDown()
 {
     if (m_CurrentInteractible != null)
     {
         // Do trigger down and over
         m_CurrentInteractible.TriggerDown(m_VrInput);
         m_CurrentInteractible.TriggerOver(m_VrInput);
     }
 }
        protected override void doRaycast()
        {
            if (m_Enabled)
            {
                // Show the debug ray if required
                if (ShowDebugRay)
                {
                    Debug.DrawRay(ctrlT.position, ctrlT.forward * DebugRayLength, Color.blue, DebugRayDuration);
                }

                // Create a ray that points forwards from the controller.
                Ray        ray = new Ray(ctrlT.position, ctrlT.forward);
                RaycastHit hit;

                // Do the raycast forwards to see if we hit an interactive item
                if (Physics.Raycast(ray, out hit, RayLength, ~ExclusionLayers))
                {
                    // Something was hit, set at the hit position.
                    m_HitPosition = hit.point;
                    m_HitAngle    = Quaternion.FromToRotation(Vector3.forward, hit.normal);

                    VRInteractiveItem interactible = hit.collider.GetComponent <VRInteractiveItem>(); //attempt to get the VRInteractiveItem on the hit object
                    m_CurrentInteractible = interactible;
                    //print( m_CurrentInteractible.name );

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

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

                    if (Reticle)
                    {
                        Reticle.SetPosition(hit);
                    }

                    _onRaycastHit(hit);
                }
                else
                {
                    // Nothing was hit, deactive the last interactive item.
                    deactiveLastInteractible();
                    m_CurrentInteractible = null;

                    // Position the reticle at default distance.
                    if (Reticle)
                    {
                        Reticle.SetPosition();
                    }
                }
            }
        }