online game working
This commit is contained in:
@@ -5,6 +5,7 @@ using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using MegaKoop.Steam;
|
||||
using MegaKoop.Networking;
|
||||
using MegaKoop.Game.Networking;
|
||||
using TMPro;
|
||||
|
||||
namespace MegaKoop.UI
|
||||
@@ -77,6 +78,7 @@ namespace MegaKoop.UI
|
||||
|
||||
// Steam service
|
||||
private SteamLobbyService steam;
|
||||
private LobbyGameSceneCoordinator lobbyGameCoordinator;
|
||||
|
||||
// Local state cache
|
||||
private bool IsInLobby => steam != null && steam.IsInLobby;
|
||||
@@ -247,6 +249,7 @@ namespace MegaKoop.UI
|
||||
if (steam.IsStartSignaled() && !clientStartedFromSignal)
|
||||
{
|
||||
clientStartedFromSignal = true;
|
||||
lobbyGameCoordinator?.BeginGame(steam);
|
||||
#if UNITY_NETCODE || NETCODE_PRESENT
|
||||
// Configure transport with host SteamID before starting client
|
||||
var adapter = GetSteamAdapter();
|
||||
@@ -327,6 +330,8 @@ namespace MegaKoop.UI
|
||||
#region Steam
|
||||
private void EnsureSteamServices()
|
||||
{
|
||||
GameObject servicesRoot = null;
|
||||
|
||||
if (steam == null)
|
||||
{
|
||||
// Unity 2023+: use FindFirstObjectByType; older: FindObjectOfType
|
||||
@@ -335,14 +340,34 @@ namespace MegaKoop.UI
|
||||
#else
|
||||
steam = Object.FindObjectOfType<SteamLobbyService>();
|
||||
#endif
|
||||
if (steam != null)
|
||||
{
|
||||
servicesRoot = steam.gameObject;
|
||||
}
|
||||
|
||||
if (steam == null)
|
||||
{
|
||||
var go = GameObject.Find("SteamServices") ?? new GameObject("SteamServices");
|
||||
if (go.GetComponent<SteamManager>() == null) go.AddComponent<SteamManager>();
|
||||
steam = go.GetComponent<SteamLobbyService>() ?? go.AddComponent<SteamLobbyService>();
|
||||
DontDestroyOnLoad(go);
|
||||
servicesRoot = GameObject.Find("SteamServices") ?? new GameObject("SteamServices");
|
||||
if (servicesRoot.GetComponent<SteamManager>() == null)
|
||||
{
|
||||
servicesRoot.AddComponent<SteamManager>();
|
||||
}
|
||||
steam = servicesRoot.GetComponent<SteamLobbyService>() ?? servicesRoot.AddComponent<SteamLobbyService>();
|
||||
DontDestroyOnLoad(servicesRoot);
|
||||
}
|
||||
}
|
||||
|
||||
if (steam != null)
|
||||
{
|
||||
servicesRoot ??= steam.gameObject;
|
||||
|
||||
if (servicesRoot.GetComponent<SteamManager>() == null)
|
||||
{
|
||||
servicesRoot.AddComponent<SteamManager>();
|
||||
}
|
||||
|
||||
lobbyGameCoordinator = servicesRoot.GetComponent<LobbyGameSceneCoordinator>() ?? servicesRoot.AddComponent<LobbyGameSceneCoordinator>();
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterSteamEvents()
|
||||
@@ -625,6 +650,7 @@ namespace MegaKoop.UI
|
||||
return;
|
||||
}
|
||||
steam?.StartGameSignal();
|
||||
lobbyGameCoordinator?.BeginGame(steam);
|
||||
#if UNITY_NETCODE || NETCODE_PRESENT
|
||||
// Optionally start host and load scene
|
||||
var adapter = GetSteamAdapter();
|
||||
|
||||
Reference in New Issue
Block a user