Exemple #1
0
    public void OnUpdate()
    {
        // Set the reticle's position and scale
        if (Reticle != null)
        {
            if (IsPointerIntersecting)
            {
                Vector3 controllerDiff     = PointerTransform.position - PointerIntersectionRay.origin;
                Vector3 proj               = Vector3.Project(controllerDiff, PointerIntersectionRay.direction);
                Vector3 controllerAlongRay = PointerIntersectionRay.origin + proj;
                Vector3 difference         = PointerIntersection - controllerAlongRay;
                Vector3 clampedDifference  = Vector3.ClampMagnitude(difference, MaxReticleDistance);
                Vector3 clampedPosition    = controllerAlongRay + clampedDifference;
                Reticle.transform.position = clampedPosition;
            }
            else
            {
                Reticle.transform.localPosition = new Vector3(0, 0, MaxReticleDistance);
            }

            float reticleDistanceFromCamera =
                (Reticle.transform.position - MainCamera.transform.position).magnitude;
            float scale = RETICLE_SIZE_METERS * reticleMeshSizeRatio * reticleDistanceFromCamera;
            Reticle.transform.localScale = new Vector3(scale, scale, scale);
        }

        if (LaserLineRenderer == null)
        {
            Debug.LogWarning("Line renderer is null, returning");
            return;
        }

        // Set the line renderer positions.
        if (IsPointerIntersecting)
        {
            Vector3 laserDiff            = PointerIntersection - base.PointerTransform.position;
            float   intersectionDistance = laserDiff.magnitude;
            Vector3 direction            = laserDiff.normalized;
            float   laserDistance        = intersectionDistance > MaxLaserDistance ? MaxLaserDistance : intersectionDistance;
            lineEndPoint = base.PointerTransform.position + (direction * laserDistance);
        }
        else
        {
            lineEndPoint = base.PointerTransform.position + (base.PointerTransform.forward * MaxLaserDistance);
        }
        LaserLineRenderer.SetPosition(0, base.PointerTransform.position);
        LaserLineRenderer.SetPosition(1, lineEndPoint);

        // Adjust transparency
        float alpha = GvrArmModel.Instance.preferredAlpha;

#if UNITY_5_6_OR_NEWER
        LaserLineRenderer.startColor = Color.Lerp(Color.clear, LaserColor, alpha);
        LaserLineRenderer.endColor   = Color.clear;
#else
        LaserLineRenderer.SetColors(Color.Lerp(Color.clear, LaserColor, alpha), Color.clear);
#endif  // UNITY_5_6_OR_NEWER
    }
    public void OnUpdate()
    {
        // Set the reticle's position and scale
        if (Reticle != null)
        {
            if (IsPointerIntersecting)
            {
                Vector3 difference        = PointerIntersection - PointerIntersectionRay.origin;
                Vector3 clampedDifference = Vector3.ClampMagnitude(difference, MaxReticleDistance);
                Vector3 clampedPosition   = PointerIntersectionRay.origin + clampedDifference;
                Reticle.transform.position = clampedPosition;
            }
            else
            {
                Reticle.transform.localPosition = new Vector3(0, 0, MaxReticleDistance);
            }

            float reticleDistanceFromCamera =
                (Reticle.transform.position - MainCamera.transform.position).magnitude;
            float scale = RETICLE_SIZE_METERS * reticleMeshSizeRatio * reticleDistanceFromCamera;
            Reticle.transform.localScale = new Vector3(scale, scale, scale);
        }

        if (LaserLineRenderer == null)
        {
            Debug.LogWarning("Line renderer is null, returning");
            return;
        }

        // Set the line renderer positions.
        if (IsPointerIntersecting)
        {
            Vector3 laserDiff            = PointerIntersection - base.PointerTransform.position;
            float   intersectionDistance = laserDiff.magnitude;
            Vector3 direction            = laserDiff.normalized;
            float   laserDistance        = intersectionDistance > MaxLaserDistance ? MaxLaserDistance : intersectionDistance;
            lineEndPoint = base.PointerTransform.position + (direction * laserDistance);
        }
        else
        {
            lineEndPoint = base.PointerTransform.position + (base.PointerTransform.forward * MaxLaserDistance);
        }
        LaserLineRenderer.SetPosition(0, base.PointerTransform.position);
        LaserLineRenderer.SetPosition(1, lineEndPoint);

        // Adjust transparency
        float alpha = GvrArmModel.Instance.preferredAlpha;

#pragma warning disable CS0618 // Le type ou le membre est obsolète
        LaserLineRenderer.SetColors(Color.Lerp(Color.clear, LaserColor, alpha), Color.clear);
#pragma warning restore CS0618 // Le type ou le membre est obsolète
    }