Hi, Is it normal for loading from the cache to take almost as long as downloading the assets for the first time?
Also I am seeing strange results when running the same code in a Windows build. Downloading can take a few minutes, and during this time PC freezes (frame rate drops to 1). However, loading from cache is very fast, taking only 0.6 seconds.
When I add *yield return null;*
inside the for loops, the download becomes smooth and only takes 6 seconds, but then loading from cache also takes the same 6 seconds.
Am I doing something wrong? and what can be done to speed-up loading times in Web?
Link to the web build, in case you want to test it yourself:
https://skillwarz.com/webtest/bundles/
Here’s a simplified version of the script I’m using:
private IEnumerator Load()
{
for (int i = 0; i < spriteReferences.Length; i++)
{
int index = i;
LoadAssets<Sprite>(spriteReferences[i], index, 3);
}
for (int i = 0; i < meshReferences.Length; i++)
{
int index = i;
LoadAssets<Mesh>(meshReferences[i], index, 2);
}
for (int i = 0; i < animationReferences.Length; i++)
{
int index = i;
LoadAssets<AnimationClip>(animationReferences[i], index, 1);
}
for (int i = 0; i < materialReferences.Length; i++)
{
int index = i;
LoadAssets<Material>(materialReferences[i], index, 0);
}
while (assetsDownloaded < totalAssets)
{
yield return null;
}
//...
}
private void LoadAssets<T>(AssetReference assetRef, int index, int tips) where T : UnityEngine.Object
{
var handle = assetRef.LoadAssetAsync<T>();
handle.Completed += (h) =>
{
if (h.Status == AsyncOperationStatus.Succeeded)
{
switch(tips)
{
case 0:
materialMap[index] = h.Result as Material;
if (materialMap.Count == materialReferences.Length)
{
}
break;
case 1:
animationMap[index] = h.Result as AnimationClip;
if (animationMap.Count == animationReferences.Length)
{
}
break;
case 2:
meshMap[index] = h.Result as Mesh;
if (meshMap.Count == meshReferences.Length)
{
}
break;
case 3:
spritesMap[index] = h.Result as Sprite;
if (spritesMap.Count == spriteReferences.Length)
{
}
break;
}
}
else
{
Debug.LogError($"Failed to load asset: {assetRef.RuntimeKey} - Status: {h.Status}");
}
};
}