Я пытаюсь переустановить систему pinch-to-zoom в приложении Unity UI. Около шести месяцев назад я смог взломать один из них, сделав холст пользовательского интерфейса дочерним элементом обычного GameObject и манипулируя преобразованием этого объекта, но так как обновление до Unity 5.5+ я считаю, что это не работает. Самое близкое, что я могу получить, позволяет жесту щепотка изменить масштабный масштабный файл canvas, который: a) может неправильно изменять размеры изображений, панелей и т. Д. В зависимости от их выравнивания, и b) не позволит мне кастрюли после увеличения.Pinch-To-Zoom с Unity 5 UI
То, что я до сих пор это:
public class PinchToZoomScaler : MonoBehaviour {
public Canvas canvas; // The canvas
public float zoomSpeed = 0.5f; // The rate of change of the canvas scale factor
public float _resetDuration = 3.0f;
float _durationTimer = 0.0f;
float _startScale = 0.0f;
void Start() {
_startScale = canvas.scaleFactor;
}
void Update()
{
// If there are two touches on the device...
if (Input.touchCount == 2) {
// Store both touches.
Touch touchZero = Input.GetTouch (0);
Touch touchOne = Input.GetTouch (1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
// ... change the canvas size based on the change in distance between the touches.
canvas.scaleFactor -= deltaMagnitudeDiff * zoomSpeed;
// Make sure the canvas size never drops below 0.1
canvas.scaleFactor = Mathf.Max (canvas.scaleFactor, _startScale);
canvas.scaleFactor = Mathf.Min (canvas.scaleFactor, _startScale * 3.0f);
_durationTimer = 0.0f;
} else {
_durationTimer += Time.deltaTime;
if (_durationTimer >= _resetDuration) {
canvas.scaleFactor = _startScale;
}
}
}
}
Как я уже сказал, это работает в определенной степени, но не дает мне хорошее равномерное масштабирование, не позволяет ли она мне панорамировать холст. Заранее благодарю за любую помощь.