address minigame loading crashes
This commit is contained in:
parent
4b65613f44
commit
df0fe8d52a
|
|
@ -182,7 +182,7 @@ namespace HeavenStudio
|
||||||
{
|
{
|
||||||
string game = Beatmap.Entities[0].datamodel.Split(0);
|
string game = Beatmap.Entities[0].datamodel.Split(0);
|
||||||
SetCurrentGame(game);
|
SetCurrentGame(game);
|
||||||
SetGame(game);
|
StartCoroutine(WaitAndSetGame(game));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -310,7 +310,7 @@ namespace HeavenStudio
|
||||||
{
|
{
|
||||||
string game = Beatmap.Entities[0].datamodel.Split(0);
|
string game = Beatmap.Entities[0].datamodel.Split(0);
|
||||||
SetCurrentGame(game);
|
SetCurrentGame(game);
|
||||||
SetGame(game);
|
StartCoroutine(WaitAndSetGame(game));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -387,8 +387,9 @@ namespace HeavenStudio
|
||||||
return (bp == bLen);
|
return (bp == bLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SeekAheadAndPreload(double start, float seekTime = 8f)
|
public List<Minigames.Minigame> SeekAheadAndPreload(double start, float seekTime = 8f)
|
||||||
{
|
{
|
||||||
|
List<Minigames.Minigame> gamesToPreload = new();
|
||||||
List<RiqEntity> entitiesAtSameBeat = ListPool<RiqEntity>.Get();
|
List<RiqEntity> entitiesAtSameBeat = ListPool<RiqEntity>.Get();
|
||||||
Minigames.Minigame inf;
|
Minigames.Minigame inf;
|
||||||
|
|
||||||
|
|
@ -401,6 +402,7 @@ namespace HeavenStudio
|
||||||
inf = GetGameInfo(gameName);
|
inf = GetGameInfo(gameName);
|
||||||
if (inf != null && inf.usesAssetBundle && !inf.AssetsLoaded)
|
if (inf != null && inf.usesAssetBundle && !inf.AssetsLoaded)
|
||||||
{
|
{
|
||||||
|
gamesToPreload.Add(inf);
|
||||||
Debug.Log($"ASYNC loading assetbundles for game {gameName}");
|
Debug.Log($"ASYNC loading assetbundles for game {gameName}");
|
||||||
inf.LoadAssetsAsync().Forget();
|
inf.LoadAssetsAsync().Forget();
|
||||||
}
|
}
|
||||||
|
|
@ -426,6 +428,7 @@ namespace HeavenStudio
|
||||||
inf = GetGameInfo(gameName);
|
inf = GetGameInfo(gameName);
|
||||||
if (inf != null && inf.usesAssetBundle && !inf.AssetsLoaded)
|
if (inf != null && inf.usesAssetBundle && !inf.AssetsLoaded)
|
||||||
{
|
{
|
||||||
|
gamesToPreload.Add(inf);
|
||||||
Debug.Log($"ASYNC loading assetbundles for game {gameName}");
|
Debug.Log($"ASYNC loading assetbundles for game {gameName}");
|
||||||
inf.LoadAssetsAsync().Forget();
|
inf.LoadAssetsAsync().Forget();
|
||||||
}
|
}
|
||||||
|
|
@ -433,8 +436,8 @@ namespace HeavenStudio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListPool<RiqEntity>.Release(entitiesAtSameBeat);
|
ListPool<RiqEntity>.Release(entitiesAtSameBeat);
|
||||||
|
return gamesToPreload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SeekAheadAndDoPreEvent(double start)
|
public void SeekAheadAndDoPreEvent(double start)
|
||||||
|
|
@ -738,6 +741,17 @@ namespace HeavenStudio
|
||||||
WaitUntil yieldOverlays = new WaitUntil(() => OverlaysManager.OverlaysReady);
|
WaitUntil yieldOverlays = new WaitUntil(() => OverlaysManager.OverlaysReady);
|
||||||
WaitUntil yieldBeatmap = new WaitUntil(() => Beatmap != null && Beatmap.Entities.Count > 0);
|
WaitUntil yieldBeatmap = new WaitUntil(() => Beatmap != null && Beatmap.Entities.Count > 0);
|
||||||
WaitUntil yieldAudio = new WaitUntil(() => AudioLoadDone || (ChartLoadError && !GlobalGameManager.IsShowingDialog));
|
WaitUntil yieldAudio = new WaitUntil(() => AudioLoadDone || (ChartLoadError && !GlobalGameManager.IsShowingDialog));
|
||||||
|
WaitUntil yieldGame = null;
|
||||||
|
List<Minigames.Minigame> gamesToPreload = SeekAheadAndPreload(beat, 4f);
|
||||||
|
if (gamesToPreload.Count > 0)
|
||||||
|
{
|
||||||
|
yieldGame = new WaitUntil(() => gamesToPreload.All(x => x.AssetsLoaded));
|
||||||
|
foreach (var game in gamesToPreload)
|
||||||
|
{
|
||||||
|
Debug.Log($"ASYNC loading assetbundles for game {game.LoadableName}");
|
||||||
|
game.LoadAssetsAsync().Forget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// wait for overlays to be ready
|
// wait for overlays to be ready
|
||||||
yield return yieldOverlays;
|
yield return yieldOverlays;
|
||||||
|
|
@ -745,6 +759,9 @@ namespace HeavenStudio
|
||||||
yield return yieldBeatmap;
|
yield return yieldBeatmap;
|
||||||
//wait for audio clip to be loaded
|
//wait for audio clip to be loaded
|
||||||
yield return yieldAudio;
|
yield return yieldAudio;
|
||||||
|
//wait for games to be loaded
|
||||||
|
if (yieldGame != null)
|
||||||
|
yield return yieldGame;
|
||||||
|
|
||||||
SkillStarManager.instance.KillStar();
|
SkillStarManager.instance.KillStar();
|
||||||
TimingAccuracyDisplay.instance.StopStarFlash();
|
TimingAccuracyDisplay.instance.StopStarFlash();
|
||||||
|
|
@ -1018,6 +1035,18 @@ namespace HeavenStudio
|
||||||
SetCurrentGame(game, useMinigameColor);
|
SetCurrentGame(game, useMinigameColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerator WaitAndSetGame(string game, bool useMinigameColor = true)
|
||||||
|
{
|
||||||
|
var inf = GetGameInfo(game);
|
||||||
|
if (inf != null && inf.usesAssetBundle && !inf.AssetsLoaded)
|
||||||
|
{
|
||||||
|
Debug.Log($"ASYNC loading assetbundles for game {game}");
|
||||||
|
inf.LoadAssetsAsync().Forget();
|
||||||
|
yield return new WaitUntil(() => inf.AssetsLoaded);
|
||||||
|
}
|
||||||
|
SetGame(game, useMinigameColor);
|
||||||
|
}
|
||||||
|
|
||||||
public void PreloadGameSequences(string game)
|
public void PreloadGameSequences(string game)
|
||||||
{
|
{
|
||||||
var gameInfo = GetGameInfo(game);
|
var gameInfo = GetGameInfo(game);
|
||||||
|
|
@ -1047,12 +1076,18 @@ namespace HeavenStudio
|
||||||
if (gameInfo.usesAssetBundle)
|
if (gameInfo.usesAssetBundle)
|
||||||
{
|
{
|
||||||
//game is packed in an assetbundle, load from that instead
|
//game is packed in an assetbundle, load from that instead
|
||||||
if (gameInfo.LoadedPrefab != null) return gameInfo.LoadedPrefab;
|
if (gameInfo.AssetsLoaded && gameInfo.LoadedPrefab != null) return gameInfo.LoadedPrefab;
|
||||||
// StartCoroutine(gameInfo.LoadCommonAudioClipsAsync());
|
|
||||||
// StartCoroutine(gameInfo.LoadLocalizedAudioClipsAsync());
|
try
|
||||||
|
{
|
||||||
return gameInfo.GetCommonAssetBundle().LoadAsset<GameObject>(name);
|
return gameInfo.GetCommonAssetBundle().LoadAsset<GameObject>(name);
|
||||||
}
|
}
|
||||||
name = gameInfo.LoadableName;
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Failed to load assetbundle for game {name}, using sync loading: {e.Message}");
|
||||||
|
return Resources.Load<GameObject>($"Games/{name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Resources.Load<GameObject>($"Games/{name}");
|
return Resources.Load<GameObject>($"Games/{name}");
|
||||||
|
|
|
||||||
|
|
@ -367,6 +367,13 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public AssetBundle GetLocalizedAssetBundle()
|
public AssetBundle GetLocalizedAssetBundle()
|
||||||
{
|
{
|
||||||
|
if (bundleLocalized != null && !localeLoaded)
|
||||||
|
{
|
||||||
|
bundleLocalized.Unload(true);
|
||||||
|
bundleLocalized = null;
|
||||||
|
localeLoaded = false;
|
||||||
|
localePreloaded = false;
|
||||||
|
}
|
||||||
if (!hasLocales) return null;
|
if (!hasLocales) return null;
|
||||||
if (!usesAssetBundle) return null;
|
if (!usesAssetBundle) return null;
|
||||||
if (bundleLocalized == null || currentLoadedLocale != defaultLocale) //TEMPORARY: use the game's default locale until we add localization support
|
if (bundleLocalized == null || currentLoadedLocale != defaultLocale) //TEMPORARY: use the game's default locale until we add localization support
|
||||||
|
|
@ -382,6 +389,13 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public AssetBundle GetCommonAssetBundle()
|
public AssetBundle GetCommonAssetBundle()
|
||||||
{
|
{
|
||||||
|
if (bundleCommon != null && !commonLoaded)
|
||||||
|
{
|
||||||
|
bundleCommon.Unload(true);
|
||||||
|
bundleCommon = null;
|
||||||
|
commonLoaded = false;
|
||||||
|
commonPreloaded = false;
|
||||||
|
}
|
||||||
if (commonLoaded) return bundleCommon;
|
if (commonLoaded) return bundleCommon;
|
||||||
if (!usesAssetBundle) return null;
|
if (!usesAssetBundle) return null;
|
||||||
if (bundleCommon == null)
|
if (bundleCommon == null)
|
||||||
|
|
@ -404,6 +418,14 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public async UniTask LoadCommonAssetBundleAsync()
|
public async UniTask LoadCommonAssetBundleAsync()
|
||||||
{
|
{
|
||||||
|
if (bundleCommon != null && !commonLoaded)
|
||||||
|
{
|
||||||
|
await bundleCommon.UnloadAsync(true);
|
||||||
|
bundleCommon = null;
|
||||||
|
commonLoaded = false;
|
||||||
|
commonPreloaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (commonPreloaded || commonLoaded) return;
|
if (commonPreloaded || commonLoaded) return;
|
||||||
commonPreloaded = true;
|
commonPreloaded = true;
|
||||||
if (!usesAssetBundle) return;
|
if (!usesAssetBundle) return;
|
||||||
|
|
@ -417,6 +439,14 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public async UniTask LoadLocalizedAssetBundleAsync()
|
public async UniTask LoadLocalizedAssetBundleAsync()
|
||||||
{
|
{
|
||||||
|
if (bundleLocalized != null && !localeLoaded)
|
||||||
|
{
|
||||||
|
await bundleLocalized.UnloadAsync(true);
|
||||||
|
bundleLocalized = null;
|
||||||
|
localeLoaded = false;
|
||||||
|
localePreloaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasLocales) return;
|
if (!hasLocales) return;
|
||||||
if (localePreloaded) return;
|
if (localePreloaded) return;
|
||||||
localePreloaded = true;
|
localePreloaded = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue