qsb compat (#478)

This commit is contained in:
Noah Pilarski 2022-12-31 20:07:11 -05:00 committed by GitHub
commit b722297ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -24,6 +24,10 @@ namespace NewHorizons.Builder.Props
private static void SceneManager_sceneUnloaded(Scene scene) private static void SceneManager_sceneUnloaded(Scene scene)
{ {
foreach (var prefab in _fixedPrefabCache.Values)
{
GameObject.Destroy(prefab.prefab);
}
_fixedPrefabCache.Clear(); _fixedPrefabCache.Clear();
_detailInfoToCorrespondingSpawnedGameObject.Clear(); _detailInfoToCorrespondingSpawnedGameObject.Clear();
} }
@ -114,7 +118,8 @@ namespace NewHorizons.Builder.Props
if (detail.path != null) if (detail.path != null)
{ {
_fixedPrefabCache.Add((sector, detail.path), (prop.InstantiateInactive(), isItem)); // We put these in DontDestroyOnLoad so that QSB will ignore them and so they don't clutter up the scene.
_fixedPrefabCache.Add((sector, detail.path), (prop.InstantiateInactive().DontDestroyOnLoad(), isItem));
} }
} }

View File

@ -4,7 +4,6 @@ using NewHorizons.Builder.Body;
using NewHorizons.Builder.General; using NewHorizons.Builder.General;
using NewHorizons.Builder.Props; using NewHorizons.Builder.Props;
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.Components.Orbital;
using NewHorizons.Components.Fixers; using NewHorizons.Components.Fixers;
using NewHorizons.Components.SizeControllers; using NewHorizons.Components.SizeControllers;
using NewHorizons.External; using NewHorizons.External;
@ -29,7 +28,6 @@ using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Components.Stars;
namespace NewHorizons namespace NewHorizons
{ {
@ -76,9 +74,9 @@ namespace NewHorizons
// API events // API events
public class StarSystemEvent : UnityEvent<string> { } public class StarSystemEvent : UnityEvent<string> { }
public StarSystemEvent OnChangeStarSystem; public StarSystemEvent OnChangeStarSystem = new();
public StarSystemEvent OnStarSystemLoaded; public StarSystemEvent OnStarSystemLoaded = new();
public StarSystemEvent OnPlanetLoaded; public StarSystemEvent OnPlanetLoaded = new();
public static bool HasDLC { get => EntitlementsManager.IsDlcOwned() == EntitlementsManager.AsyncOwnershipStatus.Owned; } public static bool HasDLC { get => EntitlementsManager.IsDlcOwned() == EntitlementsManager.AsyncOwnershipStatus.Owned; }
@ -187,10 +185,6 @@ namespace NewHorizons
// Patches // Patches
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
OnChangeStarSystem = new StarSystemEvent();
OnStarSystemLoaded = new StarSystemEvent();
OnPlanetLoaded = new StarSystemEvent();
SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded; SceneManager.sceneUnloaded += OnSceneUnloaded;