2022-05-03 23:01:28 -07:00
|
|
|
|
using OWML.Common;
|
2020-11-04 09:34:01 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using System;
|
2020-08-16 22:39:21 +02:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB;
|
|
|
|
|
|
|
|
|
|
public static class QSBSceneManager
|
2020-08-16 22:39:21 +02:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public static OWScene CurrentScene => LoadManager.GetCurrentScene();
|
|
|
|
|
|
2022-05-03 21:41:05 -07:00
|
|
|
|
public static bool IsInUniverse => CurrentScene.IsUniverseScene();
|
2020-08-16 22:39:21 +02:00
|
|
|
|
|
2022-05-03 22:04:27 -07:00
|
|
|
|
[Obsolete("TODO: remove after migration")]
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public static event Action<OWScene, OWScene, bool> OnSceneLoaded;
|
2022-05-03 22:04:27 -07:00
|
|
|
|
[Obsolete("TODO: remove after migration")]
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public static event Action<OWScene, OWScene> OnUniverseSceneLoaded;
|
2020-08-16 22:39:21 +02:00
|
|
|
|
|
2022-05-03 21:20:59 -07:00
|
|
|
|
/// <summary>
|
2022-05-03 22:55:09 -07:00
|
|
|
|
/// runs before the scene is changed.
|
|
|
|
|
/// happens before OnDestroy.
|
2022-05-03 21:20:59 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static event LoadManager.SceneLoadEvent OnPreSceneLoad;
|
|
|
|
|
/// <summary>
|
2022-05-03 22:55:09 -07:00
|
|
|
|
/// runs after the scene is changed.
|
|
|
|
|
/// happens after Awake, but before Start.
|
2022-05-03 21:20:59 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static event LoadManager.SceneLoadEvent OnPostSceneLoad;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
static QSBSceneManager()
|
|
|
|
|
{
|
2022-05-03 21:20:59 -07:00
|
|
|
|
LoadManager.OnStartSceneLoad += (originalScene, loadScene) =>
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"PRE SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
|
|
|
|
|
OnPreSceneLoad?.SafeInvoke(originalScene, loadScene);
|
|
|
|
|
};
|
|
|
|
|
LoadManager.OnCompleteSceneLoad += (originalScene, loadScene) =>
|
2022-05-03 22:55:09 -07:00
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"POST SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
|
|
|
|
|
OnPostSceneLoad?.SafeInvoke(originalScene, loadScene);
|
2022-05-03 22:56:23 -07:00
|
|
|
|
|
|
|
|
|
OnCompleteSceneLoad(originalScene, loadScene);
|
2022-05-03 22:55:09 -07:00
|
|
|
|
};
|
2020-08-16 22:39:21 +02:00
|
|
|
|
|
2022-05-03 21:41:05 -07:00
|
|
|
|
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
2022-05-03 22:04:27 -07:00
|
|
|
|
[Obsolete("TODO: remove after migration")]
|
|
|
|
|
private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
|
|
|
|
|
{
|
|
|
|
|
var universe = newScene.IsUniverseScene();
|
|
|
|
|
|
|
|
|
|
OnSceneLoaded?.SafeInvoke(oldScene, newScene, universe);
|
|
|
|
|
if (universe)
|
|
|
|
|
{
|
|
|
|
|
OnUniverseSceneLoaded?.SafeInvoke(oldScene, newScene);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 21:41:05 -07:00
|
|
|
|
public static bool IsUniverseScene(this OWScene scene) =>
|
2022-03-02 19:46:33 -08:00
|
|
|
|
scene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse;
|
2022-05-03 21:20:59 -07:00
|
|
|
|
}
|