Aetheria/Assets/Scripts/UI/Menu/MapMenuInput.cs
Meta Vens 6140a06a0a Swap Unity.Mathematics usings for CultMath
Every Unity.Mathematics using, alias and qualified name under Assets\Scripts
and tools now names CultMath. The nine `using static ...noise;` lines are
gone: snoise lives on CultMath's math. UnityExtensions loses float4.ToColor
and Color.ToFloat4, which duplicate the bridge's ToColor and ToCultMath; the
float3 colour pair stays because the bridge has none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:39:12 +02:00

47 lines
1.5 KiB
C#

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using CultMath;
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;
}
}