2025-06-15 20:14:45 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class MapManager : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
private float moveSpeed = 10;
|
|
|
|
|
|
private float mapRealWidth;
|
|
|
|
|
|
private float mapRealHeight;
|
|
|
|
|
|
private Vector3 lastMousePosition;
|
|
|
|
|
|
private void UpdateCamera()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Input.GetAxis("Mouse ScrollWheel") < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize + Time.deltaTime * moveSpeed * Camera.main.orthographicSize, 5, 40);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (Input.GetAxis("Mouse ScrollWheel") > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize - Time.deltaTime * moveSpeed * Camera.main.orthographicSize, 5, 40);
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>϶<EFBFBD>ƽ<EFBFBD><C6BD>
|
|
|
|
|
|
if (Input.GetMouseButtonDown(2)) // <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
{
|
|
|
|
|
|
lastMousePosition = Input.mousePosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (Input.GetMouseButton(2)) // <20><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>ס
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 delta = Input.mousePosition - lastMousePosition;
|
|
|
|
|
|
Vector3 move = new Vector3(-delta.x, -delta.y, 0) * Time.deltaTime * Camera.main.orthographicSize; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
|
Vector3 newPosition = Camera.main.transform.position + move;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ͼ<EFBFBD>߽磩
|
2025-07-25 15:36:10 +08:00
|
|
|
|
newPosition.x = Mathf.Clamp(newPosition.x, 0, mapRealWidth * 1.5f);
|
2025-06-15 20:14:45 +08:00
|
|
|
|
newPosition.y = Mathf.Clamp(newPosition.y, 0, mapRealHeight);
|
|
|
|
|
|
Camera.main.transform.position = newPosition;
|
|
|
|
|
|
|
|
|
|
|
|
lastMousePosition = Input.mousePosition; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-19 13:32:33 +08:00
|
|
|
|
public void ReseCamera(float x, float y)
|
2025-06-15 20:14:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
Camera.main.transform.position = new Vector3(x / 2, y / 2, -10);
|
|
|
|
|
|
Camera.main.orthographicSize = 5;
|
|
|
|
|
|
mapRealWidth = x;
|
|
|
|
|
|
mapRealHeight = y;
|
|
|
|
|
|
}
|
2025-07-19 01:21:40 +08:00
|
|
|
|
|
|
|
|
|
|
public void MoveToCamera(float x, float y)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 newPosition;
|
2025-07-25 15:36:10 +08:00
|
|
|
|
newPosition.x = Mathf.Clamp(x, 0, mapRealWidth * 1.5f);
|
2025-07-19 01:21:40 +08:00
|
|
|
|
newPosition.y = Mathf.Clamp(y, 0, mapRealHeight);
|
|
|
|
|
|
Camera.main.transform.position = new Vector3(x, y, -10);
|
|
|
|
|
|
}
|
2025-07-19 12:48:11 +08:00
|
|
|
|
|
|
|
|
|
|
public Vector2Int GetCameraPos()
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector2Int pos = new Vector2Int();
|
|
|
|
|
|
pos.x = (int)Camera.main.transform.position.x;
|
|
|
|
|
|
pos.y = (int)Camera.main.transform.position.y;
|
2025-07-25 15:36:10 +08:00
|
|
|
|
pos.x = Mathf.Clamp(pos.x, 0, (int)(mapRealWidth * 1.5f));
|
2025-07-19 12:48:11 +08:00
|
|
|
|
pos.y = Mathf.Clamp(pos.y, 0, (int)mapRealHeight);
|
|
|
|
|
|
pos.x = (int)(pos.x / map.sideWidth);
|
|
|
|
|
|
pos.y = (int)(pos.y / map.sideHeight);
|
|
|
|
|
|
return pos;
|
|
|
|
|
|
}
|
2025-06-15 20:14:45 +08:00
|
|
|
|
}
|