示例#1
0
 private static void UpdateBundleLoading()
 {
     for (int i = 0; i < AssetManager.AsyncBundles.Count; i++)
     {
         AssetManager.Bundle bundle = AssetManager.AsyncBundles[i];
         if (bundle.WWW != null && bundle.WWW.isDone)
         {
             if (bundle.WWW.error != null && bundle.WWW.error.Length > 0)
             {
                 GameLog.ErrorT(AssetManager.TAG, "Asset bundle load failed: {0} {1}!", new object[] {
                     bundle.Name,
                     bundle.WWW.error
                 });
                 bundle.State = AssetManager.State.Failed;
             }
             else
             {
                 bundle.AssetBundle = bundle.WWW.assetBundle;
                 bundle.WWW         = null;
                 bundle.State       = AssetManager.State.Loaded;
                 bundle.OnLoaded();
             }
             AssetManager.AsyncBundles.RemoveAt(i--);
         }
     }
 }
示例#2
0
 private static AssetManager.Asset LoadAsset(AssetManager.Bundle bundle, string name, Type type, AssetManager.OnAssetLoaded assetLoaded, AssetManager.LoadAssetDelegate OnLoadAsset)
 {
     AssetManager.Asset asset = AssetManager.FindAsset(name);
     if (asset != null)
     {
         if (asset.State == AssetManager.State.Loaded)  //已经正确加载,重定向回调
         {
             asset.ClearEvents();
             asset.AssetLoaded += assetLoaded;
             asset.OnLoaded();
             return(asset);
         }
         AssetManager.StopLoadAsyncAsset(asset);
     }
     else
     {
         asset = new AssetManager.Asset();
         AssetManager.Assets.Add(name, asset);
     }
     asset.Name   = name;
     asset.Type   = type;
     asset.Bundle = bundle;
     asset.ClearEvents();   //如果先请求loadAsset,然后才loadBundle,不管前面的无效请求,只管loadBundle之后的loadAsset
     asset.AssetLoaded += assetLoaded;
     return(OnLoadAsset(asset));
 }
示例#3
0
 public static void UnloadBundle(AssetManager.Bundle bundle, bool unloadAllLoadedObjects)
 {
     bundle.AssetBundle.Unload(unloadAllLoadedObjects);
     bundle.AssetBundle = null;
     bundle.State       = AssetManager.State.Invalid;
     AssetManager.Bundles.Remove(bundle);
 }
示例#4
0
        private static AssetManager.Bundle loadBundle(string name, AssetManager.OnBundleLoaded bundleLoaded)
        {
            int num = AssetManager.Bundles.FindIndex((AssetManager.Bundle b) => b.Name == name);

            if (num != -1)
            {
                if (AssetManager.Bundles[num].State != AssetManager.State.Loaded)
                {
                    AssetManager.Bundles[num].BundleLoaded += bundleLoaded;
                }
                return(AssetManager.Bundles[num]);
            }
            AssetBundle assetBundle = AssetBundle.LoadFromFile(AssetManager.GetStreamingAssetPath(name));

            if (assetBundle == null)
            {
                GameLog.ErrorT(AssetManager.TAG, "Asset bundle load failed: {0}!", new object[] {
                    name
                });
                return(null);
            }
            AssetManager.Bundle bundle = new AssetManager.Bundle();
            bundle.Name          = name;
            bundle.AssetBundle   = assetBundle;
            bundle.State         = AssetManager.State.Loaded;
            bundle.BundleLoaded += bundleLoaded;
            AssetManager.Bundles.Add(bundle);
            bundle.OnLoaded();
            return(bundle);
        }
示例#5
0
        // Speed : LoadAsyncBundle < LoadBundle
        public static AssetManager.Bundle LoadAsyncBundle(string name, AssetManager.OnBundleLoaded bundleLoaded)
        {
            int num = AssetManager.Bundles.FindIndex((AssetManager.Bundle b) => b.Name == name);

            if (num != -1)
            {
                if (AssetManager.Bundles[num].State != AssetManager.State.Loaded)
                {
                    AssetManager.Bundles[num].BundleLoaded += bundleLoaded;
                }
                return(AssetManager.Bundles[num]);
            }
            WWW wWW = WWW.LoadFromCacheOrDownload(AssetManager.GetStreamingAssetWWWPath(name), 1);

            if (wWW == null)
            {
                GameLog.ErrorT(AssetManager.TAG, "Asset bundle load failed: {0}!", new object[] {
                    name
                });
                return(null);
            }
            AssetManager.Bundle bundle = new AssetManager.Bundle();
            bundle.Name          = name;
            bundle.WWW           = wWW;
            bundle.State         = AssetManager.State.Loading;
            bundle.BundleLoaded += bundleLoaded;
            AssetManager.Bundles.Add(bundle);
            AssetManager.AsyncBundles.Add(bundle);
            return(bundle);
        }
示例#6
0
 public static AssetManager.Asset LoadAsyncAssetFromBundle(AssetManager.Bundle bundle, string name, Type type, AssetManager.OnAssetLoaded assetLoaded)
 {
     return(AssetManager.LoadAsset(bundle, name, type, assetLoaded, new AssetManager.LoadAssetDelegate(AssetManager.OnLoadAsyncAsset)));
 }