using System; using System.Collections.Generic; using DG.Tweening; using Unity.Mathematics; using Unity.VisualScripting; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class CameraBirdSec : MonoBehaviour { public Action beginDrag; public Transform target; // 目标对象,摄像头将朝向此对象 public float smoothSpeed = 0.125f; // 摄像头平滑移动的速度 public float scrollSensitivity = 5f; // 鼠标滚轮的灵敏度 public float rotateSpeed = 0.25f; public float translateSpeed = 3f; public float minDistance = 5f; // 摄像头与目标对象的最小距离 public float maxDistance = 50f; // 摄像头与目标对象的最大距离 public float currentDistance; // 当前摄像头与目标对象的距离 private Vector3 offset; // 摄像头与目标对象的偏移量 private Vector3 velocity = Vector3.zero; // 摄像头移动的速度 private bool isDragging = false; // 是否正在拖拽 private Vector3 lastMousePosition; // 上一帧鼠标位置 public Canvas canvas; public float rotateYAngle = 0.0f; public float rotateXAngle = 0.0f; public Action OnDistanceChange; public float min_X; public float max_X; public float min_Y; public float max_Y; public bool fixMoveRange = false; public bool detailLod = false; bool isRotate = false; bool onUI = false; void Start() { // 计算偏移量 offset = transform.position - target.position; } private bool GetPointerOverUIElement(out GameObject uiElement) { uiElement = null; PointerEventData pointerEventData = new PointerEventData(EventSystem.current) { position = Input.mousePosition }; RaycastResult raycastResult = new RaycastResult(); List results = new List(); GraphicRaycaster raycaster = canvas.GetComponent(); if (raycaster != null) { raycaster.Raycast(pointerEventData, results); if (results.Count > 0) { raycastResult = results[0]; uiElement = raycastResult.gameObject; return true; } } return false; } private bool IsPointerOverUIElement() { bool specialUI = false; if (GetPointerOverUIElement(out GameObject uiElement)) { // 获取 UI 元素的类型 if (uiElement.TryGetComponent