Esempio n. 1
0
        // Skip check for near/far plane!
        private bool TryGetHitDistance(Ray ray, ref float hitDistance, out RaycastHit hitResult)
        {
            float maxDistance = hitDistance;
            int   allraycasts = -1;

            allraycasts = Physics.RaycastNonAlloc(ray, st_arrayOfRaycasts, maxDistance, m_BlockingMask);
            if (allraycasts > 0)
            {
                if (allraycasts > 1)
                {
                    System.Array.Sort(st_arrayOfRaycasts, 0, allraycasts, VRTK3DRaycastHitComparer.instance);
                }

                RaycastHit hit;
                for (int i = 0; i < allraycasts && i < st_arrayOfRaycasts.Length; i++)
                {
                    hit = st_arrayOfRaycasts[i];
                    if (hit.collider != null && !VRTK4_PlayerObject.IsPlayerObject(hit.collider.gameObject))
                    {
                        hitDistance = hit.distance;
                        hitResult   = hit;
                        return(true);
                    }
                }
            }

            hitResult = default;
            return(false);
        }
        /// <summary>
        /// The SetPlayerObject method tags the given game object with a special player object class for easier identification.
        /// </summary>
        /// <param name="obj">The game object to add the player object class to.</param>
        /// <param name="objType">The type of player object that is to be assigned.</param>
        public static void SetPlayerObject(GameObject obj, ObjectTypes objType)
        {
            VRTK4_PlayerObject currentPlayerObject = obj.GetComponent <VRTK4_PlayerObject>();

            if (currentPlayerObject == null)
            {
                currentPlayerObject = obj.AddComponent <VRTK4_PlayerObject>();
            }
            currentPlayerObject.objectType = objType;
        }
Esempio n. 3
0
        protected virtual void OnTriggerExit(Collider currentCollider)
        {
            VRTK4_PlayerObject colliderCheck = currentCollider.GetComponentInParent <VRTK4_PlayerObject>();
            VRTK4_UIPointer    pointerCheck  = colliderCheck == null ? null : colliderCheck.GetPointer();

            if (pointerCheck != null)
            {
                pointerCheck.collisionClick = false;
            }
        }
Esempio n. 4
0
        protected virtual void OnTriggerEnter(Collider currentCollider)
        {
            VRTK4_PlayerObject colliderCheck = currentCollider.GetComponentInParent <VRTK4_PlayerObject>();
            VRTK4_UIPointer    pointerCheck  = colliderCheck == null ? null : colliderCheck.GetPointer();

            if (pointerCheck != null && colliderCheck != null &&
                colliderCheck.objectType == VRTK4_PlayerObject.ObjectTypes.Pointer)
            {
                pointerCheck.collisionClick = clickOnPointerCollision;
            }
        }
Esempio n. 5
0
        protected virtual void OnTriggerExit(Collider collider)
        {
            VRTK4_PlayerObject colliderCheck = collider.GetComponentInParent <VRTK4_PlayerObject>();
            VRTK4_UIPointer    pointerCheck  = colliderCheck == null? null: colliderCheck.GetPointer();

            if (pointerCheck != null &&
                pointerCheck.autoActivatingCanvas == gameObject &&
                colliderCheck.objectType == VRTK4_PlayerObject.ObjectTypes.Pointer)
            {
                pointerCheck.autoActivatingCanvas = null;
            }
        }
Esempio n. 6
0
        // Skip check for near/far plane!
        protected virtual float GetHitDistance(Ray ray, float hitDistance)
        {
            if (CanvasToUse.renderMode != RenderMode.ScreenSpaceOverlay && blockingObjects != BlockingObjects.None)
            {
                float maxDistance = Vector3.Distance(ray.origin, CanvasToUse.transform.position) + 10f;
                int   allraycasts = -1;
                if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
                {
                    allraycasts = Physics.RaycastNonAlloc(ray, st_arrayOfRaycasts, maxDistance, m_BlockingMask);
                    if (allraycasts > 0)
                    {
                        RaycastHit hit = st_arrayOfRaycasts[0];
                        if (hit.collider != null && !VRTK4_PlayerObject.IsPlayerObject(hit.collider.gameObject))
                        {
                            hitDistance = hit.distance;
                        }
                    }

                    ClearArrNonAlloc3D();
                }

                if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
                {
                    allraycasts = Physics2D.RaycastNonAlloc(ray.origin, ray.direction, st_arrayOfRaycasts2d,
                                                            maxDistance,
                                                            m_BlockingMask);
                    if (allraycasts > 0)
                    {
                        RaycastHit2D hit = st_arrayOfRaycasts2d[0];
                        if (hit.collider != null && !VRTK4_PlayerObject.IsPlayerObject(hit.collider.gameObject))
                        {
                            hitDistance = hit.fraction * maxDistance;
                        }
                    }

                    ClearArrNonAlloc2D();
                }
            }

            return(hitDistance);
        }