Skip to content

Commit

Permalink
fix: fixing OnlineOfflineScene to work with NetworkSceneManager
Browse files Browse the repository at this point in the history
BREAKING CHANGE: OnlineOfflineScene uses NetworkSceneManager instead of just loading locally using client start
  • Loading branch information
James-Frowen committed Apr 11, 2022
1 parent fd9e895 commit bb916f3
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions Assets/Mirage/Components/OnlineOfflineScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class OnlineOfflineScene : MonoBehaviour
{
static readonly ILogger logger = LogFactory.GetLogger(typeof(OnlineOfflineScene));

[FormerlySerializedAs("client")]
public NetworkClient Client;
[FormerlySerializedAs("server")]
public NetworkServer Server;

public NetworkSceneManager NetworkSceneManager;

[Scene]
[Tooltip("Assign the OnlineScene to load for this zone")]
public string OnlineScene;
Expand All @@ -31,37 +31,22 @@ void Start()
if (string.IsNullOrEmpty(OfflineScene))
throw new MissingReferenceException("OfflineScene missing. Please assign to OnlineOfflineScene component.");

if (Client != null)
{
Client.Started.AddListener(OnClientStarted);
Client.Disconnected.AddListener(OnClientDisconnected);
}
if (Server != null)
{
Server.Started.AddListener(OnServerStarted);
Server.Stopped.AddListener(OnServerStopped);
}
}

void OnClientStarted()
{
// set not ready and wait for server to send scene message
Client.Player.SceneIsReady = false;
}

void OnClientDisconnected(ClientStoppedReason reason)
{
SceneManager.LoadSceneAsync(OfflineScene);
}

void OnServerStarted()
{
SceneManager.LoadSceneAsync(OnlineScene);
NetworkSceneManager.ServerLoadSceneNormal(OnlineScene);
}

void OnServerStopped()
{
SceneManager.LoadSceneAsync(OfflineScene);
Debug.Log("OnlineOfflineScene.OnServerStopped");
NetworkSceneManager.ServerLoadSceneNormal(OfflineScene);
}
}
}

0 comments on commit bb916f3

Please sign in to comment.