Exemplo n.º 1
0
        private void Update()
        {
            UpdateLeft();
            UpdateRight();

            void UpdateLeft()
            {
                if (EnableHandDownTimeout)
                {
                    _leftHandNoInputCount += Time.deltaTime;
                }
                else
                {
                    _leftHandNoInputCount = 0f;
                }

                if (Integrator.CheckTypingOrMouseHandsCanMoveDown())
                {
                    _leftHandBlendRate = Mathf.Max(0f, _leftHandBlendRate - HandDownBlendSpeed * Time.deltaTime);
                }
                else
                {
                    _leftHandBlendRate = Mathf.Min(1f, _leftHandBlendRate + HandUpBlendSpeed * Time.deltaTime);
                }

                //NOTE: 多くの場合ブレンド計算しないほうが計算が軽い
                if (_leftHandBlendRate > 0.999f)
                {
                    _blendedLeftHand.Position = _leftHand.Position;
                    _blendedLeftHand.Rotation = _leftHand.Rotation;
                }
                else if (_leftHandBlendRate < 0.001f)
                {
                    _blendedLeftHand.Position = DownHand.LeftHand.Position;
                    _blendedLeftHand.Rotation = DownHand.LeftHand.Rotation;
                }
                else
                {
                    var rate = Mathf.SmoothStep(0, 1, _leftHandBlendRate);
                    _blendedLeftHand.Position = Vector3.Lerp(
                        DownHand.LeftHand.Position, _leftHand.Position, rate
                        );
                    _blendedLeftHand.Rotation = Quaternion.Slerp(
                        DownHand.LeftHand.Rotation, _leftHand.Rotation, rate
                        );
                }
            }

            void UpdateRight()
            {
                if (EnableHandDownTimeout)
                {
                    _rightHandNoInputCount += Time.deltaTime;
                }
                else
                {
                    _rightHandNoInputCount = 0f;
                }

                if (Integrator.CheckTypingOrMouseHandsCanMoveDown())
                {
                    _rightHandBlendRate = Mathf.Max(0f, _rightHandBlendRate - HandDownBlendSpeed * Time.deltaTime);
                }
                else
                {
                    _rightHandBlendRate = Mathf.Min(1f, _rightHandBlendRate + HandUpBlendSpeed * Time.deltaTime);
                }

                //NOTE: 多くの場合ブレンド計算しないほうが計算が軽い
                if (_rightHandBlendRate > 0.999f)
                {
                    _blendedRightHand.Position = _rightHand.Position;
                    _blendedRightHand.Rotation = _rightHand.Rotation;
                }
                else if (_rightHandBlendRate < 0.001f)
                {
                    _blendedRightHand.Position = DownHand.RightHand.Position;
                    _blendedRightHand.Rotation = DownHand.RightHand.Rotation;
                }
                else
                {
                    var rate = Mathf.SmoothStep(0, 1, _rightHandBlendRate);
                    _blendedRightHand.Position = Vector3.Lerp(
                        DownHand.RightHand.Position, _rightHand.Position, rate
                        );
                    _blendedRightHand.Rotation = Quaternion.Slerp(
                        DownHand.RightHand.Rotation, _rightHand.Rotation, rate
                        );
                }
            }
        }