根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口说明 - 修正错误的配置示例 ``` 注意:由于您提供的code differences部分为空,以上是一个示例模板。当您有具体的代码变更时,请提供详细的变更内容以便生成更准确的commit message。
This commit is contained in:
1 parent
8d58c2223c
commit
11f1af357d
191 files changed
+2315
-1539
No files matched your search
@@ -0,0 +1,127 @@
|
||||
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 = 5f;
|
||||
|
||||
// 设置角色头像
|
||||
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;
|
||||
|
||||
// 设置阵营 ID(根据建筑的阵营)
|
||||
var buildingTeam = GetComponent<UnitTeam>();
|
||||
var unitTeam = unit.GetComponent<UnitTeam>();
|
||||
if (buildingTeam != null && unitTeam != null)
|
||||
{
|
||||
unitTeam.teamId = buildingTeam.teamId;
|
||||
}
|
||||
else if (unitTeam != null)
|
||||
{
|
||||
// 兜底:根据 tag 判断阵营
|
||||
unitTeam.teamId = unitTag == "Friend" ? 0 : 1;
|
||||
}
|
||||
|
||||
// 如果单位有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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user