Merge branch 'main' of https://scoveria.ddns.net/scove/BABA_YAGA
This commit is contained in:
@@ -53,6 +53,46 @@ namespace Hallucinate.UI
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
// Auto-connect if we bypass the UI and start directly in the Main Scene
|
||||
if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Main Scene")
|
||||
{
|
||||
Debug.Log("[BasicSpawner] Auto-starting Fusion in AutoHostOrClient mode for testing...");
|
||||
|
||||
if (_isStarting) return;
|
||||
_isStarting = true;
|
||||
|
||||
try
|
||||
{
|
||||
await EnsureRunnerExists();
|
||||
var sceneManager = gameObject.GetComponent<NetworkSceneManagerDefault>();
|
||||
if (sceneManager == null) sceneManager = gameObject.AddComponent<NetworkSceneManagerDefault>();
|
||||
|
||||
var result = await _runner.StartGame(new StartGameArgs()
|
||||
{
|
||||
GameMode = GameMode.Shared,
|
||||
SessionName = "QuickTestRoom", // Hardcoded session for instant testing
|
||||
SceneManager = sceneManager,
|
||||
Scene = SceneRef.FromIndex(UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex)
|
||||
});
|
||||
|
||||
if (result.Ok)
|
||||
{
|
||||
Debug.Log("[BasicSpawner] Auto Connect SUCCESS!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[BasicSpawner] Auto Connect FAILED: {result.ShutdownReason}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isStarting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerProfile LocalPlayerProfile { get; private set; }
|
||||
public void SetLocalPlayerProfile(PlayerProfile _profile)
|
||||
{
|
||||
@@ -91,8 +131,13 @@ namespace Hallucinate.UI
|
||||
|
||||
if (this == null) return; // BasicSpawner itself might be destroyed
|
||||
|
||||
Debug.Log("[BasicSpawner] Creating new NetworkRunner component.");
|
||||
_runner = gameObject.AddComponent<NetworkRunner>();
|
||||
_runner = gameObject.GetComponent<NetworkRunner>();
|
||||
if (_runner == null)
|
||||
{
|
||||
Debug.Log("[BasicSpawner] Creating new NetworkRunner component.");
|
||||
_runner = gameObject.AddComponent<NetworkRunner>();
|
||||
}
|
||||
|
||||
_runner.ProvideInput = true;
|
||||
_runner.AddCallbacks(this);
|
||||
}
|
||||
@@ -244,9 +289,13 @@ namespace Hallucinate.UI
|
||||
|
||||
public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
|
||||
{
|
||||
Debug.Log($"[BasicSpawner] PlayerJoined: {player.PlayerId}");
|
||||
|
||||
// In Shared Mode, there is no Server. Each client is responsible for spawning their own player.
|
||||
if (player == runner.LocalPlayer)
|
||||
{
|
||||
SendLocalMetaData(player);
|
||||
SpawnPlayer(runner, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,19 +454,43 @@ namespace Hallucinate.UI
|
||||
{
|
||||
foreach (var player in runner.ActivePlayers)
|
||||
{
|
||||
Vector2 spawnPosition = (player == runner.LocalPlayer) ? new Vector2(-8, 0) : new Vector2(8, 0);
|
||||
var networkPlayerObject = runner.Spawn(_playerPrefab, spawnPosition, Quaternion.identity, player);
|
||||
// Give the client State Authority so they can move themselves
|
||||
// networkPlayerObject.AssignStateAuthority(player);
|
||||
_spawnedCharacters.Add(player, networkPlayerObject);
|
||||
if (!_spawnedCharacters.ContainsKey(player))
|
||||
{
|
||||
SpawnPlayer(runner, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*if (currentSceneName == "Main Scene")
|
||||
{
|
||||
UIManager.Instance?.OnGameStarted();
|
||||
/
|
||||
BNM098TYU78I98IU7Y6T57U8I9I8U7Y6T57U8I7Y6T5Y67U8IU7Y6T57U8IU7Y6E4XDER45ESZXSDCER45EDSXZSDCEFR45TTRFGHJUIYTRW
|
||||
}*/
|
||||
}
|
||||
|
||||
private void SpawnPlayer(NetworkRunner runner, PlayerRef player)
|
||||
{
|
||||
Debug.Log($"[BasicSpawner] Spawning Player {player.PlayerId} at {Time.time}");
|
||||
Vector3 spawnPosition = (player == runner.LocalPlayer) ? new Vector3(-8, 2, 0) : new Vector3(8, 2, 0);
|
||||
var networkPlayerObject = runner.Spawn(_playerPrefab, spawnPosition, Quaternion.identity, player);
|
||||
|
||||
// In Shared Mode, runner.Spawn automatically grants State Authority to the caller.
|
||||
// We just need to assign Input Authority.
|
||||
networkPlayerObject.AssignInputAuthority(player);
|
||||
|
||||
_spawnedCharacters[player] = networkPlayerObject;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (_runner != null && _runner.IsRunning)
|
||||
{
|
||||
GUI.color = Color.green;
|
||||
GUI.Label(new Rect(10, 10, 300, 30), $"[Network] Session: {_runner.SessionInfo?.Name}");
|
||||
GUI.Label(new Rect(10, 30, 300, 30), $"[Network] Players in Room: {_runner.ActivePlayers.Count()}");
|
||||
GUI.Label(new Rect(10, 50, 300, 30), $"[Network] Am I Server?: {_runner.IsServer}");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSceneLoadStart(NetworkRunner runner) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user