예제 #1
0
        /// <summary>
        /// 加载assetbundle
        /// </summary>
        /// <param name="string">assetBundleName</param>
        /// <param name="bool">async = true 异步加载</param>
        /// <returns></returns>
        static void LoadDependencies(string assetBundleName, string[] deps, bool async)
        {
            string item = null;

            if (deps.Length > 0)
            {
                // Debug.LogFormat("LoadDependencies assetBundleName={0},deps={0},len={1}", assetBundleName, string.Concat(deps), deps.Length);
                CacheManager.AddDependencies(assetBundleName, deps); //记录引用关系
                //开始加载依赖
                for (int i = 0; i < deps.Length; i++)
                {
                    item = deps[i];
                    if (!item.Equals(assetBundleName))
                    {
                        CacheData cacheData = null;
                        CacheManager.CreateOrGetCache(item, out cacheData);
                        cacheData.count++;                 //引用计数加1
                        ABDelayUnloadManager.Remove(item); //从列表移除
                        if (!cacheData.canUse)
                        {
                            LoadAssetBundleInternal(item, async);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 加载assetbundle
        /// </summary>
        /// <param name="assetBundleName"> string 加载资源名</param>
        /// <param name="async"> bool 异步加载默认ture</param>
        /// <returns></returns>
        internal static bool LoadAssetBundle(string assetBundleName, bool async = true)
        {
#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                return(false);
            }
#endif
            //查找缓存
            CacheData cacheData = null;
            CacheManager.CreateOrGetCache(assetBundleName, out cacheData);
            cacheData.count++;                            //引用计数加1
            ABDelayUnloadManager.Remove(assetBundleName); //从回收列表移除
            if (cacheData.canUse)
            {
                return(true);
            }

            //开始加载依赖
            string[] deps = null;
            if (ManifestManager.fileManifest != null && (deps = ManifestManager.fileManifest.GetDirectDependencies(assetBundleName)).Length > 0)
            {
                LoadDependencies(assetBundleName, deps, async);
            }

            //加载assetbundle
            LoadAssetBundleInternal(assetBundleName, async);
            return(false);
        }