Пример #1
0
        private void AddToDelta()
        {
            // Get delta from fingers
            var fingers = SgtInputManager.GetFingers(true);
            var deltaXY = SgtInputManager.GetScaledDelta(fingers) * PanSensitivity;
            var deltaZ  = (SgtInputManager.GetPinchScale(fingers, WheelSensitivity) - 1.0f) * PinchSensitivity;

            if (fingers.Count < 2)
            {
                deltaXY = Vector2.zero;
            }

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

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

            // Translate
            transform.Translate(deltaXY.x, deltaXY.y, deltaZ, Space.Self);

            // Add to remaining
            remainingDelta += transform.localPosition - oldPosition;

            // Revert position
            transform.localPosition = oldPosition;
        }
        private void AddToDelta()
        {
            // Calculate delta
            var fingers = SgtInputManager.GetFingers(true);
            var delta   = SgtInputManager.GetScaledDelta(fingers) * Sensitivity;

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

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

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

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

            // Revert rotation
            transform.localRotation = oldRotation;
        }
Пример #3
0
        private void AddToDelta()
        {
            // Calculate delta
            var fingers = SgtInputManager.GetFingers(true);
            var delta   = SgtInputManager.GetScaledDelta(fingers) * Sensitivity;

            if (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;
        }
Пример #4
0
        private void AddToDelta()
        {
            // Get delta from fingers
            var fingers = SgtInputManager.GetFingers(true);
            var deltaXY = SgtInputManager.GetScaledDelta(fingers) * PanSensitivity;
            var deltaZ  = (SgtInputManager.GetPinchScale(fingers, WheelSensitivity) - 1.0f) * PinchSensitivity;

            if (fingers.Count < 2)
            {
                deltaXY = Vector2.zero;
            }

            // 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
            transform.Translate(deltaXY.x, deltaXY.y, deltaZ, 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 && acceleration != Vector3.zero)
            {
                var factor   = SgtHelper.DampenFactor(TargetDampening, Time.deltaTime);
                var rotation = Target.transform.rotation;

                switch (TargetRotation)
                {
                case RotationType.Acceleration:
                {
                    rotation = Quaternion.FromToRotation(Target.transform.forward, acceleration);
                }
                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);
            }
        }