1.1.0 未驗證
This commit is contained in:
1 parent
2638c5929d
commit
4a72bd132a
31 files changed
+790
-123
No files matched your search
@@ -3,6 +3,9 @@ using UnityEngine;
|
||||
|
||||
// 一次只有一隻機器人,倒下後在隨機位置重生下一隻
|
||||
// 掛在場景裡的空物件上,物件的位置就是生成範圍的中心
|
||||
// 每生成一隻就是新的一回合 : 先取出這回合的條件 (SessionPlan) 套到輔助、感知器、武器,再通知記錄器
|
||||
// 執行順序 50 : 第一隻在 Start() 生成,要排在其他腳本的 Start() 之後
|
||||
[DefaultExecutionOrder(50)]
|
||||
public class BotSpawner : MonoBehaviour
|
||||
{
|
||||
[Header("參照")]
|
||||
@@ -26,11 +29,22 @@ public class BotSpawner : MonoBehaviour
|
||||
// 目前活著的機器人,倒下到重生之間是 null (給方位指示等 UI 用)
|
||||
public BotHealth CurrentBot { get; private set; }
|
||||
|
||||
// 這一回合的條件 (記錄器寫進 config 用)
|
||||
public SessionPlan.RoundCondition CurrentCondition { get; private set; }
|
||||
|
||||
// 新的一隻生成時通知 (記錄器用來開始一回合)
|
||||
public event System.Action<BotHealth> BotSpawned;
|
||||
|
||||
private GameSettings settings;
|
||||
private AimAssist aimAssist;
|
||||
private EnemyPerceptor perceptor;
|
||||
private PlayerLook playerLook;
|
||||
private WeaponLoadout loadout;
|
||||
|
||||
void Start()
|
||||
{
|
||||
settings = GameSettings.Load();
|
||||
|
||||
// 拖進來的是 prefab 檔案本身 (不在場景裡) 或沒拖 : 改用場景裡的玩家 (只有玩家身上有 PlayerLook)
|
||||
if (player == null || !player.gameObject.scene.IsValid())
|
||||
{
|
||||
@@ -38,6 +52,19 @@ public class BotSpawner : MonoBehaviour
|
||||
player = look != null ? look.transform.root : null;
|
||||
}
|
||||
|
||||
// 每回合要套條件的腳本 (player 可能只是 PlayerRig 底下的子物件,所以從整個場景找)
|
||||
aimAssist = FindAnyObjectByType<AimAssist>();
|
||||
perceptor = FindAnyObjectByType<EnemyPerceptor>();
|
||||
playerLook = FindAnyObjectByType<PlayerLook>();
|
||||
loadout = FindAnyObjectByType<WeaponLoadout>();
|
||||
|
||||
// 條件套不上去,config 的標籤就會跟實際不符,所以寧可不生成
|
||||
if (aimAssist == null || perceptor == null || playerLook == null || loadout == null)
|
||||
{
|
||||
Debug.LogError("BotSpawner : 場景裡缺少 AimAssist / EnemyPerceptor / PlayerLook / WeaponLoadout,無法套用回合條件");
|
||||
return;
|
||||
}
|
||||
|
||||
Spawn();
|
||||
}
|
||||
|
||||
@@ -53,11 +80,24 @@ public class BotSpawner : MonoBehaviour
|
||||
{
|
||||
if (botPrefab == null) return;
|
||||
|
||||
// 自動配置做完全部回合就不再生成 (RoundProgressHUD 會提示關閉遊戲)
|
||||
if (!SessionPlan.TryGetCurrent(settings, out SessionPlan.RoundCondition c)) return;
|
||||
CurrentCondition = c;
|
||||
|
||||
// 這一回合的種子 : 生成點與機器人動作都用全域亂數
|
||||
Random.InitState(c.roundSeed);
|
||||
|
||||
BotBrain bot = Instantiate(botPrefab, PickSpawnPoint(), Quaternion.identity);
|
||||
bot.target = player;
|
||||
bot.areaCenter = transform.position;
|
||||
bot.areaRadius = spawnRadius;
|
||||
|
||||
// 套用條件並清掉上一回合的殘留,要在通知記錄器之前
|
||||
aimAssist.Apply(c);
|
||||
perceptor.Apply(c);
|
||||
playerLook.ClearAssistDelta();
|
||||
loadout.SetRecoilSeed(c.roundSeed);
|
||||
|
||||
if (bot.TryGetComponent(out BotHealth health))
|
||||
{
|
||||
health.Died += OnBotDied;
|
||||
|
||||
Reference in new issue
Block a user