mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
wait until preload bundles are loaded before loading scene
This commit is contained in:
parent
2bd8863c91
commit
e73afbebc7
@ -1,4 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using NewHorizons.Utility.Files;
|
||||
using NewHorizons.Utility.OWML;
|
||||
|
||||
namespace NewHorizons.Patches.EyeScenePatches
|
||||
@ -6,10 +7,18 @@ namespace NewHorizons.Patches.EyeScenePatches
|
||||
[HarmonyPatch(typeof(SubmitActionLoadScene))]
|
||||
public static class SubmitActionLoadScenePatches
|
||||
{
|
||||
// To call the base method
|
||||
[HarmonyReversePatch]
|
||||
[HarmonyPatch(typeof(SubmitActionConfirm), nameof(SubmitActionConfirm.ConfirmSubmit))]
|
||||
public static void SubmitActionConfirm_ConfirmSubmit(SubmitActionConfirm instance) { }
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SubmitActionLoadScene.ConfirmSubmit))]
|
||||
public static void SubmitActionLoadScene_ConfirmSubmit(SubmitActionLoadScene __instance)
|
||||
public static bool SubmitActionLoadScene_ConfirmSubmit(SubmitActionLoadScene __instance)
|
||||
{
|
||||
if (__instance._receivedSubmitAction) return false;
|
||||
|
||||
// Title screen can warp you to eye and cause problems.
|
||||
if (__instance._sceneToLoad == SubmitActionLoadScene.LoadableScenes.EYE)
|
||||
{
|
||||
@ -17,6 +26,44 @@ namespace NewHorizons.Patches.EyeScenePatches
|
||||
Main.Instance.IsWarpingBackToEye = true;
|
||||
__instance._sceneToLoad = SubmitActionLoadScene.LoadableScenes.GAME;
|
||||
}
|
||||
|
||||
// modified from patched function
|
||||
SubmitActionConfirm_ConfirmSubmit(__instance);
|
||||
__instance._receivedSubmitAction = true;
|
||||
Locator.GetMenuInputModule().DisableInputs();
|
||||
|
||||
Delay.RunWhen(() =>
|
||||
{
|
||||
// update text. just use 0%
|
||||
__instance.ResetStringBuilder();
|
||||
__instance._nowLoadingSB.Append(UITextLibrary.GetString(UITextType.LoadingMessage));
|
||||
__instance._nowLoadingSB.Append(0.ToString("P0"));
|
||||
__instance._loadingText.text = __instance._nowLoadingSB.ToString();
|
||||
|
||||
return AssetBundleUtilities.AreRequiredAssetsLoaded();
|
||||
}, () =>
|
||||
{
|
||||
switch (__instance._sceneToLoad)
|
||||
{
|
||||
case SubmitActionLoadScene.LoadableScenes.GAME:
|
||||
LoadManager.LoadSceneAsync(OWScene.SolarSystem, false, LoadManager.FadeType.ToBlack, 1f, false);
|
||||
__instance.ResetStringBuilder();
|
||||
__instance._waitingOnStreaming = true;
|
||||
break;
|
||||
case SubmitActionLoadScene.LoadableScenes.EYE:
|
||||
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToBlack, 1f, false);
|
||||
__instance.ResetStringBuilder();
|
||||
break;
|
||||
case SubmitActionLoadScene.LoadableScenes.TITLE:
|
||||
LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f, true);
|
||||
break;
|
||||
case SubmitActionLoadScene.LoadableScenes.CREDITS:
|
||||
LoadManager.LoadScene(OWScene.Credits_Fast, LoadManager.FadeType.ToBlack, 1f, false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,9 @@ namespace NewHorizons.Utility.Files
|
||||
{
|
||||
public static class AssetBundleUtilities
|
||||
{
|
||||
public static Dictionary<string, (AssetBundle bundle, bool keepLoaded)> AssetBundles = new Dictionary<string, (AssetBundle, bool)>();
|
||||
public static Dictionary<string, (AssetBundle bundle, bool keepLoaded)> AssetBundles = new();
|
||||
|
||||
private static readonly List<AssetBundleCreateRequest> _loadingBundles = new();
|
||||
|
||||
public static void ClearCache()
|
||||
{
|
||||
@ -37,13 +39,21 @@ namespace NewHorizons.Utility.Files
|
||||
string key = Path.GetFileName(assetBundleRelativeDir);
|
||||
var completePath = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, assetBundleRelativeDir);
|
||||
var request = AssetBundle.LoadFromFileAsync(completePath);
|
||||
_loadingBundles.Add(request);
|
||||
NHLogger.Log($"Preloading bundle {assetBundleRelativeDir} - {_loadingBundles.Count} left");
|
||||
request.completed += _ =>
|
||||
{
|
||||
NHLogger.Log($"Finished loading async bundle {assetBundleRelativeDir}");
|
||||
_loadingBundles.Remove(request);
|
||||
NHLogger.Log($"Finshed preloading bundle {assetBundleRelativeDir} - {_loadingBundles.Count} left");
|
||||
AssetBundles[key] = (request.assetBundle, true);
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// are preloaded bundles done loading?
|
||||
/// </summary>
|
||||
public static bool AreRequiredAssetsLoaded() => _loadingBundles.Count == 0;
|
||||
|
||||
public static T Load<T>(string assetBundleRelativeDir, string pathInBundle, IModBehaviour mod) where T : UnityEngine.Object
|
||||
{
|
||||
string key = Path.GetFileName(assetBundleRelativeDir);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user