(hopefullyt) fix asset loading issue

This commit is contained in:
minenice55 2024-04-08 19:52:10 -04:00
parent 10e9a5e35d
commit 64cbe48863
4 changed files with 42 additions and 20 deletions

View file

@ -171,7 +171,7 @@ namespace HeavenStudio
songPosBeat = GetBeatFromSongPos(time);
gameManager.SetCurrentEventToClosest(beat);
gameManager.SetCurrentEventToClosest(beat, true);
}
public void PlaySetup(double beat)

View file

@ -118,24 +118,22 @@ namespace HeavenStudio
public static List<RiqEntity> GetAllInGameManagerList(string gameName, string[] include)
{
List<RiqEntity> temp1 = instance.gameManager.Beatmap.Entities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
List<RiqEntity> temp2 = new List<RiqEntity>();
foreach (string s in include)
Predicate<RiqEntity> match = c =>
{
temp2.AddRange(temp1.FindAll(c => c.datamodel.Split('/')[1].Equals(s)));
}
return temp2;
string[] details = c.datamodel.Split('/');
return details[0] == gameName && include.Contains(details[1]);
};
return instance.gameManager.Beatmap.Entities.FindAll(match);
}
public static List<RiqEntity> GetAllInGameManagerListExclude(string gameName, string[] exclude)
{
List<RiqEntity> temp1 = instance.gameManager.Beatmap.Entities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
List<RiqEntity> temp2 = new List<RiqEntity>();
foreach (string s in exclude)
Predicate<RiqEntity> match = c =>
{
temp2.AddRange(temp1.FindAll(c => !c.datamodel.Split('/')[1].Equals(s)));
}
return temp2;
string[] details = c.datamodel.Split('/');
return details[0] == gameName && !exclude.Contains(details[1]);
};
return instance.gameManager.Beatmap.Entities.FindAll(match);
}
public static List<Minigames.Minigame> FXOnlyGames()

View file

@ -22,7 +22,6 @@ namespace HeavenStudio
[Header("Lists")]
[NonSerialized] public RiqBeatmap Beatmap = new();
private Dictionary<string, GameObject> cachedGamePrefabs = new();
[NonSerialized] public ObjectPool<Sound> SoundObjects;
[Header("Components")]
@ -1124,7 +1123,7 @@ namespace HeavenStudio
}
}
while (beat + 0.25 > Math.Max(conductor.songPositionInBeatsAsDouble, 0))
while (conductor.GetUnSwungBeat(beat + 0.25) > Math.Max(conductor.unswungSongPositionInBeatsAsDouble, 0))
{
if (!conductor.isPlaying)
{
@ -1165,13 +1164,18 @@ namespace HeavenStudio
public void DestroyGame()
{
cachedGamePrefabs.Clear();
SoundByte.UnloadAudioClips();
SetGame("noGame");
}
string currentGameRequest = null;
private IEnumerator WaitAndSetGame(string game, bool useMinigameColor = true)
{
if (game == currentGameRequest)
{
yield break;
}
currentGameRequest = game;
var inf = GetGameInfo(game);
if (inf != null && inf.usesAssetBundle)
{
@ -1179,13 +1183,15 @@ namespace HeavenStudio
{
// Debug.Log($"ASYNC loading assetbundles for game {game}");
inf.LoadAssetsAsync().Forget();
yield return new WaitUntil(() => inf.AssetsLoaded);
}
yield return new WaitUntil(() => inf.AssetsLoaded);
SetGame(game, useMinigameColor);
currentGameRequest = null;
}
else
{
SetGame(game, useMinigameColor);
currentGameRequest = null;
}
}
@ -1200,10 +1206,14 @@ namespace HeavenStudio
public GameObject GetGame(string name)
{
var gameInfo = GetGameInfo(name);
if (name is null or "" or "noGame")
{
return Resources.Load<GameObject>($"Games/noGame");
}
Minigames.Minigame gameInfo = GetGameInfo(name);
if (gameInfo != null)
{
GameObject prefab;
if (gameInfo.inferred)
{
return Resources.Load<GameObject>($"Games/noGame");
@ -1226,6 +1236,8 @@ namespace HeavenStudio
return Resources.Load<GameObject>($"Games/noGame");
}
}
GameObject prefab;
if (gameInfo.usesAssetBundle)
{
//game is packed in an assetbundle, load from that instead
@ -1234,6 +1246,11 @@ namespace HeavenStudio
try
{
Debug.LogWarning($"Game prefab wasn't cached, loading from assetbundle for game {name}");
if (gameInfo.LoadingPrefab)
{
Debug.LogWarning($"Game {name} is already loading, using noGame");
return Resources.Load<GameObject>($"Games/noGame");
}
return gameInfo.LoadGamePrefab();
}
catch (Exception e)
@ -1251,6 +1268,7 @@ namespace HeavenStudio
}
}
}
// games with no assetbundle (usually indev games)
prefab = Resources.Load<GameObject>($"Games/{name}");
if (prefab != null)
{

View file

@ -395,8 +395,10 @@ namespace HeavenStudio
public bool usesAssetBundle => wantAssetBundle is not null or "";
public bool hasLocales => supportedLocales.Count > 0;
public bool AssetsLoaded => ((hasLocales && localeLoaded && currentLoadedLocale == defaultLocale) || (!hasLocales)) && commonLoaded && loadComplete;
public bool AssetsLoaded => ((hasLocales && localeLoaded && currentLoadedLocale == defaultLocale) || (!hasLocales)) && commonLoaded && (!loadingPrefab) && loadComplete;
public bool AlreadyLoading => alreadyLoading;
public bool LoadingPrefab => loadingPrefab;
public bool SequencesPreloaded => soundSequences != null;
public string LoadableName => inferred ? "noGame" : name;
public GameObject LoadedPrefab => loadedPrefab;
@ -410,6 +412,7 @@ namespace HeavenStudio
private bool localePreloaded = false;
private GameObject loadedPrefab = null;
bool loadingPrefab = false;
bool loadComplete = false;
private SoundSequence.SequenceKeyValue[] soundSequences = null;
@ -510,6 +513,7 @@ namespace HeavenStudio
if (alreadyLoading || AssetsLoaded || !usesAssetBundle) return;
loadComplete = false;
alreadyLoading = true;
loadingPrefab = true;
await UniTask.WhenAll(LoadCommonAssetBundleAsync(), LoadLocalizedAssetBundleAsync());
await UniTask.WhenAll(LoadGamePrefabAsync(), LoadCommonAudioClips(), LoadLocalizedAudioClips());
SoundByte.PreloadGameAudioClips(this);
@ -585,6 +589,7 @@ namespace HeavenStudio
soundSequences = minigame.SoundSequences;
}
loadedPrefab = prefab;
loadingPrefab = false;
}
public GameObject LoadGamePrefab()
@ -636,6 +641,7 @@ namespace HeavenStudio
}
SoundByte.UnloadAudioClips(name);
loadComplete = false;
loadingPrefab = false;
}
}