Esempio n. 1
0
        /// <summary>
        /// AssetBundle同步加载;
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public AssetBundle LoadFromFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(path);

            if (assetBundlePath == null)
            {
                return(null);
            }
            string assetBundleName = FilePathHelper.GetAssetBundleFileName(path);

            AssetBundle assetBundle = LoadSync(assetBundlePath);

            if (assetBundle == null)
            {
                return(null);
            }
            //返回AssetBundleName;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.shaderAssetBundleName) ||
                    tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.luaAssetBundleName))
                {
                    continue;
                }
                string tempPtah = FilePathHelper.AssetBundlePath + tempAssetBundle;
                LoadSync(tempPtah);
            }
            return(assetBundle);
        }
        /// <summary>
        /// AssetBundle同步加载;
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <returns>AssetBundle</returns>
        public AssetBundle LoadAssetBundleSync(AssetType type, string assetName)
        {
            if (type == AssetType.Non || string.IsNullOrEmpty(assetName))
            {
                return(null);
            }

            string assetBundlePath = FilePathHelper.GetAssetBundlePath(type, assetName);

            if (assetBundlePath == null)
            {
                return(null);
            }
            string assetBundleName = FilePathHelper.GetAssetBundleFileName(type, assetName);

            AssetBundle assetBundle = LoadAssetBundleSync(assetBundlePath);

            if (assetBundle == null)
            {
                return(null);
            }

            //返回AssetBundleName;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders"))
                {
                    continue;
                }
                string tempPtah = FilePathHelper.AssetBundlePath + tempAssetBundle;
                LoadAssetBundleSync(tempPtah);
            }
            return(assetBundle);
        }
        /// <summary>
        /// 通用资源AssetBundle卸载方法[Unload(true)];
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        public void UnloadAsset(AssetType type, string assetName)
        {
            if (type == AssetType.Non || type == AssetType.Shader || type == AssetType.Lua || type == AssetType.Scripts || string.IsNullOrEmpty(assetName))
            {
                return;
            }

            string assetBundleName = FilePathHelper.GetAssetBundleFileName(type, assetName);

            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders"))
                {
                    continue;
                }
                string tempPtah = FilePathHelper.AssetBundlePath + tempAssetBundle;
                UnloadAsset(tempPtah, true);
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(type, assetName);

            if (assetBundlePath != null)
            {
                UnloadAsset(assetBundlePath, true);
            }
        }
Esempio n. 4
0
        private void SetLuaAssetName()
        {
            AssetImporter importer = AssetImporter.GetAtPath(FilePathHelper.luaPath);

            if (importer != null)
            {
                importer.assetBundleName = FilePathHelper.GetAssetBundleFileName(AssetType.Lua, "lua");
                AssetDatabase.ImportAsset(FilePathHelper.luaPath);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// AssetBundle异步加载;
        /// </summary>
        /// <param name="path"></param>
        /// <param name="action"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public IEnumerator <float> LoadFromFileAsync(string path, Action <AssetBundle> action, Action <float> progress)
        {
            if (string.IsNullOrEmpty(path))
            {
                yield break;
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(path);

            if (assetBundlePath == null)
            {
                yield break;
            }
            string assetBundleName = FilePathHelper.GetAssetBundleFileName(path);

            //先加载依赖的AssetBundle;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            float    count   = DependentAssetBundle.Length;
            var      precent = ResourceMgr.Instance.LOAD_BUNDLE_PRECENT;
            float    unit    = precent / (count + 1);
            int      index   = 0;

            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                float dp = 0f;
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.shaderAssetBundleName) ||
                    tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.luaAssetBundleName))
                {
                    continue;
                }
                string tempPtah          = FilePathHelper.AssetBundlePath + tempAssetBundle;
                IEnumerator <float> itor = LoadAsync(tempPtah, null, (value) => { dp = value; });
                while (itor.MoveNext())
                {
                    if (progress != null)
                    {
                        progress(unit * (index + dp));
                    }
                    yield return(Timing.WaitForOneFrame);
                }
                index++;
            }
            //加载目标AssetBundle;
            float p = 0f;
            IEnumerator <float> itorTarget = LoadAsync(assetBundlePath, action, (value) => { p = value; });

            while (itorTarget.MoveNext())
            {
                if (progress != null)
                {
                    progress(unit * (count + p));
                }
                yield return(Timing.WaitForOneFrame);
            }
        }
        /// <summary>
        /// AssetBundle异步加载;
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <param name="action">AssetBundle回调</param>
        /// <param name="progress">progress回调</param>
        /// <returns></returns>
        public IEnumerator <float> LoadAssetBundleAsync(AssetType type, string assetName, Action <AssetBundle> action, Action <float> progress)
        {
            if (type == AssetType.Non || string.IsNullOrEmpty(assetName))
            {
                yield break;
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(type, assetName);

            if (assetBundlePath == null)
            {
                yield break;
            }
            string assetBundleName = FilePathHelper.GetAssetBundleFileName(type, assetName);

            //先加载依赖的AssetBundle;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            float    count = DependentAssetBundle.Length;
            float    unit  = 0.9f / (count + 1);
            int      index = 0;

            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                float dp = 0f;
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders"))
                {
                    continue;
                }
                string tempPtah          = FilePathHelper.AssetBundlePath + tempAssetBundle;
                IEnumerator <float> itor = LoadAsync(tempPtah, null, (value) => { dp = value; });
                while (itor.MoveNext())
                {
                    if (progress != null)
                    {
                        progress(unit * (index + dp));
                    }
                    yield return(Timing.WaitForOneFrame);
                }
                index++;
            }
            //加载目标AssetBundle;
            float p = 0f;
            IEnumerator <float> itorTarget = LoadAsync(assetBundlePath, action, (value) => { p = value; });

            while (itorTarget.MoveNext())
            {
                if (progress != null)
                {
                    progress(unit * (count + p));
                }
                yield return(Timing.WaitForOneFrame);
            }
        }
        /// <summary>
        /// AssetBundle 镜像卸载方法[Unload(false)],使用资源为一般初始化就全局保存不在销毁的资源,如:Shader;
        /// </summary>
        /// <param name="type">资源类型</param>
        /// <param name="assetName">资源名字</param>
        public void UnloadMirroring(AssetType type, string assetName)
        {
            if (type == AssetType.Non || type == AssetType.Scripts || string.IsNullOrEmpty(assetName))
            {
                return;
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(type, assetName);

            if (assetBundlePath != null)
            {
                UnloadAsset(assetBundlePath, false);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// AssetBundle 镜像卸载方法[Unload(false)];
        /// 使用资源为一般初始化就全局保存不在销毁的资源,如:Shader;
        /// </summary>
        /// <param name="path"></param>
        public void UnloadMirroring(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(path);

            if (assetBundlePath != null)
            {
                UnloadAsset(assetBundlePath, false);
            }
        }
        /// <summary>
        /// AssetBundle异步加载;
        /// </summary>
        /// <param name="path"></param>
        /// <param name="action"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public IEnumerator <float> LoadFromFileAsync(string path, Action <AssetBundle> action, Action <float> progress)
        {
            if (string.IsNullOrEmpty(path))
            {
                yield break;
            }
            var assetBundlePath = FilePathHelper.GetAssetBundlePath(path);

            if (assetBundlePath == null)
            {
                yield break;
            }
            var assetBundleName = FilePathHelper.GetAssetBundleFileName(path);
            //先加载依赖的AssetBundle;
            var dependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            var count   = dependentAssetBundle.Length;
            var precent = ResourceMgr.singleton.LOAD_BUNDLE_PRECENT;
            var unit    = precent / (count + 1);
            int index   = 0;

            foreach (var tempAssetBundle in dependentAssetBundle)
            {
                var dp = 0f;
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.shaderAssetBundleName) ||
                    tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.luaAssetBundleName))
                {
                    continue;
                }
                var tempPtah = $"{FilePathHelper.AssetBundlePath}/{tempAssetBundle}";
                var itor     = LoadAsync(tempPtah, null, (value) => { dp = value; });
                while (itor.MoveNext())
                {
                    progress?.Invoke(unit * (index + dp));
                    yield return(Timing.WaitForOneFrame);
                }
                index++;
            }
            //加载目标AssetBundle;
            var p          = 0f;
            var itorTarget = LoadAsync(assetBundlePath, action, (value) => { p = value; });

            while (itorTarget.MoveNext())
            {
                progress?.Invoke(unit * (count + p));
                yield return(Timing.WaitForOneFrame);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Resource同步加载;
        /// </summary>
        /// <typeparam name="T">ctrl</typeparam>
        /// <param name="assetType">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <returns>ctrl</returns>
        public T LoadResourceSync <T>(AssetType assetType, string assetName) where T : Object
        {
            string path = FilePathHelper.GetResourcePath(assetType, assetName);

            if (path != null)
            {
                //Resources.Load加载同一资源,只会有一份Asset,需要实例化的资源可以Instantiate多个对象;
                T ctrl = Resources.Load <T>(path);
                if (ctrl != null)
                {
                    return(ctrl);
                }
            }
            LogHelper.PrintError(string.Format("[ResourceMgr]LoadResourceSync Load Asset {0} failure!",
                                               assetName + "." + assetType.ToString()));
            return(null);
        }
Esempio n. 11
0
        /// <summary>
        /// 通用资源AssetBundle卸载方法[Unload(true)];
        /// </summary>
        /// <param name="path"></param>
        /// <param name="asset"></param>
        public void UnloadAsset(string path, Object asset)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            if (asset != null)
            {
                List <WeakReference> list;
                if (_assetBundleRefDict.TryGetValue(path, out list))
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        if ((Object)(list[i].Target) == asset)
                        {
                            list.RemoveAt(i);
                            //需要UnloadAsset?
                            //Resources.UnloadAsset(asset);
                            break;
                        }
                    }
                }
            }

            string assetBundleName = FilePathHelper.GetAssetBundleFileName(path);

            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(FilePathHelper.shaderAssetBundleName))
                {
                    continue;
                }
                string tempPtah = FilePathHelper.AssetBundlePath + tempAssetBundle;
                UnloadAsset(tempPtah, true);
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(path);

            if (assetBundlePath != null)
            {
                UnloadAsset(assetBundlePath, true);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Resource异步加载;
        /// </summary>
        /// <typeparam name="T">ctrl</typeparam>
        /// <param name="assetType">资源类型</param>
        /// <param name="assetName">资源名字</param>
        /// <param name="proxy">代理</param>
        /// <param name="action">资源回调</param>
        /// <param name="progress">progress回调</param>
        /// <returns></returns>
        private IEnumerator <float> LoadResourceAsync <T>(AssetType assetType, string assetName, AsyncResourceProxy proxy
                                                          , Action <T> action, Action <float> progress) where T : Object
        {
            string path = FilePathHelper.GetResourcePath(assetType, assetName);
            T      ctrl = null;

            if (path != null)
            {
                ResourceRequest request = Resources.LoadAsync <T>(path);
                while (request.progress < 0.99)
                {
                    if (progress != null)
                    {
                        progress(request.progress);
                    }
                    yield return(Timing.WaitForOneFrame);
                }
                while (!request.isDone)
                {
                    yield return(Timing.WaitForOneFrame);
                }
                ctrl = request.asset as T;
            }
            if (null == ctrl)
            {
                LogHelper.PrintError(string.Format("[ResourceMgr]LoadResourceAsync Load Asset {0} failure!",
                                                   assetName + "." + assetType.ToString()));
            }
            //--------------------------------------------------------------------------------------
            //先等一帧;
            yield return(Timing.WaitForOneFrame);

            if (!proxy.IsCancel && action != null)
            {
                action(ctrl);
            }
            if (proxy != null)
            {
                proxy.OnFinish(ctrl);
            }
        }
Esempio n. 13
0
        public AssetBundleLoadNode GetAssetBundleLoadNode(AssetType assetType, string assetName)
        {
            if (assetType == AssetType.Non || string.IsNullOrEmpty(assetName))
            {
                return(null);
            }
            string assetBundlePath = FilePathHelper.GetAssetBundlePath(assetType, assetName);

            if (assetBundlePath == null)
            {
                return(null);
            }
            string assetBundleName = FilePathHelper.GetAssetBundleFileName(assetType, assetName);

            Queue <AssetBundleLoadNode> nodeQueue = null;

            //返回AssetBundleName;
            string[] DependentAssetBundle = Manifest.GetAllDependencies(assetBundleName);
            if (DependentAssetBundle.Length > 0)
            {
                nodeQueue = new Queue <AssetBundleLoadNode>();
            }
            foreach (string tempAssetBundle in DependentAssetBundle)
            {
                if (tempAssetBundle == FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders"))
                {
                    continue;
                }
                string tempPtah = FilePathHelper.AssetBundlePath + tempAssetBundle;
                AssetBundleLoadNode tempNode = PoolMgr.Instance.GetCsharpObject <AssetBundleLoadNode>();
                tempNode.Init(tempPtah);
                nodeQueue.Enqueue(tempNode);
            }
            AssetBundleLoadNode node = PoolMgr.Instance.GetCsharpObject <AssetBundleLoadNode>();

            node.Init(assetBundlePath, nodeQueue);
            return(node);
        }
        public Object GetUnityAsset(AssetType assetType, string assetName)
        {
            string path = FilePathHelper.GetAssetBundlePath(assetType, assetName);
            UnityAssetCacheInfo info = null;

            if (!string.IsNullOrEmpty(path) && _unityAssetCacheDict.TryGetValue(path, out info))
            {
                int count = 0;
                if (!_unityAssetRefCountDict.TryGetValue(path, out count))
                {
                    count = 0;
                }
                count++;
                _unityAssetRefCountDict[path] = count;
            }
            if (null == info)
            {
                return(null);
            }
            else
            {
                return(info.target);
            }
        }
        /// <summary>
        /// 分析全部资源依赖关系;
        /// </summary>
        /// <returns></returns>
        public List <AssetBundleBuild> AnalysisAllAsset()
        {
            Stopwatch watch = Stopwatch.StartNew();//开启计时;

            string[] allPath = Directory.GetFiles(FilePathHelper.resPath, "*.*", SearchOption.AllDirectories);

            //剔除.meta文件;
            List <string> allAssetPath = new List <string>();

            foreach (string tempPath in allPath)
            {
                string path = tempPath.Replace("\\", "/");
                if (Path.GetExtension(path) == ".meta")
                {
                    continue;
                }
                allAssetPath.Add(path);
            }

            //开始分析资源依赖关系;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                if (!CheckAssetNode(allAssetPath[i]))
                {
                    continue;
                }

                //还未遍历到该资源;
                if (!allAsset.ContainsKey(allAssetPath[i]))
                {
                    allAsset[allAssetPath[i]] = CreateNewAssetNode(allAssetPath[i]);
                }

                //获取依赖关系;
                string[] allDirectDependencies = AssetDatabase.GetDependencies(allAssetPath[i], false);

                foreach (string tempPath in allDirectDependencies)
                {
                    if (!CheckAssetNode(tempPath))
                    {
                        continue;
                    }

                    //添加依赖的资源信息;
                    allAsset[allAssetPath[i]].sonDependentAssets.Add(tempPath);
                    //添加被依赖的资源信息;
                    if (!allAsset.ContainsKey(tempPath))
                    {
                        allAsset[tempPath] = CreateNewAssetNode(tempPath);
                    }
                    allAsset[tempPath].parentDependentAssets.Add(allAssetPath[i]);
                }
            }

            foreach (var tempAsset in allAsset)
            {
                if (tempAsset.Value.parentDependentAssets.Count == 0 || //没有被依赖的资源;
                    tempAsset.Value.parentDependentAssets.Count > 1 ||  //被超过一个资源依赖的资源;
                    tempAsset.Key.Contains(FilePathHelper.resPath))     //Bundles资源目录下的资源,允许加载所以单独打包;
                {
                    independenceAsset[tempAsset.Key] = tempAsset.Value;
                }
            }

            //TODO:AssetBundleBuild修改为可以包含多个资源.
            List <AssetBundleBuild> builderList = new List <AssetBundleBuild>();

            foreach (var asset in independenceAsset)
            {
                var node = asset.Value;
                AssetBundleBuild build = new AssetBundleBuild
                {
                    assetBundleName = FilePathHelper.GetAssetBundleFileName(node.assetPath)
                };
                List <string> assetLis = new List <string>
                {
                    node.assetPath
                };
                foreach (var tempAsset in node.sonDependentAssets)
                {
                    if (!independenceAsset.ContainsKey(tempAsset))
                    {
                        assetLis.Add(tempAsset);
                    }
                }
                build.assetNames = assetLis.ToArray();
                builderList.Add(build);
            }

            AssetBundleBuild shaderBuild = new AssetBundleBuild
            {
                assetBundleName = FilePathHelper.GetAssetBundleFileName(FilePathHelper.shaderAssetBundleName)
            };
            List <string> shaderList = new List <string>();

            foreach (var shader in allShaderAsset)
            {
                shaderList.Add(shader);
            }
            shaderBuild.assetNames = shaderList.ToArray();
            builderList.Add(shaderBuild);

            AssetBundleBuild luaBuild = new AssetBundleBuild
            {
                assetBundleName = FilePathHelper.GetAssetBundleFileName(FilePathHelper.luaAssetBundleName)
            };
            List <string> luaList = new List <string>();

            foreach (var lua in allLuaAsset)
            {
                luaList.Add(lua);
            }
            luaBuild.assetNames = luaList.ToArray();
            builderList.Add(luaBuild);

            watch.Stop();

            LogHelper.PrintWarning($"[AssetDependenciesAnalysis]Asset Dependencies Analysis Spend Time:{watch.Elapsed.TotalSeconds}s");

            SaveBuildInfo(builderList);

            return(builderList);
        }
Esempio n. 16
0
        /// <summary>
        /// 分析全部资源依赖关系;
        /// </summary>
        public void AnalysisAllAsset()
        {
            Stopwatch watch = Stopwatch.StartNew();//开启计时;

            string[] allPath = Directory.GetFiles(FilePathHelper.resPath, "*.*", SearchOption.AllDirectories);

            //剔除.meta文件;
            List <string> allAssetPath = new List <string>();

            foreach (string tempPath in allPath)
            {
                string path = tempPath.Replace("\\", "/");
                if (Path.GetExtension(path) == ".meta")
                {
                    continue;
                }
                allAssetPath.Add(path);
            }

            //开始分析资源依赖关系;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "获取需要打包的资源", ((float)i / (float)allAssetPath.Count));

                //还未遍历到该资源;
                if (!allAsset.ContainsKey(allAssetPath[i]))
                {
                    allAsset[allAssetPath[i]] = CreateNewAssetNode(allAssetPath[i]);
                }
                //获取依赖关系;
                string[] allDirectDependencies = AssetDatabase.GetDependencies(allAssetPath[i], false);
                foreach (string tempPath in allDirectDependencies)
                {
                    //依赖脚本直接添加到脚本队列;
                    if (AssetBundleDefine.GetAssetType(tempPath) == AssetType.Scripts)
                    {
                        continue;
                    }
                    //依赖Shader直接添加到Shader队列;
                    if (AssetBundleDefine.GetAssetType(tempPath) == AssetType.Shader)
                    {
                        allShaderAsset.Add(tempPath);
                        continue;
                    }
                    if (tempPath.Contains(FilePathHelper.resPath))
                    {
                        //添加依赖的资源信息;
                        allAsset[allAssetPath[i]].sonDependentAssets.Add(tempPath);
                        //添加被依赖的资源信息;
                        if (!allAsset.ContainsKey(tempPath))
                        {
                            allAsset[tempPath] = CreateNewAssetNode(tempPath);
                        }
                        allAsset[tempPath].parentDependentAssets.Add(allAssetPath[i]);
                    }
                    else
                    {
                        //需要打包AssetBundle的资源目录下的资源,引用非该目录下的资源;
                        LogHelper.Print("[Asset Dependencies Analysis] path:" + allAssetPath[i] + "--->>>reference--->>>: " + tempPath);
                    }
                }
            }
            EditorUtility.ClearProgressBar();

            //找出需要打包的资源;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "分析需要打包的资源", ((float)i / (float)allAssetPath.Count));

                //图集特殊处理;

                /*
                 * if (allAssetPath[i].Contains("Atlas") && Path.GetExtension(allAssetPath[i]) == ".prefab")//ngui
                 * {
                 *  independenceAsset[allAssetPath[i]] = allAsset[allAssetPath[i]];
                 *  continue;
                 * }
                 */
                if (allAssetPath[i].Contains(FilePathHelper.resPath + "Shaders") && Path.GetExtension(allAssetPath[i]) == ".shader")
                {
                    allShaderAsset.Add(allAssetPath[i]);
                    continue;
                }
                if (allAsset[allAssetPath[i]].parentDependentAssets.Count == 0 || //没有被依赖的资源;
                    allAsset[allAssetPath[i]].parentDependentAssets.Count > 1 ||  //被超过一个资源依赖的资源;
                    allAssetPath[i].Contains(FilePathHelper.singleResPath))       //指定要求单独打包的资源;
                {
                    independenceAsset[allAssetPath[i]] = allAsset[allAssetPath[i]];
                }
            }
            EditorUtility.ClearProgressBar();

            //设置资源AssetBundle Name;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "设置AssetBundle Name", ((float)i / (float)allAssetPath.Count));

                AssetImporter importer = AssetImporter.GetAtPath(allAssetPath[i]);
                if (importer != null)
                {
                    if (independenceAsset.ContainsKey(allAssetPath[i]))
                    {
                        importer.assetBundleName = FilePathHelper.GetAssetBundleFileName(independenceAsset[allAssetPath[i]].type, independenceAsset[allAssetPath[i]].assetName);
                    }
                    else
                    {
                        importer.assetBundleName = null;
                    }
                    AssetDatabase.ImportAsset(allAssetPath[i]);
                }
            }
            EditorUtility.ClearProgressBar();

            int index = 0;

            //设置Shader AssetBundle Name;
            foreach (string tempPath in allShaderAsset)
            {
                index++;
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "设置Shader AssetBundle Name", ((float)index / (float)allShaderAsset.Count));
                AssetImporter importer = AssetImporter.GetAtPath(tempPath);
                if (importer != null)
                {
                    importer.assetBundleName = FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders");
                    AssetDatabase.ImportAsset(tempPath);
                }
            }

            SetLuaAssetName();
            //SetAtlasName();

            EditorUtility.ClearProgressBar();

            watch.Stop();
            LogHelper.PrintWarning(string.Format("[AssetDependenciesAnalysis]Asset Dependencies Analysis Spend Time:{0}s", watch.Elapsed.TotalSeconds));

            AssetDatabase.Refresh();
        }
Esempio n. 17
0
        public AssetBundle LoadLuaAssetBundle()
        {
            string path = FilePathHelper.GetAssetBundlePath(AssetType.Lua, "lua");

            return(LoadAssetBundleSync(path));
        }
Esempio n. 18
0
        /// <summary>
        /// 加载Shader AssetBundle;
        /// </summary>
        /// <returns>AssetBundle</returns>
        public AssetBundle LoadShaderAssetBundle()
        {
            string path = FilePathHelper.GetAssetBundlePath(AssetType.Shader, "Shaders");

            return(LoadAssetBundleSync(path));
        }
        public void ReleaseUnityAsset(AssetType assetType, string assetName, Object obj, bool isUsePool)
        {
            string path = FilePathHelper.GetAssetBundlePath(assetType, assetName);

            if (null == obj)
            {
                LogHelper.PrintError(string.Format("[UnityAssetCachePool]Release unity asset:{0} error" +
                                                   ",Object is null!", path));
                return;
            }
            if (string.IsNullOrEmpty(path))
            {
                ResourceMgr.Instance.UnloadUnityAssetMemory(assetType, obj);
                return;
            }
            UnityAssetCacheInfo info = null;

            if (_unityAssetCacheDict.TryGetValue(path, out info))
            {
                if (info.target != obj)
                {
                    LogHelper.PrintError(string.Format("[UnityAssetCachePool]Release unity asset:{0} error" +
                                                       ",the path ref multiple Object!", path));
                    ResourceMgr.Instance.UnloadUnityAssetMemory(assetType, obj);
                    return;
                }
                int count = 0;
                if (!_unityAssetRefCountDict.TryGetValue(path, out count))
                {
                    LogHelper.PrintError(string.Format("[UnityAssetCachePool]Release unity asset:{0} error" +
                                                       ",ref count not exist!", path));
                    _unityAssetRefCountDict[path] = 0;
                }
                else
                {
                    _unityAssetRefCountDict[path]--;
                    if (!isUsePool)
                    {
                        //引用为0,又不是初次放入,直接回收;
                        if (_unityAssetRefCountDict[path] == 0)
                        {
                            _unityAssetCacheDict.Remove(path);
                            _unityAssetRefCountDict.Remove(path);
                            ResourceMgr.Instance.UnloadUnityAssetMemory(assetType, info.target);
                            PoolMgr.Instance.ReleaseCsharpObject <UnityAssetCacheInfo>(info);
                            AssetBundleMgr.Instance.UnloadAsset(assetType, assetName);
                        }
                    }
                }
            }
            else
            {
                info = PoolMgr.Instance.GetCsharpObject <UnityAssetCacheInfo>();
                info.Init(assetType, assetName, obj);
                _unityAssetCacheDict[path] = info;
                int count = 0;
                if (_unityAssetRefCountDict.TryGetValue(path, out count))
                {
                    LogHelper.PrintError(string.Format("[UnityAssetCachePool]Release unity asset:{0} error" +
                                                       ",ref count != 0!", path));
                }
                _unityAssetRefCountDict[path] = 0;
            }
        }