Esempio n. 1
0
        private TrackedDeviceEventData GetOrCreateCachedTrackedDeviceEvent()
        {
            var result = m_CachedTrackedDeviceEventData;

            if (result == null)
            {
                result = new TrackedDeviceEventData(eventSystem);
                m_CachedTrackedDeviceEventData = result;
            }

            return(result);
        }
        public void CopyFrom(TrackedDeviceEventData eventData)
        {
            m_ImplementationData.pointerTarget        = eventData.pointerEnter;
            m_ImplementationData.isDragging           = eventData.dragging;
            m_ImplementationData.pressedTime          = eventData.clickTime;
            m_ImplementationData.pressedPosition      = eventData.pressPosition;
            m_ImplementationData.pressedRaycast       = eventData.pointerPressRaycast;
            m_ImplementationData.pressedGameObject    = eventData.pointerPress;
            m_ImplementationData.pressedGameObjectRaw = eventData.rawPointerPress;
            m_ImplementationData.draggedGameObject    = eventData.pointerDrag;
            m_ImplementationData.lastFrameRaycast     = eventData.pointerCurrentRaycast;

            m_ImplementationData.hoverTargets.Clear();
            m_ImplementationData.hoverTargets.AddRange(eventData.hovered);
        }
Esempio n. 3
0
        /// <summary>Copies data from this model to the UI Event.</summary>
        /// <param name="eventData">The event that copies the data.</param>
        public void CopyTo(TrackedDeviceEventData eventData)
        {
            eventData.rayPoints = m_RaycastPoints;
            // Demolish the position so we don't trigger any checks from the Graphics Raycaster.
            eventData.position  = new Vector2(float.MinValue, float.MinValue);
            eventData.layerMask = m_RaycastLayerMask;

            eventData.pointerEnter        = m_ImplementationData.pointerTarget;
            eventData.dragging            = m_ImplementationData.isDragging;
            eventData.clickTime           = m_ImplementationData.pressedTime;
            eventData.pressPosition       = m_ImplementationData.pressedPosition;
            eventData.pointerPressRaycast = m_ImplementationData.pressedRaycast;
            eventData.pointerPress        = m_ImplementationData.pressedGameObject;
            eventData.rawPointerPress     = m_ImplementationData.pressedGameObjectRaw;
            eventData.pointerDrag         = m_ImplementationData.draggedGameObject;

            eventData.hovered.Clear();
            eventData.hovered.AddRange(m_ImplementationData.hoverTargets);
        }
        public void CopyTo(TrackedDeviceEventData eventData)
        {
            eventData.ray         = new Ray(m_Position, m_Orientation * Vector3.forward);
            eventData.maxDistance = maxRaycastDistance;
            // Demolish the position so we don't trigger any checks from the Graphics Raycaster.
            eventData.position = new Vector2(float.MinValue, float.MinValue);

            eventData.pointerEnter        = m_ImplementationData.pointerTarget;
            eventData.dragging            = m_ImplementationData.isDragging;
            eventData.clickTime           = m_ImplementationData.pressedTime;
            eventData.pressPosition       = m_ImplementationData.pressedPosition;
            eventData.pointerPressRaycast = m_ImplementationData.pressedRaycast;
            eventData.pointerPress        = m_ImplementationData.pressedGameObject;
            eventData.rawPointerPress     = m_ImplementationData.pressedGameObjectRaw;
            eventData.pointerDrag         = m_ImplementationData.draggedGameObject;

            eventData.hovered.Clear();
            eventData.hovered.AddRange(m_ImplementationData.hoverTargets);
        }
        private void PerformRaycast(TrackedDeviceEventData eventData, List <RaycastResult> resultAppendList)
        {
            if (canvas == null)
            {
                return;
            }

            if (eventCamera == null)
            {
                return;
            }

            var ray = eventData.ray;

            var hitDistance = eventData.maxDistance;

            if (m_CheckFor3DOcclusion)
            {
                var hits = Physics.RaycastAll(ray, hitDistance, m_BlockingMask);

                if (hits.Length > 0 && hits[0].distance < hitDistance)
                {
                    hitDistance = hits[0].distance;
                }
            }

            if (m_CheckFor2DOcclusion)
            {
                var raycastDistance = hitDistance;
                var hits            = Physics2D.GetRayIntersectionAll(ray, raycastDistance, m_BlockingMask);

                if (hits.Length > 0 && hits[0].fraction * raycastDistance < hitDistance)
                {
                    hitDistance = hits[0].fraction * raycastDistance;
                }
            }

            m_RaycastResultsCache.Clear();
            SortedRaycastGraphics(canvas, ray, m_RaycastResultsCache);

            //Now that we have a list of sorted hits, process any extra settings and filters.
            for (var i = 0; i < m_RaycastResultsCache.Count; i++)
            {
                var validHit = true;

                var hitData = m_RaycastResultsCache[i];

                var go = hitData.graphic.gameObject;
                if (m_IgnoreReversedGraphics)
                {
                    var forward     = ray.direction;
                    var goDirection = go.transform.rotation * Vector3.forward;
                    validHit = Vector3.Dot(forward, goDirection) > 0;
                }

                validHit &= hitData.distance < hitDistance;

                if (validHit)
                {
                    Transform trans        = go.transform;
                    Vector3   transForward = trans.forward;
                    var       castResult   = new RaycastResult
                    {
                        gameObject    = go,
                        module        = this,
                        index         = resultAppendList.Count,
                        distance      = hitData.distance,
                        depth         = hitData.graphic.depth,
                        sortingLayer  = canvas.sortingLayerID,
                        sortingOrder  = canvas.sortingOrder,
                        worldPosition = hitData.worldHitPosition,
                        worldNormal   = -transForward
                    };
                    resultAppendList.Add(castResult);
                }
            }
        }