Adding Match State controller
This commit is contained in:
parent
c100db52e5
commit
abcefcd7f1
13 changed files with 445 additions and 99 deletions
|
|
@ -45,7 +45,27 @@ namespace TD.Gameplay
|
|||
return;
|
||||
}
|
||||
|
||||
SpawnBuilderForOwner();
|
||||
var pms = GetComponent<PlayerMatchState>();
|
||||
if (pms == null)
|
||||
{
|
||||
Debug.LogError("[PlayerBuilderSpawner] PlayerMatchState not found on Player Prefab. " +
|
||||
"Add it as a sibling component.");
|
||||
return;
|
||||
}
|
||||
|
||||
// PlayerMatchState.OnNetworkSpawn may have already fired (component order: it first)
|
||||
// or may fire after us (component order: we first). Handle both cases.
|
||||
if (pms.Slot != PlayerSlot.None)
|
||||
SpawnBuilderForOwner(pms.Slot);
|
||||
else
|
||||
pms.SlotReady += OnOwnerSlotReady;
|
||||
}
|
||||
|
||||
private void OnOwnerSlotReady(PlayerSlot slot)
|
||||
{
|
||||
var pms = GetComponent<PlayerMatchState>();
|
||||
if (pms != null) pms.SlotReady -= OnOwnerSlotReady;
|
||||
SpawnBuilderForOwner(slot);
|
||||
}
|
||||
|
||||
public override void OnNetworkDespawn()
|
||||
|
|
@ -58,11 +78,11 @@ namespace TD.Gameplay
|
|||
spawnedBuilder = null;
|
||||
}
|
||||
|
||||
private void SpawnBuilderForOwner()
|
||||
private void SpawnBuilderForOwner(PlayerSlot slot)
|
||||
{
|
||||
// Compute initial position: centroid of this player's zone.
|
||||
// Falls back to origin if loader/zone data isn't available.
|
||||
Vector3 spawnPos = ComputeZoneCentroid(OwnerToSlot(OwnerClientId));
|
||||
Vector3 spawnPos = ComputeZoneCentroid(slot);
|
||||
|
||||
var go = Instantiate(builderPrefab, spawnPos, Quaternion.identity);
|
||||
var netObj = go.GetComponent<NetworkObject>();
|
||||
|
|
@ -94,17 +114,6 @@ namespace TD.Gameplay
|
|||
|
||||
// ----- Helpers ----------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Stub mapping: client 0 = Player1, client 1 = Player2, etc.
|
||||
/// Replaced by MatchState's authoritative assignment when that lands.
|
||||
/// </summary>
|
||||
private static PlayerSlot OwnerToSlot(ulong clientId)
|
||||
{
|
||||
byte slotByte = (byte)(clientId + 1);
|
||||
if (slotByte < 1 || slotByte > 9) return PlayerSlot.None;
|
||||
return (PlayerSlot)slotByte;
|
||||
}
|
||||
|
||||
private static Vector3 ComputeZoneCentroid(PlayerSlot slot)
|
||||
{
|
||||
var loader = LevelLoader.Instance;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue