예제 #1
0
        private void AddToDelta()
        {
            // Calculate delta
            var delta = inputManager.GetAverageDeltaScaled() * Sensitivity;

            if (inputManager.Fingers.Count > 1)
            {
                delta = Vector2.zero;
            }

            // Store old rotation
            var oldRotation = transform.localRotation;

            // Rotate
            transform.Rotate(delta.y, -delta.x, 0.0f, Space.Self);

            var roll = 0.0f;

            if (Input.GetKey(RollLeftKey) == true)
            {
                roll += 1.0f;
            }

            if (Input.GetKey(RollRightKey) == true)
            {
                roll -= 1.0f;
            }

            transform.Rotate(0.0f, 0.0f, roll * RollSpeed * Time.deltaTime, Space.Self);

            // Add to remaining
            remainingDelta *= Quaternion.Inverse(oldRotation) * transform.localRotation;

            // Revert rotation
            transform.localRotation = oldRotation;
        }
        private void AddToDelta()
        {
            // Get delta from fingers
            var deltaXY = inputManager.GetAverageDeltaScaled() * PanSensitivity;
            var deltaZ  = (inputManager.GetPinchScale() - 1.0f) * PinchSensitivity;

            if (inputManager.Fingers.Count < 2)
            {
                deltaXY = Vector2.zero;

                KeySensitivity *= inputManager.GetPinchScale(WheelSensitivity);
            }

            // Add delta from keyboard
            deltaXY.x += Input.GetAxisRaw("Horizontal") * KeySensitivity * Time.deltaTime;
            deltaZ    += Input.GetAxisRaw("Vertical") * KeySensitivity * Time.deltaTime;

            if (SlowOnProximity == true)
            {
                var distance = float.PositiveInfinity;

                if (SgtHelper.OnCalculateDistance != null)
                {
                    SgtHelper.OnCalculateDistance(transform.position, ref distance);
                }

                if (distance < SlowDistanceMax)
                {
                    var distance01 = Mathf.InverseLerp(SlowDistanceMin, SlowDistanceMax, distance);
                    var multiplier = Mathf.Lerp(SlowMultiplier, 1.0f, distance01);

                    deltaXY *= multiplier;
                    deltaZ  *= multiplier;
                }
            }

            // Store old position
            var oldPosition = transform.position;

            // Translate
            var delta = new Vector3(deltaXY.x, deltaXY.y, deltaZ);

            transform.Translate(delta, Space.Self);

            // Add to remaining
            var acceleration = transform.position - oldPosition;

            remainingDelta += acceleration;

            // Revert position
            transform.position = oldPosition;

            // Rotate to acceleration?
            if (Target != null && TargetRotation != RotationType.None && delta != Vector3.zero)
            {
                var factor   = SgtHelper.DampenFactor(TargetDampening, Time.deltaTime);
                var rotation = Target.transform.rotation;

                switch (TargetRotation)
                {
                case RotationType.Acceleration:
                {
                    rotation = Quaternion.LookRotation(acceleration, Target.transform.up);
                }
                break;

                case RotationType.MainCamera:
                {
                    var camera = Camera.main;

                    if (camera != null)
                    {
                        rotation = camera.transform.rotation;
                    }
                }
                break;
                }

                Target.transform.rotation = Quaternion.Slerp(Target.transform.rotation, rotation, factor);
                Target.angularVelocity    = Vector3.Lerp(Target.angularVelocity, Vector3.zero, factor);
            }
        }