2020-03-25 03:15:00 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
2020-03-29 04:19:24 +01:00
|
|
|
|
using static Unity.Mathematics.math;
|
2020-03-25 03:15:00 +00:00
|
|
|
|
|
2020-12-12 00:02:00 +00:00
|
|
|
|
public class MapViewDragHandler : MonoBehaviour
|
2020-03-25 03:15:00 +00:00
|
|
|
|
{
|
|
|
|
|
|
public Camera Camera;
|
|
|
|
|
|
public float Scaling;
|
2020-04-28 01:50:50 +01:00
|
|
|
|
public ClickCatcher Background;
|
2020-03-25 03:15:00 +00:00
|
|
|
|
private Vector2 _previousPosition;
|
2020-05-06 04:56:36 +01:00
|
|
|
|
private bool _isDragging;
|
2020-03-25 03:15:00 +00:00
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
2020-05-06 04:56:36 +01:00
|
|
|
|
var newPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
|
|
|
|
|
|
|
|
if (!Input.GetMouseButton(0)) _isDragging = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (_isDragging) Camera.transform.position -= (Vector3) ((Vector2) newPosition - _previousPosition);
|
|
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
if (Background.PointerIsInside)
|
2020-03-25 03:15:00 +00:00
|
|
|
|
{
|
2020-05-06 04:56:36 +01:00
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
2020-04-28 01:50:50 +01:00
|
|
|
|
{
|
2020-05-06 04:56:36 +01:00
|
|
|
|
_previousPosition = newPosition;
|
|
|
|
|
|
_isDragging = true;
|
2020-04-28 01:50:50 +01:00
|
|
|
|
}
|
2020-03-25 03:15:00 +00:00
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
|
if (abs(Input.mouseScrollDelta.y) > .01f)
|
|
|
|
|
|
{
|
|
|
|
|
|
var previousPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
|
|
Camera.orthographicSize *= 1 + Input.mouseScrollDelta.y * Scaling;
|
|
|
|
|
|
Camera.transform.position -= Camera.ScreenToWorldPoint(Input.mousePosition) - previousPosition;
|
|
|
|
|
|
}
|
2020-03-29 04:19:24 +01:00
|
|
|
|
}
|
2020-03-25 03:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|