根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
``` docs(readme): 更新文档说明 - 添加项目使用指南 - 完善API接口说明 - 修正错误的配置示例 ```
This commit is contained in:
1 parent
a74d1e62d7
commit
8d58c2223c
167 files changed
+1119
-15679
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 拆家版出兵管理:从城堡前方出兵点生成单位,消耗能量。
|
||||
/// 替代旧的召唤师身边召唤逻辑。
|
||||
/// </summary>
|
||||
public class CastleSpawnManager : MonoBehaviour
|
||||
{
|
||||
public static CastleSpawnManager Instance { get; private set; }
|
||||
|
||||
[Header("出兵点(城堡前方)")]
|
||||
public Transform blueSpawnPoint;
|
||||
public Transform redSpawnPoint;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this) { Destroy(gameObject); return; }
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
/// <summary>从指定阵营城堡出兵,消耗能量。teamId: 0=蓝, 1=红。</summary>
|
||||
public bool TrySpawn(CharacterData data, int teamId)
|
||||
{
|
||||
if (data == null || data.unitPrefab == null) return false;
|
||||
Transform spawnPoint = teamId == 0 ? blueSpawnPoint : redSpawnPoint;
|
||||
if (spawnPoint == null)
|
||||
{
|
||||
Debug.LogError($"找不到 teamId={teamId} 的出兵点");
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 direction = spawnPoint.forward;
|
||||
direction.y = 0f;
|
||||
if (direction.sqrMagnitude < 0.001f) direction = Vector3.forward;
|
||||
direction.Normalize();
|
||||
|
||||
GameObject unit = Instantiate(
|
||||
data.unitPrefab,
|
||||
spawnPoint.position,
|
||||
Quaternion.LookRotation(direction, Vector3.up));
|
||||
|
||||
// 设置阵营
|
||||
UnitTeam unitTeam = unit.GetComponent<UnitTeam>();
|
||||
if (unitTeam != null)
|
||||
{
|
||||
unitTeam.teamId = teamId;
|
||||
unit.tag = teamId == 0 ? "Friend" : "Enemy";
|
||||
}
|
||||
|
||||
// 初始化属性(默认 1 级)
|
||||
UnitBase unitBase = unit.GetComponent<UnitBase>();
|
||||
if (unitBase != null)
|
||||
{
|
||||
PlayerCharacterData playerData = new PlayerCharacterData("castle_spawn", 1, 0);
|
||||
float hp = playerData.GetMaxHealth(data);
|
||||
float atk = playerData.GetAttackPower(data);
|
||||
float spd = playerData.GetMoveSpeed(data);
|
||||
unitBase.InitializeFromPlayerData(hp, atk, spd);
|
||||
|
||||
// 如果是敌人(teamId != 0),增大寻敌距离
|
||||
if (teamId != 0)
|
||||
{
|
||||
unitBase.detectionRange = 100f; // 从默认30增加到100
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"城堡出兵: {data.characterName} teamId={teamId} pos={spawnPoint.position}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanAfford(CharacterData data)
|
||||
{
|
||||
return data != null && data.unitPrefab != null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user