示例#1
0
        bool TryGetRaycastPoint(ref Vector3 raycastPos, ref Vector3 raycastNormal)
        {
            bool raycastHit = false;

            // Raycast against physics
            int hitCount = Physics.RaycastNonAlloc(m_Interactor.attachTransform.position, m_Interactor.attachTransform.forward,
                                                   m_RaycastHits, m_MaxRaycastDistance, m_RaycastMask);

            if (hitCount != 0)
            {
                Array.Sort(m_RaycastHits, 0, hitCount, m_RaycastHitComparer);
                raycastPos    = m_RaycastHits.First().point;
                raycastNormal = m_RaycastHits.First().normal;
                raycastHit    = true;
            }

            // Get last Raycast against EventSystem system with attached XRPointer (if available)
            if (m_XRUIPointer && m_XRUIPointer.enabled)
            {
                TrackedDeviceModel model             = m_XRUIPointer.GetTrackedDeviceModel();
                RaycastResult      lastRaycastResult = model.implementationData.lastFrameRaycast;
                if (lastRaycastResult.isValid)
                {
                    if ((lastRaycastResult.worldPosition - m_Interactor.transform.position).sqrMagnitude <
                        (raycastPos - m_Interactor.transform.position).sqrMagnitude)
                    {
                        raycastPos    = lastRaycastResult.worldPosition;
                        raycastNormal = lastRaycastResult.worldNormal;
                    }
                    raycastHit = true;
                }
            }

            return(raycastHit);
        }
示例#2
0
    /// <summary>
    /// Attempts to retrieve the current UI Model.  Returns false if not available.
    /// </summary>
    /// <param name="model"> The UI Model that matches that Interactor.</param>
    /// <returns></returns>
    public bool TryGetUIModel(out TrackedDeviceModel model)
    {
        if (m_InputModule != null)
        {
            if (m_InputModule.GetTrackedDeviceModel(this, out model))
            {
                return(true);
            }
        }

        model = new TrackedDeviceModel(-1);
        return(false);
    }
示例#3
0
        public override void UpdateUIModel(ref TrackedDeviceModel model)
        {
            // Start is called before the first frame update
            if (!isActiveAndEnabled)
            {
                return;
            }

            model.position    = transform.TransformPoint(0, -1, 0);
            model.orientation = transform.rotation;

            model.select = isUISelectActive;

            List <Vector3> raycastPoints = model.raycastPoints;

            raycastPoints.Clear();
            raycastPoints.Add(transform.TransformPoint(0, -1, 0));
            raycastPoints.Add(transform.TransformPoint(0, 1, 0));
        }
示例#4
0
    /// <summary>
    /// Updates the current UI Model to match the state of the Interactor
    /// </summary>
    /// <param name="model">The model that will match this Interactor</param>
    public void UpdateUIModel(ref TrackedDeviceModel model)
    {
        model.position    = m_StartTransform.position;
        model.orientation = m_StartTransform.rotation;
        model.select      = isUISelectActive;

        int numPoints = 0;

        GetLinePoints(ref s_CachedLinePoints, ref numPoints);

        List <Vector3> raycastPoints = model.raycastPoints;

        raycastPoints.Clear();
        if (numPoints > 0 && s_CachedLinePoints != null)
        {
            raycastPoints.Capacity = raycastPoints.Count + numPoints;
            for (int i = 0; i < numPoints; i++)
            {
                raycastPoints.Add(s_CachedLinePoints[i]);
            }
        }
        model.raycastLayerMask = raycastMask;
    }