Beispiel #1
0
        private void UpdateCurve()
        {
            Ray sourceRay = new Ray(_uiLaserInteractor.transform.position, _uiLaserInteractor.transform.forward);
            Ray hitRay    = new Ray(_uiLaserInteractor.EventData.PointerCurrentWorldPosition(), Vector3.forward);

            hitRay.direction = (sourceRay.origin - hitRay.origin).normalized;

            float startEndDistance = Vector3.Distance(
                sourceRay.origin,
                hitRay.origin);
            float handleDistance = startEndDistance / 4f;

            CubicBezierSegment bezierSegment = new CubicBezierSegment(
                sourceRay.origin,
                sourceRay.GetPoint(handleDistance),
                hitRay.GetPoint(handleDistance),
                hitRay.origin);

            float step = 1f / BezierSegmentCount;
            float t    = 0;

            for (int i = 0; i < BezierSegmentCount; ++i)
            {
                _lineRenderer.SetPosition(i, bezierSegment.Point(t));
                t += step;
            }
        }
Beispiel #2
0
        private void ButtonsHeld(XRInteractionEventReceiver receiver)
        {
            if (_attachable.CanAttachTo.Count > 0 && _attachable.CanAttachTo.Count > 0 &&
                _attachable.CanAttachTo[0].enabled)
            {
                if (!_lineRenderers[0].enabled)
                {
                    LineVisibility(true);
                }

                Transform targetTransform = _attachable.CanAttachTo[0].VisualizerTarget.transform;
                Ray       sourceRay       = new Ray(_sweepMesh.transform.position, _sweepMesh.transform.forward);
                Ray       targetRay       = new Ray(targetTransform.position, targetTransform.forward);

                float distance       = Vector3.Distance(transform.position, targetTransform.position);
                float handleDistance = distance / 3f;

                CubicBezierSegment segment = new CubicBezierSegment(
                    sourceRay.origin,
                    sourceRay.GetPoint(handleDistance),
                    targetRay.GetPoint(-handleDistance),
                    targetRay.origin);

                Vector3    initialSweepPosition      = _sweepMesh.transform.localPosition;
                Quaternion initialLocalSweepRotation = _sweepMesh.transform.localRotation;
                Quaternion initialSweepRotation      = _sweepMesh.transform.rotation;

                for (int i = 0; i < _lineRenderers.Length; ++i)
                {
                    int positionIndex = 0;
                    for (int step = 0; step < _stepLength; ++step)
                    {
                        float stepNormalized = (float)step / (float)_stepLength;
                        _sweepMesh.transform.position = segment.Point(stepNormalized);
                        _sweepMesh.transform.rotation =
                            Quaternion.Slerp(initialSweepRotation, targetTransform.rotation, stepNormalized);

                        _lineVertices[i][positionIndex] = _sweepMesh.transform.TransformPoint(_sweepVertices[i]);
                        positionIndex++;

                        _lineRenderers[i].SetPositions(_lineVertices[i]);

                        Vector2 newOffset = _lineRenderers[i].material.mainTextureOffset;
                        newOffset.x -= Time.deltaTime * _lineScrollMultiplier;
                        _lineRenderers[i].material.mainTextureOffset = newOffset;
                    }
                }

                _sweepMesh.transform.localPosition = initialSweepPosition;
                _sweepMesh.transform.localRotation = initialLocalSweepRotation;
            }
        }
Beispiel #3
0
        private void LateUpdate()
        {
            //TODO change to use event callbacks

            if (!_laserInteractor.enabled || !_laserInteractor.gameObject.activeSelf)
            {
                _lineRenderer.enabled = false;
                _hitTargetInstance.gameObject.SetActive(false);
                return;
            }
            else
            {
                _lineRenderer.enabled = true;
                _hitTargetInstance.gameObject.SetActive(true);
            }

            XRButtonDatum buttonDatum = _laserInteractor.GetButtonDatum(_visualizeButtonPressHitRay);

            if (null == buttonDatum)
            {
                Debug.LogWarning("Button specified on " + name + " not found in it's specified LaserInteractor.");
                return;
            }

            if (null == buttonDatum.PressCollider)
            {
                if (_lineRenderer.positionCount != 2)
                {
                    _lineRenderer.positionCount = 2;
                }
                _lineRenderer.SetPosition(0, _laserInteractor.CurrentSourceRay.origin);
                _lineRenderer.SetPosition(1, _laserInteractor.CurrentHitRay.origin);

                if (!_laserInteractor.CanInteractWithCurrentGameObject() && _hoverState != HoverState.Empty)
                {
                    _hoverState = HoverState.Empty;
                    _lineRenderer.startColor = _emptyStartColor;
                    _lineRenderer.endColor   = _emptyEndColor;
                    _hitTargetMaterial.color = _emptyEndColor;
                }
                else if (_laserInteractor.CanInteractWithCurrentGameObject() && _hoverState != HoverState.Hover)
                {
                    _hoverState = HoverState.Hover;
                    _lineRenderer.startColor = _hoverStartColor;
                    _lineRenderer.endColor   = _hoverEndColor;
                    _hitTargetMaterial.color = _hoverEndColor;
                }

                _hitTargetInstance.transform.localScale = new Vector3(
                    _hitTargetScale,
                    _hitTargetScale,
                    _hitTargetScale);
                _hitTargetInstance.transform.position = _laserInteractor.CurrentHitRay.origin;
                _hitTargetInstance.transform.up       = _laserInteractor.CurrentHitRay.direction;
            }
            else
            {
                if (_lineRenderer.positionCount != BezierSegmentCount)
                {
                    _lineRenderer.positionCount = BezierSegmentCount;
                }

                if (_hoverState != HoverState.Press)
                {
                    _hoverState = HoverState.Press;
                    _lineRenderer.startColor = _pressStartColor;
                    _lineRenderer.endColor   = _pressEndColor;
                    _hitTargetMaterial.color = _pressEndColor;
                }

                float startEndDistance = Vector3.Distance(
                    _laserInteractor.CurrentSourceRay.origin,
                    buttonDatum.RayHitChildedToPressGameObject.origin);
                float handleDistance = startEndDistance / 4f;

                Ray hitRay = new Ray();

                if (_aimHitRayAtInteractor)
                {
                    hitRay.origin    = buttonDatum.RayHitChildedToPressGameObject.origin;
                    hitRay.direction = buttonDatum.RayHitChildedToPressGameObject.origin - _laserInteractor.transform.position;
                }
                else
                {
                    hitRay.origin    = buttonDatum.RayHitChildedToPressGameObject.origin;
                    hitRay.direction = buttonDatum.RayHitChildedToPressGameObject.direction;
                }

                _hitTargetInstance.transform.localScale = new Vector3(
                    _hitTargetScale * 1.5f,
                    _hitTargetScale * 1.5f,
                    _hitTargetScale * 1.5f);
                _hitTargetInstance.transform.position = hitRay.origin;
                _hitTargetInstance.transform.up       = buttonDatum.RayHitChildedToPressGameObject.direction;

                CubicBezierSegment bezierSegment = new CubicBezierSegment(
                    _laserInteractor.CurrentSourceRay.origin,
                    _laserInteractor.CurrentSourceRay.GetPoint(handleDistance),
                    hitRay.GetPoint(handleDistance),
                    hitRay.origin);

                float step = 1f / BezierSegmentCount;
                float t    = 0;
                for (int i = 0; i < BezierSegmentCount; ++i)
                {
                    _lineRenderer.SetPosition(i, bezierSegment.Point(t));
                    t += step;
                }
            }
        }