Esempio n. 1
0
 /// <summary>
 /// Convenience function for cloning PointerEventData
 /// </summary>
 /// <param name="from">Copy this value</param>
 /// <param name="to">to this object</param>
 protected void CopyFromTo(OVRRayPointerEventData @from, OVRRayPointerEventData @to)
 {
     @to.position              = @from.position;
     @to.delta                 = @from.delta;
     @to.scrollDelta           = @from.scrollDelta;
     @to.pointerCurrentRaycast = @from.pointerCurrentRaycast;
     @to.pointerEnter          = @from.pointerEnter;
     @to.worldSpaceRay         = @from.worldSpaceRay;
 }
Esempio n. 2
0
        /// <summary>
        /// The purpose of this function is to allow us to switch between using the standard IsPointerMoving
        /// method for mouse driven pointers, but to always return true when it's a ray based pointer.
        /// All real-world ray-based input devices are always moving so for simplicity we just return true
        /// for them.
        ///
        /// If PointerEventData.IsPointerMoving was virtual we could just override that in
        /// OVRRayPointerEventData.
        /// </summary>
        /// <param name="pointerEvent"></param>
        /// <returns></returns>
        static bool IsPointerMoving(PointerEventData pointerEvent)
        {
            OVRRayPointerEventData rayPointerEventData = pointerEvent as OVRRayPointerEventData;

            if (rayPointerEventData != null)
            {
                return(true);
            }
            else
            {
                return(pointerEvent.IsPointerMoving());
            }
        }
Esempio n. 3
0
        protected bool GetPointerData(int id, out OVRRayPointerEventData data, bool create)
        {
            if (!m_VRRayPointerData.TryGetValue(id, out data) && create)
            {
                data = new OVRRayPointerEventData(eventSystem)
                {
                    pointerId = id,
                };

                m_VRRayPointerData.Add(id, data);
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

            OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData;

            if (rayPointerEventData == null)
            {
                return;
            }

            var ray = rayPointerEventData.worldSpaceRay;

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.RaycastAll(ray, dist, finalEventMask);

            if (hits.Length > 1)
            {
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
            }

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject    = hits[b].collider.gameObject,
                        module        = this,
                        distance      = hits[b].distance,
                        index         = resultAppendList.Count,
                        worldPosition = hits[0].point,
                        worldNormal   = hits[0].normal,
                    };
                    resultAppendList.Add(result);
                }
            }
        }
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

            OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData;

            if (rayPointerEventData == null)
            {
                return;
            }

            var ray = rayPointerEventData.worldSpaceRay;

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            //warrick: offset the laser so it doesn't render oddly.
            //setPosition(0, ray.origin) if want to shoot exactly from head.
            Vector3 laserOrigin = new Vector3(ray.origin.x, ray.origin.y * .7f, ray.origin.z);


            if (debugLine != null)
            {
                debugLine.SetPosition(0, laserOrigin);
                debugLine.SetPosition(1, ray.origin + ray.direction * dist);
            }

            var hits = Physics.RaycastAll(ray, dist, finalEventMask);

            if (hits.Length > 1)
            {
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
            }

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject    = hits[b].collider.gameObject,
                        module        = this,
                        distance      = hits[b].distance,
                        index         = resultAppendList.Count,
                        worldPosition = hits[0].point,
                        worldNormal   = hits[0].normal,
                    };
                    resultAppendList.Add(result);
                }
            }

            /*warrick: Added this so physics raycaster returning results always
             * else
             * {
             *  if (Input.GetButtonDown("Fire1"))
             *  {
             *      transform.root.position = ray.origin + ray.direction * teleportDistance;
             *      Debug.Log("test");
             *  }
             * }
             */
        }