|
@@ -1,3 +1,4 @@
|
|
|
+using System;
|
|
|
using DG.Tweening;
|
|
|
using Unity.VisualScripting;
|
|
|
using UnityEngine;
|
|
@@ -22,6 +23,15 @@ public class CameraBirdSec : MonoBehaviour
|
|
|
public float rotateYAngle = 0.0f;
|
|
|
public float rotateXAngle = 0.0f;
|
|
|
|
|
|
+ public Action<float> OnDistanceChange;
|
|
|
+
|
|
|
+ public float min_X;
|
|
|
+ public float max_X;
|
|
|
+ public float min_Y;
|
|
|
+ public float max_Y;
|
|
|
+
|
|
|
+ public bool fixMoveRange = false;
|
|
|
+
|
|
|
bool isRotate = false;
|
|
|
|
|
|
bool onUI = false;
|
|
@@ -33,6 +43,8 @@ public class CameraBirdSec : MonoBehaviour
|
|
|
currentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance);
|
|
|
// 计算偏移量
|
|
|
offset = transform.position - target.position;
|
|
|
+
|
|
|
+ OnDistanceChange?.Invoke(currentDistance);
|
|
|
}
|
|
|
|
|
|
private bool IsPointerOverUIElement()
|
|
@@ -54,6 +66,7 @@ public class CameraBirdSec : MonoBehaviour
|
|
|
currentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance);
|
|
|
|
|
|
//this.GetComponent<DepthFog>().Height = 400000 / currentDistance;
|
|
|
+ OnDistanceChange?.Invoke(currentDistance);
|
|
|
}
|
|
|
if (Input.GetMouseButton(2))
|
|
|
{
|
|
@@ -84,7 +97,15 @@ public class CameraBirdSec : MonoBehaviour
|
|
|
Vector3 moveDirection = Vector3.down * mouseOffset.y * translateSpeed + Vector3.left * mouseOffset.x * translateSpeed;
|
|
|
// 平滑移动摄像头到目标位置
|
|
|
target.position += moveDirection;
|
|
|
-
|
|
|
+ //限制移动范围
|
|
|
+ if (fixMoveRange)
|
|
|
+ {
|
|
|
+ Vector3 finalPos=target.localPosition;
|
|
|
+ finalPos.x = Mathf.Clamp(finalPos.x, min_X, max_X);
|
|
|
+ finalPos.y = Mathf.Clamp(finalPos.y, min_Y, max_Y);
|
|
|
+ target.localPosition = finalPos;
|
|
|
+ }
|
|
|
+
|
|
|
// 计算目标位置
|
|
|
Vector3 targetPosition = target.position + Quaternion.Euler(new Vector3(rotateXAngle, 0, 0)) * offset.normalized * currentDistance;
|
|
|
|
|
@@ -128,6 +149,23 @@ public class CameraBirdSec : MonoBehaviour
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public void SetRange(float _minX,float _maxX,float _minY,float _maxY)
|
|
|
+ {
|
|
|
+ min_X = _minX;
|
|
|
+ max_X = _maxX;
|
|
|
+ min_Y = _minY;
|
|
|
+ max_Y = _maxY;
|
|
|
+
|
|
|
+ //限制移动范围
|
|
|
+ if (fixMoveRange)
|
|
|
+ {
|
|
|
+ Vector3 finalPos=target.localPosition;
|
|
|
+ finalPos.x = Mathf.Clamp(finalPos.x, min_X, max_X);
|
|
|
+ finalPos.y = Mathf.Clamp(finalPos.y, min_Y, max_Y);
|
|
|
+ target.localPosition = finalPos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void SetCameraToCenterFade(Vector3 centerPos,float distance = 300)
|
|
|
{
|