Ejemplo n.º 1
0
        private void setCrosshairCanvasPositionAndScale()
        {
            if (_crosshairCanvasParent == null || VRPlayer.instance == null || _crosshairCamera == null)
            {
                return;
            }
            float canvasWidth = _crosshairCanvas.GetComponent <RectTransform>().rect.width;
            float scaleFactor = CROSSHAIR_SCALAR * VHVRConfig.CrosshairScalar() / canvasWidth;

            _crosshairCamera.transform.rotation = CameraUtils.getCamera(CameraUtils.VR_CAMERA).transform.rotation;
            _crosshairCamera.transform.position = CameraUtils.getCamera(CameraUtils.VR_CAMERA).transform.position;
            _crosshairCanvasParent.transform.SetParent(_crosshairCamera.gameObject.transform, false);
            _crosshairCanvasParent.transform.position = VRPlayer.instance.transform.position;
            float crosshairDistance = calculateCrosshairDistance();

            _crosshairCanvasParent.transform.localPosition             = new Vector3(0f, 0f, crosshairDistance);
            _crosshairCanvas.GetComponent <RectTransform>().localScale = Vector3.one * scaleFactor * crosshairDistance;
            _crosshairCanvasParent.transform.localRotation             = Quaternion.Euler(0f, 0f, 0f);
        }
Ejemplo n.º 2
0
        private void setHoverNameCanvasesPositionAndScale()
        {
            if (_hoverNameCanvasParent == null)
            {
                return;
            }
            float canvasWidth   = _hoverNameCanvas.GetComponent <RectTransform>().rect.width;
            float scaleFactor   = CROSSHAIR_SCALAR * VHVRConfig.CrosshairScalar() / canvasWidth;
            var   positionRight = HandBasedInteractionPatches.currentHitPositionRight;
            var   positionLeft  = HandBasedInteractionPatches.currentHitPositionLeft;
            float distanceRight = Vector3.Distance(positionRight, _crosshairCamera.transform.position);
            float distanceLeft  = Vector3.Distance(positionLeft, _crosshairCamera.transform.position);

            _hoverNameCanvasParent.transform.position   = positionRight;
            _hoverNameCanvasParent.transform.localScale = Vector3.one * scaleFactor * distanceRight;
            _hoverNameCanvasParent.transform.LookAt(_crosshairCamera.transform);
            _hoverNameCanvasParent.transform.Rotate(0f, 180f, 0f);
            _hoverNameCanvasParentLeft.transform.position   = positionLeft;
            _hoverNameCanvasParentLeft.transform.localScale = Vector3.one * scaleFactor * distanceLeft;
            _hoverNameCanvasParentLeft.transform.LookAt(_crosshairCamera.transform);
            _hoverNameCanvasParentLeft.transform.Rotate(0f, 180f, 0f);
        }