feat(gameplay): 添加建筑系统和改进摄像机控制 - 移除人类士兵数据资产文件,重构为建筑放置系统 - 在CharacterData中添加productionInterval和buildingCost字段用于建筑生产 - 实现CameraFollow脚本的完整重写,支持键盘WASD拖动、鼠标拖动、触摸拖动 - 添加摄像机缩放功能,支持上下键和触摸双指缩放 - 更新Projecttile.cs以同时处理单位和建筑目标的伤害检测 - 修改SummonCardButton从法力值召唤改为金币建筑放置模式 - 在UnitBase.cs中更新攻击逻辑以支持对建筑造成伤害 - 升级WorldHealthBar以显示建筑生产进度和更好的缩放补偿 - 修复MainCharacterDebugMovement移除键盘移动输入冲突 - 更新包管理器中的codely.bridge版本从1.0.80到1.0.81 ```
115 lines
3.0 KiB
C#
115 lines
3.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Barracks : MonoBehaviour
|
|
{
|
|
[Header("角色数据")]
|
|
public CharacterData characterData;
|
|
|
|
[Header("阵营")]
|
|
public string unitTag = "Friend";
|
|
|
|
[Header("生产设置")]
|
|
public Transform spawnPoint; // 单位生成位置
|
|
|
|
[Header("UI显示")]
|
|
public Image progressBar; // 生产进度条
|
|
public Image characterIcon; // 角色头像
|
|
|
|
private float spawnTimer = 0f;
|
|
private float spawnInterval = 5f;
|
|
private bool isProducing = true;
|
|
private BuildingHealth buildingHealth;
|
|
|
|
private void Start()
|
|
{
|
|
buildingHealth = GetComponent<BuildingHealth>();
|
|
|
|
if (characterData != null)
|
|
{
|
|
spawnInterval = Mathf.Max(0.1f, characterData.productionInterval);
|
|
|
|
// 设置角色头像
|
|
if (characterIcon != null && characterData.cardIcon != null)
|
|
{
|
|
characterIcon.sprite = characterData.cardIcon;
|
|
}
|
|
|
|
Debug.Log($"兵营初始化:{characterData.characterName},生产间隔{spawnInterval}秒");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("兵营缺少角色数据!");
|
|
}
|
|
|
|
// 如果没有spawnPoint,使用兵营自己的位置
|
|
if (spawnPoint == null)
|
|
{
|
|
spawnPoint = transform;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!isProducing || characterData == null) return;
|
|
|
|
spawnTimer += Time.deltaTime;
|
|
|
|
// 更新进度条
|
|
if (buildingHealth != null)
|
|
{
|
|
buildingHealth.SetProductionProgress(spawnTimer / spawnInterval);
|
|
}
|
|
else if (progressBar != null)
|
|
{
|
|
progressBar.fillAmount = spawnTimer / spawnInterval;
|
|
}
|
|
|
|
// 时间到,生产单位
|
|
if (spawnTimer >= spawnInterval)
|
|
{
|
|
SpawnUnit();
|
|
spawnTimer = 0f;
|
|
}
|
|
}
|
|
|
|
private void SpawnUnit()
|
|
{
|
|
if (characterData == null || characterData.unitPrefab == null)
|
|
{
|
|
Debug.LogError("无法生产单位:缺少unitPrefab");
|
|
return;
|
|
}
|
|
|
|
// 在spawnPoint位置生成单位
|
|
Vector3 spawnPosition = spawnPoint.position;
|
|
|
|
GameObject unit = Instantiate(characterData.unitPrefab, spawnPosition, Quaternion.identity);
|
|
unit.name = characterData.characterName;
|
|
unit.tag = unitTag;
|
|
|
|
// 如果单位有UnitBase组件,使用1级属性初始化
|
|
var unitBase = unit.GetComponent<UnitBase>();
|
|
if (unitBase != null)
|
|
{
|
|
float health = characterData.GetMaxHealth(1);
|
|
float attack = characterData.GetAttackPower(1);
|
|
float moveSpeed = characterData.GetMoveSpeed(1);
|
|
|
|
unitBase.InitializeFromPlayerData(health, attack, moveSpeed);
|
|
}
|
|
|
|
Debug.Log($"兵营生产了单位:{characterData.characterName}");
|
|
}
|
|
|
|
public void StopProduction()
|
|
{
|
|
isProducing = false;
|
|
}
|
|
|
|
public void StartProduction()
|
|
{
|
|
isProducing = true;
|
|
}
|
|
}
|