Finished Map Tab
This commit is contained in:
parent
4f19189244
commit
615cc4e936
43 changed files with 8383 additions and 920 deletions
43
Assets/MapMenuInput.cs
Normal file
43
Assets/MapMenuInput.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class MapMenuInput : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
|
||||
{
|
||||
public MapRenderer Map;
|
||||
public float ZoomSpeed;
|
||||
|
||||
private Vector2 _startMousePosition;
|
||||
|
||||
private Vector2 _startMapPosition;
|
||||
private RectTransform _mapRect;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_mapRect = Map.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
_startMousePosition = eventData.position;
|
||||
_startMapPosition = Map.Position;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
Map.Position = _startMapPosition - (eventData.position - _startMousePosition) * Map.Scale;
|
||||
}
|
||||
|
||||
public void OnScroll(PointerEventData eventData)
|
||||
{
|
||||
Vector3[] mapCorners = new Vector3[4];
|
||||
_mapRect.GetWorldCorners(mapCorners);
|
||||
var mapCenter = ((float3)(mapCorners[2] + mapCorners[0]) / 2).xy;
|
||||
var oldPointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
|
||||
Map.Scale *= 1 - eventData.scrollDelta.y * ZoomSpeed;
|
||||
var pointerPosition = Map.Position + ((float2)eventData.position - mapCenter) * Map.Scale;
|
||||
Map.Position += oldPointerPosition - pointerPosition;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue