示例#1
0
        protected override void doRaycast()
        {
            // Show the debug ray if required
            if (ShowDebugRay)
            {
                Debug.DrawRay(CameraT.position, CameraT.forward * DebugRayLength, Color.blue, DebugRayDuration);
            }

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

            // Do the raycast forweards 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;

                // 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.GazeOver(m_VrInput);
                }

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

                m_LastInteractible = interactible;

                // Something was hit, set at the hit position.
                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();
                }
            }
        }
示例#2
0
        // Use this for initialization
        void Start()
        {
            if (Source == null)
            {
                Source = transform.parent.GetComponent <VRControllerRaycaster>();
            }
            if (Reticle == null)
            {
                Reticle = GetComponent <Reticle>();
            }
            if (FromTransform == null)
            {
                FromTransform = Source.Input.transform;
            }

            if (hasOff)
            {
                m_OffRenderer               = new GameObject("OffLine").AddComponent <LineRenderer>();
                m_OffRenderer.startWidth    = OffStartWidth;
                m_OffRenderer.endWidth      = OffEndWidth;
                m_OffRenderer.startColor    = OffColor;
                m_OffRenderer.material      = OffMaterial;
                m_OffRenderer.endColor      = new Color(OffColor.r, OffColor.g, OffColor.b, 0);
                m_OffRenderer.useWorldSpace = true;
                m_OffRenderer.enabled       = false;
            }

            if (hasOn)
            {
                m_OnRendererColor = new GameObject("OnLineColor").AddComponent <LineRenderer>();
                m_OnRendererWhite = new GameObject("OnLineWhite").AddComponent <LineRenderer>();

                Vector3[] v3LinePositions = new Vector3[] { Vector3.zero, new Vector3(0, 0, 1) };
                foreach (LineRenderer r in new LineRenderer[] { m_OnRendererColor, m_OnRendererWhite })
                {
                    r.numCapVertices = CapVerts;
                    r.positionCount  = v3LinePositions.Length;
                    r.SetPositions(v3LinePositions);
                    r.useWorldSpace = true;
                    r.material      = OnMaterial;
                }

                m_OnRendererColor.startWidth = OnWidth;
                m_OnRendererColor.endWidth   = OnWidth;
                m_OnRendererColor.startColor = OnColor;
                m_OnRendererColor.endColor   = OnColor;
                m_OnRendererWhite.startWidth = CenterWidthRel * OnWidth;
                m_OnRendererWhite.endWidth   = CenterWidthRel * OnWidth;
                m_OnRendererWhite.startColor = Color.white;
                m_OnRendererWhite.endColor   = Color.white;
                m_OnRendererColor.enabled    = false;
                m_OnRendererWhite.enabled    = false;
            }

            foreach (LineRenderer r in new LineRenderer[] { m_OffRenderer, m_OnRendererColor, m_OnRendererWhite })
            {
                if (r)
                {
                    r.transform.SetParent(transform);
                    r.transform.localPosition = Vector3.zero;
                }
            }
        }