Jo Jo funguje Kappa
This commit is contained in:
@@ -17,6 +17,8 @@ namespace MegaKoop.Game.Networking
|
||||
[DefaultExecutionOrder(-500)]
|
||||
public class LobbyGameSceneCoordinator : MonoBehaviour
|
||||
{
|
||||
private static LobbyGameSceneCoordinator Instance;
|
||||
|
||||
[SerializeField] private string characterSceneName = "CharacterScene";
|
||||
[SerializeField] private float spawnRadius = 3f;
|
||||
[SerializeField] private float minimumSpawnSpacing = 2.5f;
|
||||
@@ -28,6 +30,14 @@ namespace MegaKoop.Game.Networking
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Singleton to avoid double spawners (e.g., one from DontDestroyOnLoad and one from scene contents)
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
// Another coordinator already exists and persists; remove this duplicate.
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
SceneManager.sceneLoaded += HandleSceneLoaded;
|
||||
}
|
||||
@@ -58,7 +68,12 @@ namespace MegaKoop.Game.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already in the target scene (e.g., during hot reload).
|
||||
// Already in the target scene (e.g., during hot reload). Avoid double-spawn.
|
||||
if (hasSpawned)
|
||||
{
|
||||
Debug.Log("[LobbyGameSceneCoordinator] BeginGame called but players already spawned; ignoring.");
|
||||
return;
|
||||
}
|
||||
loadPending = false;
|
||||
hasSpawned = false;
|
||||
SpawnPlayersInScene(SceneManager.GetActiveScene());
|
||||
@@ -131,11 +146,13 @@ namespace MegaKoop.Game.Networking
|
||||
|
||||
hasSpawned = true;
|
||||
|
||||
// Proactively remove any previously spawned character clones (e.g., from a duplicate coordinator)
|
||||
DespawnExistingClones(scene, template);
|
||||
|
||||
Vector3 basePosition = template.transform.position;
|
||||
Quaternion baseRotation = template.transform.rotation;
|
||||
Transform parent = template.transform.parent;
|
||||
|
||||
// Hide template so only spawned copies are visible.
|
||||
template.SetActive(false);
|
||||
|
||||
int total = Mathf.Max(1, pendingPlayers.Count);
|
||||
@@ -155,6 +172,28 @@ namespace MegaKoop.Game.Networking
|
||||
}
|
||||
}
|
||||
|
||||
private static void DespawnExistingClones(Scene scene, GameObject template)
|
||||
{
|
||||
// Destroy any GameObjects in the scene that look like spawned player avatars, excluding the template hierarchy.
|
||||
foreach (var root in scene.GetRootGameObjects())
|
||||
{
|
||||
// Skip the template root itself
|
||||
if (root == template) continue;
|
||||
|
||||
// Heuristic: if it has a SteamCharacterNetworkBridge or ThirdPersonCharacterController, treat it as a character clone
|
||||
var bridge = root.GetComponentInChildren<SteamCharacterNetworkBridge>(true);
|
||||
var tpc = root.GetComponentInChildren<ThirdPersonCharacterController>(true);
|
||||
if (bridge != null || tpc != null)
|
||||
{
|
||||
// Avoid deleting the template if nested under a different root (shouldn't happen)
|
||||
if (!template.transform.IsChildOf(root.transform) && !root.transform.IsChildOf(template.transform))
|
||||
{
|
||||
UnityEngine.Object.Destroy(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static GameObject FindWizardTemplate(Scene scene)
|
||||
{
|
||||
foreach (var root in scene.GetRootGameObjects())
|
||||
|
||||
Reference in New Issue
Block a user