/// <summary> /// Rotates object. /// </summary> private void RotateObject() { if (selectedObject != null) { TouchManager.TouchElement[] touchElements = TouchManager.Instance.TouchElements; float currentAngleY = 0; float currentAngleX = 0; if (RotationType == RotationMode.OneFinger) { currentAngleY = touchElements[0].position.x; currentAngleX = touchElements[0].position.y; } else if (RotationType == RotationMode.TwoFingers) { currentAngleY = touchElements[1].position.x; currentAngleX = touchElements[1].position.y; } else { currentAngleY = Vector2Extensions.AngleBetweenLinear(touchElements[0].position, touchElements[1].position); currentAngleX = 0; } float angleY = touchRotationY - currentAngleY; angleY = (RotationType == RotationMode.TwoFingers || RotationType == RotationMode.OneFinger) ? angleY * 0.4f * RotationSpeed : angleY * RotationSpeed; float angleX = touchRotationX - currentAngleX; angleX = (RotationType == RotationMode.TwoFingers || RotationType == RotationMode.OneFinger) ? angleX * 0.4f * RotationSpeed : angleX * RotationSpeed; if (RotationStep != -1f) { angleY = Mathf.Floor(angleY / RotationStep) * RotationStep; angleX = Mathf.Floor(angleX / RotationStep) * RotationStep; } if (selectedObject.Transformation.RotateEnabledAxis.HasFlag(Axis.Y)) objectRotation.y = initialRotation.y + angleY; if (selectedObject.Transformation.RotateEnabledAxis.HasFlag(Axis.X)) objectRotation.x = initialRotation.x + angleX; selectedObject.SetLocalRotation(objectRotation); } }
/// <summary> /// Sets initial rotation. /// </summary> private void SetInitialRotation() { TouchManager.TouchElement[] touchElements = TouchManager.Instance.TouchElements; initialRotation = objectRotation; if (RotationType == RotationMode.OneFinger) { touchRotationY = touchElements[0].position.x; touchRotationX = touchElements[0].position.y; } else if (RotationType == RotationMode.TwoFingers) { touchRotationY = touchElements[1].position.x; touchRotationX = touchElements[1].position.y; } else { touchRotationY = Vector2Extensions.AngleBetweenLinear(touchElements[0].position, touchElements[1].position); touchRotationX = 0; } }