Ejemplo n.º 1
0
        private IEnumerator m_LoadAssetBundleFromFileAsync(string assetBundleName)
        {
            string[] list = Instance.GetAssetBundleDependencies(assetBundleName);
            if (list.Length != 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    yield return(StartCoroutine(m_LoadAssetBundleFromFileAsync(list[i])));
                }
            }

            if (!allAssetBundleDic.ContainsKey(assetBundleName))
            {
                AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(AutoGetResourcePath(assetBundleName, false));
                //HFLog.L("异步加载AssetBundle   " + assetBundleName);
                yield return(request);

                if (!allAssetBundleDic.ContainsKey(assetBundleName))
                {
                    AssetBundle        bundle         = request.assetBundle;
                    AssetBundlePackage tmpAssetBundle = new AssetBundlePackage(bundle, assetBundleName);
                    AddAssetBundleToDic(tmpAssetBundle);
                }
            }
            else
            {
                AssetBundlePackage ab = allAssetBundleDic[assetBundleName];
                ab.Retain();
                //HFLog.L("异步 通过缓存加载");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  一般来说,尽可能使用AssetBundle.LoadFromFile。该API在速度,磁盘使用率和运行时内存使用方面是最有效的
        /// </summary>
        public AssetBundlePackage LoadAssetBundleFromFile(string assetBundleName)
        {
            assetBundleName = assetBundleName.ToLower();
            string[] list = Instance.GetAssetBundleDependencies(assetBundleName);
            if (list.Length != 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    LoadAssetBundleFromFile(list[i]);
                }
            }

            if (!allAssetBundleDic.ContainsKey(assetBundleName))
            {
                AssetBundle        bundle         = AssetBundle.LoadFromFile(AutoGetResourcePath(assetBundleName, false));
                AssetBundlePackage tmpAssetBundle = new AssetBundlePackage(bundle, assetBundleName);
                AddAssetBundleToDic(tmpAssetBundle);
                //HFLog.L("同步加载AssetBundle   " + assetBundleName);
                return(tmpAssetBundle);
            }
            else
            {
                AssetBundlePackage ab = allAssetBundleDic[assetBundleName];
                ab.Retain();
                return(ab);
            }
        }
Ejemplo n.º 3
0
        private IEnumerator m_LoadAssetBundleFromFileAsync(string assetBundleName, Action <AssetBundlePackage> finishCallback)
        {
            assetBundleName = assetBundleName.ToLower();
            yield return(StartCoroutine(m_LoadAssetBundleFromFileAsync(assetBundleName)));

            if (finishCallback != null)
            {
                AssetBundlePackage ab = allAssetBundleDic[assetBundleName];
                ab.Retain();
                finishCallback(ab);
            }
        }