feat(gameplay): 添加建筑系统和改进摄像机控制 - 移除人类士兵数据资产文件,重构为建筑放置系统 - 在CharacterData中添加productionInterval和buildingCost字段用于建筑生产 - 实现CameraFollow脚本的完整重写,支持键盘WASD拖动、鼠标拖动、触摸拖动 - 添加摄像机缩放功能,支持上下键和触摸双指缩放 - 更新Projecttile.cs以同时处理单位和建筑目标的伤害检测 - 修改SummonCardButton从法力值召唤改为金币建筑放置模式 - 在UnitBase.cs中更新攻击逻辑以支持对建筑造成伤害 - 升级WorldHealthBar以显示建筑生产进度和更好的缩放补偿 - 修复MainCharacterDebugMovement移除键盘移动输入冲突 - 更新包管理器中的codely.bridge版本从1.0.80到1.0.81 ```
112 lines
2.6 KiB
C#
112 lines
2.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class MainCharacterDebugMovement : MonoBehaviour
|
|
{
|
|
[Header("电脑调试移动")]
|
|
[Min(0f)]
|
|
public float moveSpeed = 4f;
|
|
|
|
[Min(0f)]
|
|
public float clickStopDistance = 0.08f;
|
|
|
|
[Header("移动范围")]
|
|
public bool limitToBattlePlatform = true;
|
|
public Vector2 xLimits = new Vector2(-7.5f, 7.5f);
|
|
public Vector2 zLimits = new Vector2(-14f, 14f);
|
|
|
|
private Animator animator;
|
|
private Vector3 clickTarget;
|
|
private bool hasClickTarget;
|
|
|
|
public bool IsMoving => hasClickTarget;
|
|
|
|
private void Start()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
clickTarget = transform.position;
|
|
SetWalking(false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
HandleClickTarget();
|
|
|
|
if (!hasClickTarget)
|
|
{
|
|
SetWalking(false);
|
|
return;
|
|
}
|
|
|
|
Vector3 toTarget = clickTarget - transform.position;
|
|
toTarget.y = 0f;
|
|
|
|
if (toTarget.magnitude <= clickStopDistance)
|
|
{
|
|
hasClickTarget = false;
|
|
SetWalking(false);
|
|
return;
|
|
}
|
|
|
|
Move(toTarget.normalized);
|
|
}
|
|
|
|
private void HandleClickTarget()
|
|
{
|
|
if (!Input.GetMouseButtonDown(0) || Camera.main == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
return;
|
|
}
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
if (!Physics.Raycast(ray, out RaycastHit hit))
|
|
{
|
|
return;
|
|
}
|
|
|
|
clickTarget = hit.point;
|
|
clickTarget.y = transform.position.y;
|
|
hasClickTarget = true;
|
|
}
|
|
|
|
public void StopMovement()
|
|
{
|
|
hasClickTarget = false;
|
|
SetWalking(false);
|
|
}
|
|
|
|
private void Move(Vector3 direction)
|
|
{
|
|
direction.y = 0f;
|
|
if (direction.sqrMagnitude <= 0.001f)
|
|
{
|
|
SetWalking(false);
|
|
return;
|
|
}
|
|
|
|
SetWalking(true);
|
|
transform.position += direction * moveSpeed * Time.deltaTime;
|
|
if (limitToBattlePlatform)
|
|
{
|
|
Vector3 position = transform.position;
|
|
position.x = Mathf.Clamp(position.x, xLimits.x, xLimits.y);
|
|
position.z = Mathf.Clamp(position.z, zLimits.x, zLimits.y);
|
|
transform.position = position;
|
|
}
|
|
|
|
transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
|
|
}
|
|
|
|
private void SetWalking(bool walking)
|
|
{
|
|
if (animator != null)
|
|
{
|
|
animator.SetInteger("speed", walking ? 1 : 0);
|
|
}
|
|
}
|
|
} |