Ejemplo n.º 1
0
        private IEnumerator StartLoadAllAsync <T>(string assetBundleName, string assetName, Action <List <T>, object> callback, object customData, bool unloadAutomatically) where T : UnityEngine.Object
        {
            string cacheKey = GetCacheKey <T>(assetBundleName, assetName);

            yield return(PreloadAllAsync <T>(cacheKey, assetBundleName, assetName));

            if (!InCache(cacheKey))
            {
                JSLDebug.LogWarningFormat(LOG_LOADALL_ASSET_FAILED, assetName, assetBundleName);

                callback?.Invoke(null, customData);
                RemoveAsyncLoadingReferencedCounts(cacheKey);

                yield break;
            }

            LoadedResource res = m_loadedResources[cacheKey];

            res.referencedCount++;

            List <T> assets = new List <T>();
            T        cache  = null;

            for (int i = 0; i < res.resources.Length; i++)
            {
                cache = (T)res.resources[i];
                if (cache)
                {
                    assets.Add(cache);
                }
            }

            callback?.Invoke(assets, customData);
            RemoveAsyncLoadingReferencedCounts(cacheKey);

            if (unloadAutomatically)
            {
                Unload <T>(assetBundleName, assetName);
            }
        }