GetRay() public method

public GetRay ( ) : Ray
return Ray
Beispiel #1
0
        private void EyeRaycast()
        {
            // Show the debug ray if required
            if (m_ShowDebugRay)
            {
                Debug.DrawRay(m_Camera.position, m_Camera.forward * m_DebugRayLength, Color.blue, m_DebugRayDuration);
            }

            // Create a ray that points forwards from the camera.

            //Ray ray = new Ray(m_Camera.position, m_Camera.forward);
            Ray ray = m_SteamCamera.GetRay();

            RaycastHit hit;

            // Do the raycast forweards to see if we hit an interactive item
            if (Physics.Raycast(ray, out hit, m_RayLength, ~m_ExclusionLayers))
            {
                VRInteractiveItem interactible = hit.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();
                }

                m_LastInteractible = interactible;

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

                if (OnRaycasthit != null)
                {
                    OnRaycasthit(hit);
                }
            }
            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();
                }
            }
        }
    void FixedUpdate()
    {
        if (notificationCanvasOn)
        {
            //Debug.Log("notification canvas is on");
            RaycastHit[] hits;
            hits = Physics.RaycastAll(cameraScript.GetRay(), 10.0F).OrderBy(h => h.distance).ToArray();
            bool watching = false;
            //start timer. if watching becomes true, reset timer. once timer is over, reset notification
            bool firstCanvasFound = false;
            foreach (Collider c in canvasColliders)
            {
                c.gameObject.transform.localScale = Vector3.one;
            }
            for (int i = 0; i < hits.Length; i++)
            {
                RaycastHit hit = hits[i];
                if (hit.collider == selfCollider && !watching)
                {
                    watching = true;
                    watchAnimator.SetBool("Watching", watching);
                    lightSource.SetActive(false);
                    if (!isOn)
                    {
                        isOn = true;

                        //first time it happens note down the time that is the reaction time
                        if (!reacted)
                        {
                            reactionTime = Time.realtimeSinceStartup - notificationSpawnTime;
                            reacted      = true;
                            timerTarget  = 4.0f;
                        }
                    }
                    timerTarget = 4.0f;//reset timer
                }
                if (!firstCanvasFound && canvasColliders.Contains(hit.collider))
                {
                    firstCanvasFound = true;
                    watching         = true;
                    if (!isOn)
                    {
                        isOn = true;
                        if (!reacted)
                        {
                            reactionTime = Time.realtimeSinceStartup - notificationSpawnTime;
                            reacted      = true;
                        }
                    }
                    watchAnimator.SetBool("Watching", watching);
                    lightSource.SetActive(false);
                    timerTarget = 4.0f;//reset timer
                    hit.collider.gameObject.transform.localScale = Vector3.one * 3;
                }
            }
            timerTarget -= Time.deltaTime;
            // Debug.Log(timerTarget);

            if (watching == false && timerTarget < 0.0f)
            {
                notificationCanvasOn = false;
                timeCanvas.SetActive(true);
                canvasSet.SetActive(false);

                // end of interaction
                if (reacted && !ended)
                {
                    interactionDuration = Time.realtimeSinceStartup - notificationSpawnTime;
                    ended   = true;
                    reacted = false;
                    notificationController.GetComponent <NotificationController>().logInfo("Watch", "reaction Time", reactionTime);
                    notificationController.GetComponent <NotificationController>().logInfo("Watch", "interaction duration", interactionDuration);

                    notificationController.GetComponent <NotificationController>().onCurrentInteractionComplete();
                    //Debug.Log("reaction Time : " + reactionTime);
                    //Debug.Log("interaction Duration : " + interactionDuration);
                    lightSource.SetActive(false);
                }
            }
            if (watching == false && timerTarget < 2.0f)
            {
                watchAnimator.SetBool("Watching", watching);
                if (isOn)
                {
                    isOn = false;
                }
            }
        }
    }