Exemplo n.º 1
0
        // 加载 AB
        private bool LoadAB <T>(string name, AbMeta ab, AssetHandler <T> handler, ErrorHandler errorhandler, bool loadDependencies = true) where T : Object
        {
            if (ab == null)
            {
                var error = string.Format("Can't find AssetBundle \"{0}\"", name);
#if UNITY_EDITOR
                RTLog.LogError(LogCat.Asset, error);
#endif
                if (errorhandler != null)
                {
                    errorhandler(error);
                }
                return(false);
            }
            if (ab.assetBundle != null)
            {
                if (handler != null)
                {
                    handler(ab.assetBundle as T);
                }
                return(false);
            }
            bool load = false;
            // 加载依赖包
            if (loadDependencies)
            {
                var dependencies = mManifest.GetAllDependencies(ab.name);
                if (dependencies != null)
                {
                    for (int i = 0; i < dependencies.Length; i++)
                    {
                        var id  = HashAssetID(dependencies[i]);
                        var dab = GlobalUtil.Binsearch(mAbs, id);
                        load |= LoadAB <AssetBundle>(dependencies[i], dab, null, null, false);
                    }
                }
            }
            // 加载 ab
            var assethandler = GetHandler(ab.Identify);
            if (assethandler == null)
            {
                assethandler = new ABObtain(ab);
                mHandlers.AddLast(assethandler);
                mLoaders++;
                load = true;
                assethandler.DoComplete(FinishAndLoadNextAsset);
            }
            if (handler != null)
            {
                assethandler.RegistHandler(handler);
            }
            if (errorhandler != null)
            {
                assethandler.RegistErrorHandler(errorhandler);
            }
            return(load);
        }
Exemplo n.º 2
0
        public ABAssetsUtil(AssetSetting set) : base()
        {
            mHandlers = new LinkedList <IAssetHandler>();
            mAssets   = new Dictionary <int, AssetMeta>(set.initCapacity);
            var ab = AssetBundle.LoadFromFile(Path.Combine(set.abFolder, set.manifestName));

            if (ab != null)
            {
                mManifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            }
            if (mManifest == null)
            {
                RTLog.LogError(LogCat.Asset, "Lost AssetBundle Manifest File.");
                mAbs = new AbMeta[0];
            }
            else
            {
                var abs = mManifest.GetAllAssetBundles();
                mAbs = new AbMeta[abs == null ? 0 : abs.Length];
                for (int i = 0; i < mAbs.Length; i++)
                {
                    mAbs[i] = new AbMeta(this, abs[i], Path.Combine(set.abFolder, abs[i]));
                }
                GlobalUtil.Sort(mAbs, (x, y) => x.Identify <= y.Identify ? -1 : 1);
                for (int i = 0; i < mAbs.Length; i++)
                {
                    var dependencies = mManifest.GetAllDependencies(mAbs[i].name);
                    if (dependencies == null || dependencies.Length == 0)
                    {
                        continue;
                    }
                    for (int j = 0; j < dependencies.Length; j++)
                    {
                        var meta = GlobalUtil.Binsearch(mAbs, HashAssetID(dependencies[j]));
                        if (meta != null)
                        {
                            meta.AddReferenceTo(mAbs[i].Identify);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public ABObtain(AbMeta meta)
 {
     mMeta = meta;
 }