feat(gameplay): 添加建筑系统和改进摄像机控制

- 移除人类士兵数据资产文件,重构为建筑放置系统
- 在CharacterData中添加productionInterval和buildingCost字段用于建筑生产
- 实现CameraFollow脚本的完整重写,支持键盘WASD拖动、鼠标拖动、触摸拖动
- 添加摄像机缩放功能,支持上下键和触摸双指缩放
- 更新Projecttile.cs以同时处理单位和建筑目标的伤害检测
- 修改SummonCardButton从法力值召唤改为金币建筑放置模式
- 在UnitBase.cs中更新攻击逻辑以支持对建筑造成伤害
- 升级WorldHealthBar以显示建筑生产进度和更好的缩放补偿
- 修复MainCharacterDebugMovement移除键盘移动输入冲突
- 更新包管理器中的codely.bridge版本从1.0.80到1.0.81
```
This commit is contained in:
huadexuan committed 2026-09-13 23:35:59 +08:00
1 parent fb56cd7ede
commit 769aea30f3
55 files changed
+9328 -90

No files matched your search

+128 -20
View File
@@ -2,36 +2,144 @@ using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target; // 角色的Transform组件
public Vector3 offset; // 摄像机相对于角色的偏移量
public float smoothSpeed = 0.125f; // 摄像机移动的平滑速度
[Header("拖动控制")]
public float keyboardDragSpeed = 10f; // WASD拖动速度(模拟手指拖动屏幕)
public float mouseDragSpeed = 0.5f; // 鼠标拖动速度
public float touchDragSpeed = 0.5f; // 触摸拖动速度
[Header("缩放控制(正交相机用orthographicSize,透视相机用fieldOfView)")]
public float zoomSpeed = 5f; // 缩放速度
public float minOrthographicSize = 5f; // 正交相机最小size
public float maxOrthographicSize = 20f; // 正交相机最大size
public float minFieldOfView = 30f; // 透视相机最小FOV
public float maxFieldOfView = 90f; // 透视相机最大FOV
[Header("边界限制")]
public bool enableBounds = true; // 是否启用边界限制
public float minX = -6f; // X轴最小边界
public float maxX = 6f; // X轴最大边界
public float minZ = -30f; // Z轴最小边界(摄像机位置,不是主角位置)
public float maxZ = 91f; // Z轴最大边界(摄像机位置,不是主角位置)
public bool enableBounds = true;
public float minX = -6f;
public float maxX = 6f;
public float minZ = -30f;
public float maxZ = 91f;
private void LateUpdate()
private Vector3 lastMousePosition;
private bool isDragging = false;
private Camera cam;
private void Start()
{
if (target == null)
cam = GetComponent<Camera>();
if (cam == null)
{
return;
Debug.LogError("CameraFollow需要挂载在Camera组件上");
}
}
private void Update()
{
HandleKeyboardDrag();
HandleMouseDrag();
HandleKeyboardZoom();
}
private void HandleKeyboardDrag()
{
float horizontal = 0f;
float vertical = 0f;
if (Input.GetKey(KeyCode.W)) vertical = 1f;
if (Input.GetKey(KeyCode.S)) vertical = -1f;
if (Input.GetKey(KeyCode.A)) horizontal = -1f;
if (Input.GetKey(KeyCode.D)) horizontal = 1f;
if (horizontal != 0f || vertical != 0f)
{
Vector3 movement = new Vector3(horizontal, 0, vertical) * keyboardDragSpeed * Time.deltaTime;
MoveCameraWithBounds(movement);
}
}
private void HandleMouseDrag()
{
// 鼠标拖动
if (Input.GetMouseButtonDown(0))
{
lastMousePosition = Input.mousePosition;
isDragging = true;
}
else if (Input.GetMouseButton(0) && isDragging)
{
Vector3 delta = Input.mousePosition - lastMousePosition;
Vector3 movement = new Vector3(-delta.x, 0, -delta.y) * mouseDragSpeed * Time.deltaTime;
MoveCameraWithBounds(movement);
lastMousePosition = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
{
isDragging = false;
}
Vector3 desiredPosition = target.position + offset;
// 触摸拖动(移动设备)
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 touchDelta = Input.GetTouch(0).deltaPosition;
Vector3 movement = new Vector3(-touchDelta.x, 0, -touchDelta.y) * touchDragSpeed * Time.deltaTime;
MoveCameraWithBounds(movement);
}
}
private void HandleKeyboardZoom()
{
if (cam == null) return;
float zoomDelta = 0f;
// 上下键控制缩放
if (Input.GetKey(KeyCode.UpArrow)) zoomDelta = -1f; // 缩小(拉近)
if (Input.GetKey(KeyCode.DownArrow)) zoomDelta = 1f; // 放大(拉远)
// 触摸双指缩放
if (Input.touchCount == 2)
{
Touch touch0 = Input.GetTouch(0);
Touch touch1 = Input.GetTouch(1);
Vector2 touch0PrevPos = touch0.position - touch0.deltaPosition;
Vector2 touch1PrevPos = touch1.position - touch1.deltaPosition;
float prevMagnitude = (touch0PrevPos - touch1PrevPos).magnitude;
float currentMagnitude = (touch0.position - touch1.position).magnitude;
float difference = currentMagnitude - prevMagnitude;
zoomDelta = -difference * 0.01f; // 负号:手指分开=拉近,手指合拢=拉远
}
if (zoomDelta != 0f)
{
if (cam.orthographic)
{
// 正交相机:调整 orthographicSize
float newSize = cam.orthographicSize + zoomDelta * zoomSpeed * Time.deltaTime;
cam.orthographicSize = Mathf.Clamp(newSize, minOrthographicSize, maxOrthographicSize);
}
else
{
// 透视相机:调整 fieldOfView
float newFov = cam.fieldOfView + zoomDelta * zoomSpeed * Time.deltaTime;
cam.fieldOfView = Mathf.Clamp(newFov, minFieldOfView, maxFieldOfView);
}
}
}
private void MoveCameraWithBounds(Vector3 movement)
{
Vector3 newPosition = transform.position + movement;
// 边界限制:摄像机停在边界处,主角可以继续移动
if (enableBounds)
{
desiredPosition.x = Mathf.Clamp(desiredPosition.x, minX, maxX);
desiredPosition.z = Mathf.Clamp(desiredPosition.z, minZ, maxZ);
newPosition.x = Mathf.Clamp(newPosition.x, minX, maxX);
newPosition.z = Mathf.Clamp(newPosition.z, minZ, maxZ);
}
transform.position = Vector3.Lerp(
transform.position,
desiredPosition,
smoothSpeed);
transform.position = newPosition;
}
}