2020-11-04 09:34:01 +00:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Utility;
|
2021-03-23 13:18:29 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-11-04 09:34:01 +00:00
|
|
|
|
using System;
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB
|
|
|
|
|
{
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public static class QSBSceneManager
|
|
|
|
|
{
|
|
|
|
|
public static OWScene CurrentScene => LoadManager.GetCurrentScene();
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public static bool IsInUniverse => InUniverse(CurrentScene);
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2021-08-08 18:50:47 +00:00
|
|
|
|
public static event Action<OWScene, OWScene, bool> OnSceneLoaded;
|
|
|
|
|
public static event Action<OWScene, OWScene> OnUniverseSceneLoaded;
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
static QSBSceneManager()
|
|
|
|
|
{
|
|
|
|
|
LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad;
|
|
|
|
|
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
|
|
|
|
|
}
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
|
2022-01-18 08:46:27 +00:00
|
|
|
|
QSBWorldSync.RemoveWorldObjects();
|
2021-05-09 07:31:16 +00:00
|
|
|
|
var universe = InUniverse(newScene);
|
|
|
|
|
if (QSBCore.IsInMultiplayer && universe)
|
2021-03-23 13:18:29 +00:00
|
|
|
|
{
|
2021-05-02 07:54:00 +00:00
|
|
|
|
// So objects have time to be deleted, made, whatever
|
2022-01-29 09:29:02 +00:00
|
|
|
|
Delay.RunNextFrame(() => QSBWorldSync.BuildWorldObjects(newScene).Forget());
|
2021-03-23 13:18:29 +00:00
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2021-08-08 18:50:47 +00:00
|
|
|
|
OnSceneLoaded?.SafeInvoke(oldScene, newScene, universe);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
if (universe)
|
|
|
|
|
{
|
2021-08-08 18:50:47 +00:00
|
|
|
|
OnUniverseSceneLoaded?.SafeInvoke(oldScene, newScene);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2021-12-22 12:36:56 +00:00
|
|
|
|
|
|
|
|
|
if (newScene == OWScene.TitleScreen && QSBCore.IsInMultiplayer)
|
|
|
|
|
{
|
2022-01-15 06:25:23 +00:00
|
|
|
|
QSBNetworkManager.singleton.StopHost();
|
2021-12-22 12:36:56 +00:00
|
|
|
|
}
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private static bool InUniverse(OWScene scene) =>
|
2021-11-20 19:49:50 +00:00
|
|
|
|
scene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|