Beispiel #1
0
    private IEnumerator Load(Action <string, float> loadProgress = null)
    {
        yield return(new WaitForEndOfFrame());

        for (int i = 0; i < AllABPath.Count; i++)
        {
            int index = i;
            //根据依赖包名称进行加载
            UnityWebRequester requester = new UnityWebRequester(App.app);
            requester.GetAssetBundle($"{mainfestPath}/{AllABPath[index]}", (AssetBundle ab) =>
            {
                if (!AssetBundlesCache.ContainsKey(AllABPath[index]))
                {
                    //注意添加进缓存 防止重复加载AB包
                    AssetBundlesCache.Add(AllABPath[index], ab);
                }
            });
            while (!requester.IsDown)
            {
                float progress = requester.DownloadedProgress;
                loadProgress?.Invoke(AllABPath[index], progress);
            }
            yield return(new WaitForEndOfFrame());

            loadProgress?.Invoke(AllABPath[index], 1);
        }
    }
Beispiel #2
0
 public void LoadAssetBundle(Action <string, float> loadProgress = null)
 {
     if (assetbundle == null)
     {
         UnityWebRequester requester = new UnityWebRequester(App.app);
         requester.GetAssetBundle($"{mainfestPath}/{PlatformManager.Instance.Name}", (AssetBundle ab) =>
         {
             assetbundle = ab;
             manifest    = assetbundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
             GetAssetBundlePath(loadProgress);
             requester.Destory();
         });
         return;
     }
     GetAssetBundlePath(loadProgress);
 }