So from the official documentation and unity forum now I know that there's async version of LoadFromFile (that I also will probably call UnityWebRequest.GetAssetBundle
later for updated asset). Now the problem is where can I call it, and how to get the .progress
value, converting from this:
public AssetManager()
{
if (!useAssetBundle) return;
foreach (var bundle_name in bundle_names)
{
var full_path = Path.Combine(Application.streamingAssetsPath + "/Bundle/", bundle_name);
var bundle = AssetBundle.LoadFromFile(full_path);
if (bundle == null) LogHelper.Critical("Failed to load AssetBundle {0}", full_path);
bundles[bundle_name] = bundle;
}
}
To this (that obviously wrong):
private List<AssetBundleCreateRequest> loadPro = new List<AssetBundleCreateRequest>();
private IEnumerator<AssetBundle> _loadOneAssetBundle(string full_path)
{
var creq = AssetBundle.LoadFromFileAsync(full_path);
loadPro.Add(creq);
yield return creq.assetBundle;
}
public AssetManager(MonoBehaviour parent)
{
if (!useAssetBundle) return;
foreach (var bundle_name in bundle_names)
{
var full_path = Path.Combine(Application.streamingAssetsPath + "/Bundle/", bundle_name);
var bundle = parent.StartCoroutine(_loadOneAssetBundle(full_path)).assetBundle; // NOPE T_T)
if (bundle == null) LogHelper.Critical("Failed to load AssetBundle {0}", full_path);
bundles[bundle_name] = bundle; // NOPE 'n')
}
}
public void Update()
{
var progress = 0f;
foreach (var pro in loadPro)
{
progress += pro.progress;
}
LogHelper.Debug("Progress %f",progress);
}