Example #1
0
        /// <summary>
        /// 导出资源包
        /// </summary>
        public static bool ExportRes(ResExportDesc rd, bool compress)
        {
            // 导出
            string pathName = UtilityTools.GenResExportPath(rd.resDir, rd.resName);
            var    names    = new string[] { rd.resName };
            var    assets   = new UnityEngine.Object[] { rd.asset };
            var    options  = BuildAssetBundleOptions.DeterministicAssetBundle;

            if (!compress)
            {
                options |= BuildAssetBundleOptions.UncompressedAssetBundle;
            }
            if (!BuildPipeline.BuildAssetBundleExplicitAssetNames(assets, names, pathName, options, EditorUserBuildSettings.activeBuildTarget))
            {
                Debug.LogErrorFormat("ExportAssetBundle {0} failed!", pathName);
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// 收集资源
        /// </summary>
        protected string CollectRes(UnityEngine.Object asset, Dictionary <string, ResExportDesc> dictResDesc)
        {
            // 名字
            var resName = GetResName(asset);
            int n       = 0;

            while (true)
            {
                // 字典里没有
                ResExportDesc resDesc;
                if (!dictResDesc.TryGetValue(resName, out resDesc))
                {
                    resDesc          = new ResExportDesc();
                    resDesc.asset    = asset;
                    resDesc.resType  = resType;
                    resDesc.resName  = resName;
                    resDesc.resDir   = GetResDir();
                    resDesc.refCount = 1;
                    dictResDesc.Add(resName, resDesc);
                    break;
                }

                // 相同类型,同名
                if (resDesc.resType == resType)
                {
                    var path = AssetDatabase.GetAssetPath(asset);
                    var p    = AssetDatabase.GetAssetPath(resDesc.asset);
                    if (path != p)
                    {
                        Debug.LogErrorFormat("资源\"{0}\"和\"{1}\"重名!", path, p);
                    }
                    ++resDesc.refCount;
                    break;
                }

                // 不同类型、同名
                resName = string.Format("{0}_r{1}", resName, ++n);
            }
            return(resName);
        }