コード例 #1
0
ファイル: BuildScript.cs プロジェクト: wwwsosokk/hugula
        /// <summary>
        /// 自动构建ab
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="outPath"></param>
        /// <param name="abName"></param>
        /// <param name="bbo"></param>
        static public void BuildABs(string[] assets, string outPath, string abName, BuildAssetBundleOptions bbo)
        {
            AssetBundleBuild[] bab = new AssetBundleBuild[1];
            bab[0].assetBundleName = abName;//打包的资源包名称 随便命名
            bab[0].assetNames      = assets;
            if (string.IsNullOrEmpty(outPath))
            {
                outPath = GetOutPutPath();
            }

            string tmpPath = BuildScript.GetProjectTempPath();

            ExportResources.CheckDirectory(tmpPath);
            string tmpFileName = Path.Combine(tmpPath, abName);

            BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target);

            string   targetFileName = Path.Combine(outPath, abName);
            FileInfo tInfo          = new FileInfo(targetFileName);

            if (tInfo.Exists)
            {
                tInfo.Delete();
            }
            FileInfo fino = new FileInfo(tmpFileName);

            fino.CopyTo(targetFileName);
        }
コード例 #2
0
ファイル: BuildScript.cs プロジェクト: wwwsosokk/hugula
        /// <summary>
        /// 自动构建ab
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="outPath"></param>
        /// <param name="abName"></param>
        /// <param name="bbo"></param>
        static public void BuildABs(AssetBundleBuild[] bab, string outPath, BuildAssetBundleOptions bbo)
        {
            if (string.IsNullOrEmpty(outPath))
            {
                outPath = GetOutPutPath();
            }

            string tmpPath = BuildScript.GetProjectTempPath();

            ExportResources.CheckDirectory(tmpPath);

            BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target);

            foreach (AssetBundleBuild abb in  bab)
            {
                string   abName         = abb.assetBundleName;
                string   tmpFileName    = Path.Combine(tmpPath, abName);
                string   targetFileName = Path.Combine(outPath, abName);
                FileInfo tInfo          = new FileInfo(targetFileName);
                if (tInfo.Exists)
                {
                    tInfo.Delete();
                }
                FileInfo fino = new FileInfo(tmpFileName);
                fino.CopyTo(targetFileName);
            }
        }
コード例 #3
0
ファイル: SplitPackage.cs プロジェクト: pengjugame/hugula
        /// <summary>
        ///   delete res folder
        /// </summary>
        public static void DeleteSplitPackageResFolder()
        {
            string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);

            Debug.Log("Delete directory " + updateOutPath);
            ExportResources.DirectoryDelete(updateOutPath);

            string updateOutVersionPath = Path.Combine(UpdateOutVersionPath, ResFolderName);

            Debug.Log("Delete directory " + updateOutVersionPath);
            ExportResources.DirectoryDelete(updateOutVersionPath);
        }
コード例 #4
0
ファイル: SplitPackage.cs プロジェクト: pengjugame/hugula
        public static uint CreateStreamingFileManifest(AssetBundleManifest assetBundleManifest)
        {
            var allABs             = assetBundleManifest.GetAllAssetBundles();
            var bundlesWithVariant = assetBundleManifest.GetAllAssetBundlesWithVariant();

            var streamingManifest = ScriptableObject.CreateInstance(typeof(FileManifest)) as FileManifest;
            //读取 bundlesWithVariant
            var MyVariant = new string[bundlesWithVariant.Length];

            for (int i = 0; i < bundlesWithVariant.Length; i++)
            {
                var curSplit = bundlesWithVariant[i].Split('.');
                MyVariant[i] = bundlesWithVariant[i];
            }
            //读取abinfo
            List <ABInfo> allABInfos = new List <ABInfo>();

            foreach (var abs in allABs)
            {
                var abInfo       = new ABInfo(abs, 0, 0, 0);
                var dependencies = assetBundleManifest.GetDirectDependencies(abs);
                abInfo.dependencies = dependencies;
                allABInfos.Add(abInfo);
            }

            //fill data
            streamingManifest.allAbInfo = allABInfos;
            streamingManifest.allAssetBundlesWithVariant = bundlesWithVariant;
            streamingManifest.appNumVersion = CodeVersion.APP_NUMBER;
            // streamingManifest.crc32 = assetBundleManifest.GetHashCode();

            //create asset
            string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            ExportResources.CheckDirectory(tmpPath);
            var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
            string assetPath     = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset";

            AssetDatabase.CreateAsset(streamingManifest, assetPath);
            //build assetbundle
            string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME);

            BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions);

            streamingManifest.WriteToFile("Assets/" + BuildScript.TmpPath + "local_streamingManifest.txt");
            Debug.LogFormat("FileManifest  Path = {0}/{1};", CUtils.realStreamingAssetsPath, crc32outfilename);
            return(0);
        }
コード例 #5
0
ファイル: SplitPackage.cs プロジェクト: lzxkulou/hugula
        private static void CopyFileToSplitFolder(Dictionary <string, uint[]> updateList)
        {
            string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);

            ExportResources.CheckDirectory(updateOutPath);

            int allLen = updateList.Count;
            int i      = 0;

            EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath, 0.09f);

            string sourcePath;
            string outfilePath;
            string key;
            uint   crc = 0;

            foreach (var k in updateList)
            {
                key        = k.Key;//CUtils.GetAssetBundleName(k.Key);
                sourcePath = Path.Combine(CUtils.GetRealStreamingAssetsPath(), k.Key);
                crc        = k.Value[0];
                if (crc != 0)
                {
                    if (key.Equals(CUtils.platformFloder))
                    {
                        key = key + "_" + crc.ToString() + "." + Common.ASSETBUNDLE_SUFFIX;
                    }
                    else
                    {
                        key = CUtils.InsertAssetBundleName(key, "_" + crc.ToString());//
                    }
                }
                outfilePath = Path.Combine(updateOutPath, key);
                FileHelper.CheckCreateFilePathDirectory(outfilePath);
                File.Copy(sourcePath, outfilePath, true);// source code copy
                EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file  =>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }
            Debug.Log(" copy  file complete!");
            EditorUtility.ClearProgressBar();
        }
コード例 #6
0
ファイル: ExportResources.cs プロジェクト: lzxkulou/hugula
        public static void doExportLua(string[] childrens, bool android_ab_build = false)
        {
            BuildScript.CheckstreamingAssetsPath();

            string info  = "luac";
            string title = "build lua";

            EditorUtility.DisplayProgressBar(title, info, 0);

            var checkChildrens = AssetDatabase.GetAllAssetPaths().Where(p =>
                                                                        (p.StartsWith("Assets/Lua") ||
                                                                         p.StartsWith("Assets/Config")) &&
                                                                        (p.EndsWith(".lua"))
                                                                        ).ToArray();
            string path  = "Assets/Lua/";     //lua path
            string path1 = "Assets/Config/";  //config path
            string root  = CurrentRootFolder; //Application.dataPath.Replace("Assets", "");

            string crypName = "", fileName = "", outfilePath = "", arg = "";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            //refresh directory
            if (checkChildrens.Length == childrens.Length)
            {
                DirectoryDelete(OutLuaPath);
            }
            CheckDirectory(OutLuaPath);

            float allLen = childrens.Length;
            float i      = 0;

            System.Diagnostics.Process luaProccess = new System.Diagnostics.Process();
            luaProccess.StartInfo.CreateNoWindow = true;
            luaProccess.StartInfo.WindowStyle    = System.Diagnostics.ProcessWindowStyle.Hidden;
            luaProccess.StartInfo.FileName       = luacPath;

            System.Diagnostics.Process luajit32Proccess = new System.Diagnostics.Process();
            luajit32Proccess.StartInfo.CreateNoWindow   = true;
            luajit32Proccess.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
            luajit32Proccess.StartInfo.FileName         = luajit32Path;
            luajit32Proccess.StartInfo.WorkingDirectory = luaWorkingPath;

            System.Diagnostics.Process luajit64Proccess = new System.Diagnostics.Process();
            luajit64Proccess.StartInfo.CreateNoWindow   = true;
            luajit64Proccess.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
            luajit64Proccess.StartInfo.FileName         = luajit64Path;
            luajit64Proccess.StartInfo.WorkingDirectory = luaWorkingPath;

            Debug.Log("luajit32Path:" + luajit32Path);
            Debug.Log("luajit64Path:" + luajit64Path);
            Debug.Log("luacPath:" + luacPath);
#if UNITY_ANDROID
            string streamingAssetsPath = Path.Combine(CurrentRootFolder, LuaTmpPath);
            DirectoryDelete(streamingAssetsPath);
            CheckDirectory(streamingAssetsPath);
#else
            string streamingAssetsPath = CUtils.realStreamingAssetsPath;
#endif
            Debug.Log(streamingAssetsPath);
            luaProccess.StartInfo.WorkingDirectory = luaWorkingPath;
            List <string> exportNames = new List <string>();

            foreach (string file in childrens)
            {
                string filePath = Path.Combine(root, file);
                fileName = CUtils.GetAssetName(filePath);
                crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "+").Replace("/", "+");

                if (!string.IsNullOrEmpty(luajit32Path))// luajit32
                {
                    string override_name = CUtils.GetRightFileName(crypName);
                    string override_lua  = Path.Combine(streamingAssetsPath, override_name);
                    arg = "-b " + filePath + " " + override_lua; //for jit
                    luajit32Proccess.StartInfo.Arguments = arg;
                    luajit32Proccess.Start();
                    luajit32Proccess.WaitForExit();
#if UNITY_ANDROID
                    Debug.Log(luajit32Proccess.StartInfo.FileName + " " + arg);
                    exportNames.Add(Path.Combine(LuaTmpPath, override_name));
#endif
                    sb.AppendLine("[\"" + crypName + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},");
                }
                if (!string.IsNullOrEmpty(luajit64Path)) //luajit64
                {
                    string crypName_64   = CUtils.InsertAssetBundleName(crypName, "_64");
                    string override_name = CUtils.GetRightFileName(crypName_64);
                    string override_lua  = Path.Combine(streamingAssetsPath, override_name);
                    arg = "-b " + filePath + " " + override_lua; //for jit
                    luajit64Proccess.StartInfo.Arguments = arg;
                    luajit64Proccess.Start();
                    luajit64Proccess.WaitForExit();
                    sb.AppendLine("[\"" + crypName_64 + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},");
                }
                if (!string.IsNullOrEmpty(luacPath))                          //for editor
                {
                    string override_name = CUtils.GetRightFileName(crypName); //CUtils.GetRightFileName(CUtils.InsertAssetBundleName(crypName,"_64"));
                    string override_lua  = Path.Combine(OutLuaPath, override_name);
#if UNITY_EDITOR_OSX && !UNITY_STANDALONE_WIN
                    arg = "-o " + override_lua + " " + filePath; //for lua
#else
                    arg = "-b " + filePath + " " + override_lua; //for jit
#endif
                    luaProccess.StartInfo.Arguments = arg;
                    luaProccess.Start();
                    luaProccess.WaitForExit();
                    sb.AppendLine("[\"" + crypName + "(editor)\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},");
                }
                i++;
                EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
            }

            Debug.Log("lua:" + path + "files=" + childrens.Length + " completed");
            System.Threading.Thread.Sleep(100);
            //AssetDatabase.Refresh();

            //out md5 mapping file
            string tmpPath = BuildScript.GetAssetTmpPath();
            ExportResources.CheckDirectory(tmpPath);
            string outPath = Path.Combine(tmpPath, "lua_md5mapping.txt");
            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(sb.ToString());
            }

            //
#if UNITY_ANDROID
            if (android_ab_build)
            {
                title  = "lua bytes to asset";
                allLen = exportNames.Count;
                i      = 0;
                string luaStreamingAssetsPath = "Assets" + CUtils.realStreamingAssetsPath.Replace(Application.dataPath, "");
                Debug.Log(luaStreamingAssetsPath);
                // AssetImporter import = null;
                List <AssetBundleBuild> abbs = new List <AssetBundleBuild>();
                foreach (var luapath in exportNames)
                {
                    try
                    {
                        byte[] luabytes   = File.ReadAllBytes(luapath);
                        string assetName  = Path.GetFileName(luapath);//CUtils.GetAssetBundleName(luapath);
                        var    bytesAsset = ScriptableObject.CreateInstance <BytesAsset>();
                        bytesAsset.bytes = luabytes;
                        string assetPath = luapath.Replace("." + Common.LUA_LC_SUFFIX, ".asset");
                        AssetDatabase.CreateAsset(bytesAsset, assetPath);
                        AssetBundleBuild abb = new AssetBundleBuild();
                        abb.assetBundleName = assetName;
                        abb.assetNames      = new string[] { assetPath };
                        abbs.Add(abb);
                        i++;
                        EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogError(e.ToString());
                    }
                }

                title  = "lua asset to assetbundle";
                allLen = abbs.Count;
                i      = 0;

                // foreach (var abb in abbs)
                // {
                //     BuildScript.BuildABs(abb.assetNames, null, abb.assetBundleName, BuildAssetBundleOptions.None);
                //     i++;
                //     EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                // }

                title = "build lua assetbundle ";
                EditorUtility.DisplayProgressBar(title, info + "=>", 1);

                BuildScript.BuildABs(abbs.ToArray(), null, BuildAssetBundleOptions.None);
            }
#endif

            EditorUtility.ClearProgressBar();
        }
コード例 #7
0
ファイル: ExportResources.cs プロジェクト: lzxkulou/hugula
 public static void DeleteStreamingOutPath()
 {
     ExportResources.DirectoryDelete(Application.streamingAssetsPath);
 }
コード例 #8
0
ファイル: SplitPackage.cs プロジェクト: wwwsosokk/hugula
        public const string ResFolderName = EditorCommon.ResFolderName; //"res";
        #region public


        /// <summary>
        /// 1 读取首包,找出忽略文件
        /// </summary>
        /// <param name="ignoreFiles">Ignore files.</param>
        public static bool ReadFirst(Dictionary <string, object[]> firstCrcDict, HashSet <string> whiteFileList, HashSet <string> blackFileList)
        {
            string title = "read first crc file list";

            CrcCheck.Clear();
            bool firstExists = false;

            string readPath = Path.Combine(GetFirstOutPath(), CUtils.platform);

            readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME));
            Debug.Log(readPath);

            whiteFileList.Clear();
            blackFileList.Clear();

            WWW abload = new WWW("file://" + readPath);

            if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null)
            {
                var        ab     = abload.assetBundle;
                Object[]   assets = ab.LoadAllAssets();
                BytesAsset ba;
                foreach (Object o in assets)
                {
                    ba = o as BytesAsset;
                    if (ba != null)
                    {
                        byte[] bytes   = ba.bytes;
                        string context = LuaHelper.GetUTF8String(bytes);
                        Debug.Log(context);
                        string[] split = context.Split('\n');
                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+{(\d+),(\d+)}");
                        float j = 1;
                        float l = split.Length;
                        foreach (var line in split)
                        {
                            System.Text.RegularExpressions.Match match = regex.Match(line);
                            if (match.Success)
                            {
                                //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value);
                                //					CrcCheck.Add (match.Groups [1].Value, System.Convert.ToUInt32 (match.Groups [2].Value));
                                object[] val = new object[] { System.Convert.ToUInt32(match.Groups[2].Value), System.Convert.ToUInt32(match.Groups[3].Value) };
                                firstCrcDict[match.Groups[1].Value] = val;
                            }
                            //Debug.Log(line);
                            EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l);
                            j++;
                        }
                        firstExists = true;
                    }
                }
                ab.Unload(true);
            }
            else
            {
                Debug.LogWarning(abload.error + "no frist packeage in " + readPath);
            }
            abload.Dispose();


#if HUGULA_WEB_MODE
            string[] whitelist = new string[] { CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME),
                                                CUtils.GetRightFileName(Common.CRC32_VER_FILENAME),
                                                CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME),
                                                CUtils.platformFloder };
            foreach (var kv in whitelist)
            {
                whiteFileList.Add(kv);
            }
#else
            //读取忽略扩展包
            bool spExtFolder = HugulaSetting.instance.spliteExtensionFolder;
            if (spExtFolder)
            {
                string        firstStreamingPath = CUtils.realStreamingAssetsPath;
                DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath);
                var           dircs = dinfo.GetDirectories();
                foreach (var dir in dircs)
                {
                    var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false);
                    //List<string> assets = new List<string>();
                    foreach (var s in u3dList)
                    {
                        string ab = CUtils.GetAssetBundleName(s);
                        ab = ab.Replace("\\", "/");
                        blackFileList.Add(ab);
                        Debug.Log("extends folder:" + ab);
                    }
                }
            }
            else
            {
                Debug.Log("extends folder is close ,spliteExtensionFolder=" + spExtFolder);
            }
#endif
            //从网络读取白名单列表 todo


            EditorUtility.ClearProgressBar();
            return(firstExists);
        }
コード例 #9
0
ファイル: SplitPackage.cs プロジェクト: pengjugame/hugula
        private static void CopyFileToSplitFolder(Dictionary <string, ABInfo> updateList)
        {
            string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);  //总的资源目录
            // ExportResources.CheckDirectory(updateOutPath);
            string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName); //特定版本资源目录用于资源备份
            // ExportResources.CheckDirectory(verPath);

            int allLen = updateList.Count;
            int i      = 0;

            Debug.LogFormat("CopyFileToSplitFolder.Count = {0}", updateList.Count);
            EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath + updateList.Count, 0.09f);

            string        sourcePath;
            string        outfilePath, outfileVerionPath;
            string        key, extension;
            uint          crc  = 0;
            StringBuilder erro = new StringBuilder();

            foreach (var k in updateList)
            {
                key = k.Key;//CUtils.GetAssetBundleName(k.Key);
                Debug.LogFormat(" update file = {0},{1},{2};", k.Key, k.Value.abName, k.Value.assetPath);
                sourcePath = Path.Combine(Application.dataPath, k.Value.assetPath);
                if (string.IsNullOrEmpty(k.Value.assetPath))
                {
                    continue;
                }
                if (!File.Exists(sourcePath)) //
                {
                    string e = string.Format("copy file ({0}) not Exists ", sourcePath);
                    Debug.LogWarning(e);
                    erro.AppendLine(e);
                    continue;
                }
                extension = System.IO.Path.GetExtension(key);
                crc       = (uint)k.Value.crc32;
                if (crc != 0)
                {
                    if (string.IsNullOrEmpty(extension))
                    {
                        key = InsertAssetBundleName(key + Common.CHECK_ASSETBUNDLE_SUFFIX, "_" + crc.ToString());
                    }
                    else if (extension == Common.DOT_BYTES)
                    {
                        key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX);
                        key = InsertAssetBundleName(key, "_" + crc.ToString());//
                    }
                    else
                    {
                        key = InsertAssetBundleName(key, "_" + crc.ToString());//
                    }
                }
                outfilePath       = Path.Combine(updateOutPath, key);
                outfileVerionPath = Path.Combine(verPath, key);
                // Debug.LogFormat("{0} copy to {1}", outfilePath, outfileVerionPath);
                //
                uint filelen     = 0;
                uint copyFileCrc = 0;

                var resType = HugulaSetting.instance.backupResType;
                if (resType == CopyResType.VerResFolder)
                {
                    FileHelper.CheckCreateFilePathDirectory(outfileVerionPath);
                    File.Copy(sourcePath, outfileVerionPath, true);// copy to v{d}/res folder
                    copyFileCrc = CrcCheck.GetLocalFileCrc(outfileVerionPath, out filelen);
                }

                if (resType == CopyResType.OneResFolder)
                {
                    FileHelper.CheckCreateFilePathDirectory(outfilePath);
                    File.Copy(sourcePath, outfilePath, true);// copy to /res folder
                    copyFileCrc = CrcCheck.GetLocalFileCrc(outfilePath, out filelen);
                }

                //check file crc
                if (copyFileCrc != crc)
                {
                    string e = string.Format("crc(source{0}!=copy{1}),path={2}", crc, copyFileCrc, outfilePath);
                    Debug.LogError(e);
                    erro.AppendLine(e);
                }
                EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file  =>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }
            Debug.Log(" copy  file complete!");
            EditorUtility.ClearProgressBar();
            string errContent = erro.ToString();

            if (!string.IsNullOrEmpty(errContent))
            {
                string tmpPath = BuildScript.GetAssetTmpPath();
                ExportResources.CheckDirectory(tmpPath);
                string outPath = Path.Combine(tmpPath, "error.txt");
                Debug.Log("write to path=" + outPath);
                using (StreamWriter sr = new StreamWriter(outPath, true))
                {
                    sr.WriteLine(" Error : " + System.DateTime.Now.ToString());
                    sr.Write(errContent);
                }
            }
        }
コード例 #10
0
ファイル: SplitPackage.cs プロジェクト: wwwsosokk/hugula
        /// <summary>
        ///   delete res folder
        /// </summary>
        public static void DeleteSplitPackageResFolder()
        {
            string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);

            ExportResources.DirectoryDelete(updateOutPath);
        }
コード例 #11
0
ファイル: SplitPackage.cs プロジェクト: pengjugame/hugula
        /// <summary>
        /// Creates the streaming crc list.
        /// </summary>
        /// <param name="sb">Sb.</param>
        public static uint CreateStreamingCrcList(FileManifest sb, string fileListName, bool firstExists = false, bool copyToResFolder = false)
        {
            sb.appNumVersion = CodeVersion.APP_NUMBER;
            var    crc32filename = CUtils.GetAssetName(fileListName);
            string tmpPath       = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            ExportResources.CheckDirectory(tmpPath);

            string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset";

            EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f);
            AssetDatabase.CreateAsset(sb, assetPath);

            string crc32outfilename = CUtils.GetRightFileName(fileListName);
            // Debug.Log("write to path=" + outPath);
            //读取crc
            string abPath     = string.Empty;
            string resOutPath = null;
            uint   fileSize   = 0;
            uint   fileCrc    = 0;

            if (copyToResFolder)
            {
                resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName);
                abPath     = Path.Combine(resOutPath, crc32outfilename);
                BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, DefaultBuildAssetBundleOptions);
                fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize);

                //copy crc list
                FileInfo finfo   = new FileInfo(abPath);
                var      resType = HugulaSetting.instance.backupResType;
                if (resType == CopyResType.VerResFolder)
                {
                    string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份
                    string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                    FileHelper.CheckCreateFilePathDirectory(newName);
                    if (File.Exists(newName))
                    {
                        File.Delete(newName);
                    }
                    finfo.CopyTo(newName);
                }

                if (resType == CopyResType.OneResFolder)
                {
                    string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录
                    string newName       = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                    FileHelper.CheckCreateFilePathDirectory(newName);
                    if (File.Exists(newName))
                    {
                        File.Delete(newName);
                    }
                    finfo.CopyTo(newName);
                }
            }
            else
            {
                abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename);
                BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions);
                fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize);
            }
            // CrcCheck.Clear();

            //copy first crc list
            if (!firstExists && File.Exists(abPath)) //如果没有首包 copy first package
            {
                string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString());
                string destFirst         = Path.Combine(UpdateOutPath, crc32FirstOutName);
                Debug.LogFormat("abpath={0},destFirst={1}:", abPath, destFirst);
                File.Copy(abPath, destFirst, true);
            }

            EditorUtility.ClearProgressBar();
            // File.Delete(assetPath);

            Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath);

            return(fileCrc);
        }
コード例 #12
0
        public static void doExportLua(string[] childrens)
        {
            BuildScript.CheckstreamingAssetsPath();

            string info  = "luac";
            string title = "build lua";

            EditorUtility.DisplayProgressBar(title, info, 0);

            var checkChildrens = AssetDatabase.GetAllAssetPaths().Where(p =>
                                                                        (p.StartsWith("Assets/Lua") ||
                                                                         p.StartsWith("Assets/Config")) &&
                                                                        (p.EndsWith(".lua"))
                                                                        ).ToArray();
            string path  = "Assets/Lua/";     //lua path
            string path1 = "Assets/Config/";  //config path
            string root  = CurrentRootFolder; //Application.dataPath.Replace("Assets", "");

            string crypName = "", crypEditorName = "", fileName = "", outfilePath = "", arg = "";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            //refresh directory
            if (checkChildrens.Length == childrens.Length)
            {
                DirectoryDelete(OutLuaPath);
            }
            CheckDirectory(OutLuaPath);

            float allLen = childrens.Length;
            float i      = 0;

            System.Diagnostics.Process luaProccess = new System.Diagnostics.Process();
            luaProccess.StartInfo.CreateNoWindow = true;
            luaProccess.StartInfo.WindowStyle    = System.Diagnostics.ProcessWindowStyle.Hidden;
            luaProccess.StartInfo.FileName       = luacPath;

            System.Diagnostics.Process luajit32Proccess = new System.Diagnostics.Process();
            luajit32Proccess.StartInfo.CreateNoWindow   = true;
            luajit32Proccess.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
            luajit32Proccess.StartInfo.FileName         = luajit32Path;
            luajit32Proccess.StartInfo.WorkingDirectory = luaWorkingPath;

            System.Diagnostics.Process luajit64Proccess = new System.Diagnostics.Process();
            luajit64Proccess.StartInfo.CreateNoWindow   = true;
            luajit64Proccess.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
            luajit64Proccess.StartInfo.FileName         = luajit64Path;
            luajit64Proccess.StartInfo.WorkingDirectory = luaWorkingPath;

            Debug.Log("luajit32Path:" + luajit32Path);
            Debug.Log("luajit64Path:" + luajit64Path);
            Debug.Log("luacPath:" + luacPath);

            string streamingAssetsPath = OutLuaBytesPath;  //Path.Combine(CurrentRootFolder, LuaTmpPath);

            DirectoryDelete(streamingAssetsPath);
            CheckDirectory(streamingAssetsPath);

            Debug.Log(streamingAssetsPath);
            luaProccess.StartInfo.WorkingDirectory = luaWorkingPath;

            foreach (string file in childrens)
            {
                string filePath = Path.Combine(root, file);
                fileName       = CUtils.GetAssetName(filePath);
                crypName       = file.Replace(path, "").Replace(path1, "").Replace(".lua", ".bytes").Replace("\\", "+").Replace("/", "+");
                crypEditorName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "+").Replace("/", "+");
                if (!string.IsNullOrEmpty(luajit32Path))// luajit32
                {
                    string override_name = CUtils.GetRightFileName(crypName);
                    string override_lua  = Path.Combine(streamingAssetsPath, override_name);
                    arg = "-b " + filePath + " " + override_lua; //for jit
                    // Debug.Log(arg);
                    luajit32Proccess.StartInfo.Arguments = arg;
                    luajit32Proccess.Start();
                    luajit32Proccess.WaitForExit();
                    sb.AppendLine("[\"" + crypName + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},");
                }
                if (!string.IsNullOrEmpty(luajit64Path)) //luajit64
                {
                    string crypName_64   = CUtils.InsertAssetBundleName(crypName, "_64");
                    string override_name = CUtils.GetRightFileName(crypName_64);
                    string override_lua  = Path.Combine(streamingAssetsPath, override_name);
                    arg = "-b " + filePath + " " + override_lua; //for jit
                    //  Debug.Log(arg);
                    luajit64Proccess.StartInfo.Arguments = arg;
                    luajit64Proccess.Start();
                    luajit64Proccess.WaitForExit();
                    sb.AppendLine("[\"" + crypName_64 + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},");
                }
                if (!string.IsNullOrEmpty(luacPath))                                //for editor
                {
                    string override_name = CUtils.GetRightFileName(crypEditorName); //CUtils.GetRightFileName(CUtils.InsertAssetBundleName(crypName,"_64"));
                    string override_lua  = Path.Combine(OutLuaPath, override_name);
#if UNITY_EDITOR_OSX && !UNITY_STANDALONE_WIN
                    arg = "-o " + override_lua + " " + filePath; //for lua
#else
                    arg = "-b " + filePath + " " + override_lua; //for jit
#endif
                    // Debug.Log(arg);
                    luaProccess.StartInfo.Arguments = arg;
                    luaProccess.Start();
                    luaProccess.WaitForExit();
                    sb.AppendLine("[\"" + crypEditorName + "(editor)\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},");
                }
                i++;
                EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
            }

            Debug.Log("lua:" + path + "files=" + childrens.Length + " completed");
            System.Threading.Thread.Sleep(100);

            //out md5 mapping file
            string tmpPath = BuildScript.GetAssetTmpPath();
            ExportResources.CheckDirectory(tmpPath);
            string outPath = Path.Combine(tmpPath, "lua_md5mapping.txt");
            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(sb.ToString());
            }

            EditorUtility.ClearProgressBar();
        }
コード例 #13
0
ファイル: SplitPackage.cs プロジェクト: pengjugame/hugula
        /// <summary>
        /// 1 读取首包,找出忽略文件
        /// </summary>
        /// <param name="ignoreFiles">Ignore files.</param>
        public static bool ReadFirst(out FileManifest firstCrcDict, out FileManifest streamingManifest, FileManifest extensionFileManifest)
        {
            // string title = "read first crc file list";
            bool firstExists = false;

            firstCrcDict = null;
            HugulaExtensionFolderEditor.instance = null;

            string readPath      = Path.Combine(FirstOutReleasePath, CUtils.platform);
            string firstFileName = CUtils.InsertAssetBundleName(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), "_v" + CodeVersion.CODE_VERSION.ToString());

            readPath = Path.Combine(readPath, firstFileName);
            Debug.Log(readPath);

            //check tmp directory
            if (!Directory.Exists("Assets/Tmp"))
            {
                Directory.CreateDirectory("Assets/Tmp");
            }

            // extensionFileManifest.Clear();
            //读取首包
            WWW abload = new WWW("file://" + readPath);

            if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null)
            {
                var      ab     = abload.assetBundle;
                Object[] assets = ab.LoadAllAssets();
                foreach (Object o in assets)
                {
                    if (o is FileManifest)
                    {
                        firstCrcDict = o as FileManifest;
                        firstExists  = true;
                        firstCrcDict.WriteToFile("Assets/Tmp/firstManifest.txt");
                        Debug.Log(firstCrcDict.Count);
                    }
                }
                ab.Unload(false);
            }
            else
            {
                Debug.LogWarning(abload.error + "no frist packeage in " + readPath);
            }
            abload.Dispose();

            //读取本地AB包AssetBundleManifest
            var fileListName = Common.CRC32_FILELIST_NAME;
            var url          = CUtils.PathCombine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(fileListName));

            Debug.Log(url);
            // url = CUtils.GetAndroidABLoadPath(url);
            AssetBundle assetbundle = AssetBundle.LoadFromFile(url);
            var         assets1     = assetbundle.LoadAllAssets <FileManifest>();
            uint        len         = 0;
            var         crc32       = CrcCheck.GetLocalFileCrc(url, out len);

            var streamingManifest1 = assets1[0];

            assetbundle.Unload(false);
            streamingManifest        = streamingManifest1;
            streamingManifest1.crc32 = crc32;
            Debug.Log(streamingManifest1.appNumVersion);
            Debug.Log(streamingManifest1.crc32);

            //读取忽略扩展包
            System.Action <string, int> AddExtensionFileManifest = (string ab, int priority1) =>
            {
                var abinfo = streamingManifest1.GetABInfo(ab);
                if (abinfo == null)
                {
                    abinfo = new ABInfo(ab, 0, 0, priority1);
                    streamingManifest1.Add(abinfo);
                }

                abinfo.priority = priority1;
                extensionFileManifest.Add(abinfo);
            };


            //读取忽略别名后缀
            // priority = FileManifestOptions.StreamingAssetsPriority;
            // var inclusionVariants = HugulaSetting.instance.inclusionVariants;
            // var allVariants = HugulaSetting.instance.allVariants;
            // string pattern = "";
            // string sp = "";
            // foreach (var s in allVariants)
            // {
            //     if (!inclusionVariants.Contains(s))
            //     {
            //         pattern += sp + @"\." + s + "$";
            //         sp = "|";
            //     }
            // }

            // if (!string.IsNullOrEmpty(pattern))
            // {
            //     // Debug.Log(pattern);
            //     var u3dList = ExportResources.getAllChildFiles(dinfo.FullName, pattern, null, true);
            //     foreach (var s in u3dList)
            //     {
            //         priority++;
            //         string ab = CUtils.GetAssetBundleName(s);
            //         ab = ab.Replace("\\", "/");
            //         AddExtensionFileManifest(ab, priority);
            //     }
            // }

            //读取手动加载排除资源
            string        firstStreamingPath = CUtils.realStreamingAssetsPath;
            DirectoryInfo dinfo    = new DirectoryInfo(firstStreamingPath);
            var           dircs    = dinfo.GetDirectories();
            var           priority = FileManifestOptions.ManualPriority;

            Debug.LogFormat("ManualPriority.priority={0}", priority);
            foreach (var dir in dircs)
            {
                var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false);
                foreach (var s in u3dList)
                {
                    priority++;
                    string ab = CUtils.GetAssetBundleName(s);
                    ab = ab.Replace("\\", "/");
                    AddExtensionFileManifest(ab, priority);
                }
            }

            //读取首包排除资源
            var firstLoadFiles = HugulaExtensionFolderEditor.instance.FirstLoadFiles;

            priority = FileManifestOptions.FirstLoadPriority;
            Debug.LogFormat("FirstLoadPriority.priority={0}", priority);
            var needLoadFirst = false;

            foreach (var s in firstLoadFiles)
            {
                var ab = CUtils.GetRightFileName(s);
                priority++;
                AddExtensionFileManifest(ab, priority);
                needLoadFirst = true;
            }

            if (!HugulaSetting.instance.spliteExtensionFolder)
            {
                needLoadFirst = false;
            }
            streamingManifest.hasFirstLoad = needLoadFirst;
            // AssetDatabase.SaveAssets();

            //读取自动下载资源
            var extensionFiles = HugulaExtensionFolderEditor.instance.ExtensionFiles;

            priority = FileManifestOptions.AutoHotPriority;
            Debug.LogFormat("AutoHotPriority.priority={0}", priority);

            foreach (var s in extensionFiles)
            {
                var ab = CUtils.GetRightFileName(s);
                priority++;
                AddExtensionFileManifest(ab, priority);
            }

            streamingManifest.WriteToFile("Assets/Tmp/streamingManifest0.txt");
            extensionFileManifest.WriteToFile("Assets/Tmp/manualFileList0.txt");
            EditorUtility.ClearProgressBar();
            return(firstExists);
        }
コード例 #14
0
ファイル: SplitPackage.cs プロジェクト: wwwsosokk/hugula
        /// <summary>
        /// Creates the streaming crc list.
        /// </summary>
        /// <param name="sb">Sb.</param>
        public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, string outPath = null)
        {
            var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
            string tmpPath       = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            ExportResources.CheckDirectory(tmpPath);
            string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset";

            EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f);

            string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua");

            using (StreamWriter sr = new StreamWriter(outTmpPath, false))
            {
                sr.Write(sb.ToString());
            }
            //
            //打包到streaming path
            AssetDatabase.Refresh();

            BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset;

            ba.bytes = File.ReadAllBytes(outTmpPath);
            AssetDatabase.CreateAsset(ba, assetPath);

            string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME);

            Debug.Log("write to path=" + outPath);
            Debug.Log(sb.ToString());
            //读取crc
            string abPath     = string.Empty;
            string resOutPath = null;

            if (string.IsNullOrEmpty(outPath))
            {
                abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename);
            }
            else
            {
                resOutPath = Path.Combine(outPath, ResFolderName);
                ExportResources.CheckDirectory(resOutPath);
                abPath = Path.Combine(resOutPath, crc32outfilename);
            }

            BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle);

            CrcCheck.Clear();
            uint fileSize = 0;
            uint fileCrc  = CrcCheck.GetLocalFileCrc(abPath, out fileSize);

            EditorUtility.ClearProgressBar();
            Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath);
            if (!string.IsNullOrEmpty(outPath))
            {
                string newName = Path.Combine(resOutPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                if (File.Exists(newName))
                {
                    File.Delete(newName);
                }
                FileInfo finfo = new FileInfo(abPath);
                if (!firstExists) //如果没有首包
                {
                    string destFirst = Path.Combine(outPath, crc32outfilename);
                    Debug.Log("destFirst:" + destFirst);
                    File.Copy(abPath, destFirst, true);
                    // finfo.CopyTo(destFirst);
                }
                finfo.MoveTo(newName);
                Debug.Log(" change name to " + newName);
            }
            return(fileCrc);
        }
コード例 #15
0
ファイル: SplitPackage.cs プロジェクト: wwwsosokk/hugula
        private static void CopyFileToSplitFolder(Dictionary <string, object[]> updateList)
        {
            string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录

            ExportResources.CheckDirectory(updateOutPath);
            string updateOutVersionPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份

            ExportResources.CheckDirectory(updateOutVersionPath);

            int allLen = updateList.Count;
            int i      = 0;

            EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath, 0.09f);

            string        sourcePath;
            string        outfilePath, outfileVerionPath;
            string        key, extension;
            uint          crc  = 0;
            StringBuilder erro = new StringBuilder();

            foreach (var k in updateList)
            {
                key        = k.Key;           //CUtils.GetAssetBundleName(k.Key);
                sourcePath = Path.Combine(Application.dataPath, k.Value[2].ToString());
                if (!File.Exists(sourcePath)) //
                {
                    string e = string.Format("copy file ({0}) not Exists ", sourcePath);
                    Debug.LogError(e);
                    erro.AppendLine(e);
                    continue;
                }
                extension = System.IO.Path.GetExtension(key);
                crc       = (uint)k.Value[0];
                if (crc != 0)
                {
                    if (string.IsNullOrEmpty(extension))
                    {
                        key = key + "_" + crc.ToString() + Common.CHECK_ASSETBUNDLE_SUFFIX;
                    }
                    else if (extension != Common.CHECK_ASSETBUNDLE_SUFFIX)
                    {
                        key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX);
                        key = CUtils.InsertAssetBundleName(key, "_" + crc.ToString());//
                    }
                    else
                    {
                        key = CUtils.InsertAssetBundleName(key, "_" + crc.ToString()); //
                    }
                }
                outfilePath       = Path.Combine(updateOutPath, key);
                outfileVerionPath = Path.Combine(updateOutVersionPath, key);

                FileHelper.CheckCreateFilePathDirectory(outfilePath);
                // FileHelper.CheckCreateFilePathDirectory(outfileVerionPath);

                File.Copy(sourcePath, outfilePath, true);// source code copy
                // File.Copy(sourcePath, outfileVerionPath, true);// source code copy

                //check file crc
                uint filelen     = 0;
                var  copyFileCrc = CrcCheck.GetLocalFileCrc(outfilePath, out filelen);
                if (copyFileCrc != crc)
                {
                    string e = string.Format("crc(source{0}!=copy{1}),path={2}", crc, copyFileCrc, outfilePath);
                    Debug.LogError(e);
                    erro.AppendLine(e);
                }
                EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file  =>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }
            Debug.Log(" copy  file complete!");
            EditorUtility.ClearProgressBar();
            string errContent = erro.ToString();

            if (!string.IsNullOrEmpty(errContent))
            {
                string tmpPath = BuildScript.GetAssetTmpPath();
                ExportResources.CheckDirectory(tmpPath);
                string outPath = Path.Combine(tmpPath, "error.txt");
                Debug.Log("write to path=" + outPath);
                using (StreamWriter sr = new StreamWriter(outPath, true))
                {
                    sr.WriteLine(" Error : " + System.DateTime.Now.ToString());
                    sr.Write(errContent);
                }
            }
        }
コード例 #16
0
ファイル: BuildScript.cs プロジェクト: wwwsosokk/hugula
        public static void GenerateAssetBundlesMd5Mapping(string[] allAssets)
        {
            string info = "Generate AssetBundles Md5Mapping ";

            EditorUtility.DisplayProgressBar("GenerateAssetBundlesMd5Mapping", info, 0);
            AssetImporter import  = null;
            float         i       = 0;
            float         allLen  = allAssets.Length;
            string        name    = "";
            string        nameMd5 = "";
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine("return {");
            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    Object s = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                    name = s.name.ToLower();

                    string line = string.Empty;
                    if (string.IsNullOrEmpty(import.assetBundleVariant))
                    {
                        line = "[\"" + import.assetBundleName + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    }
                    else
                    {
                        line = "[\"" + import.assetBundleName + "." + import.assetBundleVariant + "\"] = { name = \"" + name + "\", path = \"" + path + "\"},";
                    }

                    sb.AppendLine(line);
                    if (name.Contains(" "))
                    {
                        Debug.LogWarning(name + " contains space");
                    }
                }
                else
                {
                    //Debug.LogWarning(path + " import not exist");
                }
                EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);

                i++;
            }

            string[] spceil = new string[] { CUtils.platform, Common.CONFIG_CSV_NAME, Common.CRC32_FILELIST_NAME, Common.CRC32_VER_FILENAME };
            foreach (string p in spceil)
            {
                name    = GetAssetBundleName(p);
                nameMd5 = CUtils.GetRightFileName(name);
                string line = "[\"" + nameMd5 + "\"] ={ name = \"" + name + "\", path = \"" + p + "\" },";
                sb.AppendLine(line);
            }

            sb.AppendLine("}");
            string tmpPath = Path.Combine(Application.dataPath, TmpPath);

            ExportResources.CheckDirectory(tmpPath);
            EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", "write file to Assets/" + TmpPath + "Md5Mapping.txt", 0.99f);

            string outPath = Path.Combine(tmpPath, "md5mapping.txt");

            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(sb.ToString());
            }

            EditorUtility.ClearProgressBar();
            Debug.Log(info + " Complete! Assets/" + TmpPath + "md5mapping.txt");
        }
コード例 #17
0
ファイル: SplitPackage.cs プロジェクト: zuojiashun/hugula
        /// <summary>
        /// Creates the streaming crc list.
        /// </summary>
        /// <param name="sb">Sb.</param>
        public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, bool copyToResFolder = false)
        {
            var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
            string tmpPath       = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            ExportResources.CheckDirectory(tmpPath);
            string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset";

            EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f);

            string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua");

            using (StreamWriter sr = new StreamWriter(outTmpPath, false))
            {
                sr.Write(sb.ToString());
            }
            //
            //打包到streaming path
            AssetDatabase.Refresh();

            BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset;

            ba.bytes = File.ReadAllBytes(outTmpPath);
            AssetDatabase.CreateAsset(ba, assetPath);

            string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME);

            // Debug.Log("write to path=" + outPath);
            Debug.Log(sb.ToString());
            //读取crc
            string abPath     = string.Empty;
            string resOutPath = null;
            uint   fileSize   = 0;
            uint   fileCrc    = 0;

            if (copyToResFolder)
            {
                resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName);
                abPath     = Path.Combine(resOutPath, crc32outfilename);
                BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle);
                fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize);
                //copy first crc list
                string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString());
                if (!firstExists) //如果没有首包 copy first package
                {
                    string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName);
                    Debug.Log("destFirst:" + destFirst);
                    File.Copy(abPath, destFirst, true);
                }

                //copy crc list
                FileInfo finfo   = new FileInfo(abPath);
                var      resType = HugulaSetting.instance.backupResType;
                if (resType == CopyResType.VerResFolder)
                {
                    string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份
                    string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                    FileHelper.CheckCreateFilePathDirectory(newName);
                    if (File.Exists(newName))
                    {
                        File.Delete(newName);
                    }
                    finfo.CopyTo(newName);
                }

                if (resType == CopyResType.OneResFolder)
                {
                    string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录
                    string newName       = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                    FileHelper.CheckCreateFilePathDirectory(newName);
                    if (File.Exists(newName))
                    {
                        File.Delete(newName);
                    }
                    finfo.CopyTo(newName);
                }
            }
            else
            {
                abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename);
                BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle);
                fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize);
            }
            CrcCheck.Clear();

            EditorUtility.ClearProgressBar();

            Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath);

            return(fileCrc);
        }
コード例 #18
0
ファイル: SplitPackage.cs プロジェクト: zuojiashun/hugula
        /// <summary>
        /// 1 读取首包,找出忽略文件
        /// </summary>
        /// <param name="ignoreFiles">Ignore files.</param>
        public static bool ReadFirst(Dictionary <string, object[]> firstCrcDict, HashSet <string> manualFileList)
        {
            string title = "read first crc file list";

            CrcCheck.Clear();
            bool firstExists = false;

            string readPath      = Path.Combine(FirstOutReleasePath, CUtils.platform);
            string firstFileName = CUtils.InsertAssetBundleName(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), "_v" + CodeVersion.CODE_VERSION.ToString());

            readPath = Path.Combine(readPath, firstFileName);
            Debug.Log(readPath);

            manualFileList.Clear();
            //读取首包
            WWW abload = new WWW("file://" + readPath);

            if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null)
            {
                var        ab     = abload.assetBundle;
                Object[]   assets = ab.LoadAllAssets();
                BytesAsset ba;
                foreach (Object o in assets)
                {
                    ba = o as BytesAsset;
                    if (ba != null)
                    {
                        byte[] bytes   = ba.bytes;
                        string context = LuaHelper.GetUTF8String(bytes);
                        Debug.Log(context);
                        string[] split = context.Split('\n');
                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+{(\d+),(\d+)}");
                        float j = 1;
                        float l = split.Length;
                        foreach (var line in split)
                        {
                            System.Text.RegularExpressions.Match match = regex.Match(line);
                            if (match.Success)
                            {
                                //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value);
                                object[] val = new object[] { System.Convert.ToUInt32(match.Groups[2].Value), System.Convert.ToUInt32(match.Groups[3].Value) };
                                firstCrcDict[match.Groups[1].Value] = val;
                            }
                            //Debug.Log(line);
                            EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l);
                            j++;
                        }
                        firstExists = true;
                    }
                }
                ab.Unload(true);
            }
            else
            {
                Debug.LogWarning(abload.error + "no frist packeage in " + readPath);
            }
            abload.Dispose();

            //读取忽略扩展包
            string firstStreamingPath = CUtils.realStreamingAssetsPath;
            //读取忽略扩展文件夹
            DirectoryInfo dinfo = new DirectoryInfo(firstStreamingPath);
            var           dircs = dinfo.GetDirectories();

            foreach (var dir in dircs)
            {
                var u3dList = ExportResources.getAllChildFiles(dir.FullName, @"\.meta$|\.manifest$|\.DS_Store$", null, false);
                foreach (var s in u3dList)
                {
                    string ab = CUtils.GetAssetBundleName(s);
                    ab = ab.Replace("\\", "/");
                    manualFileList.Add(ab);
                    Debug.Log("extends folder:" + ab);
                }
            }

            //读取忽略别名后缀
            var    inclusionVariants = HugulaSetting.instance.inclusionVariants;
            var    allVariants       = HugulaSetting.instance.allVariants;
            string pattern           = "";
            string sp = "";

            foreach (var s in allVariants)
            {
                if (!inclusionVariants.Contains(s))
                {
                    pattern += sp + @"\." + s + "$";
                    sp       = "|";
                }
            }

            if (!string.IsNullOrEmpty(pattern))
            {
                Debug.Log(pattern);
                var u3dList = ExportResources.getAllChildFiles(dinfo.FullName, pattern, null, true);
                foreach (var s in u3dList)
                {
                    string ab = CUtils.GetAssetBundleName(s);
                    ab = ab.Replace("\\", "/");
                    manualFileList.Add(ab);
                    Debug.Log("inclusionVariants " + ab);
                }
            }

            var extensionFiles = HugulaExtensionFolderEditor.instance.ExtensionFiles;

            foreach (var s in extensionFiles)
            {
                var extName = CUtils.GetRightFileName(s);
                manualFileList.Add(extName);
                Debug.LogFormat("extensionFile:{0},md5={1}.", s, extName);
            }

            //从网络读取扩展加载列表 todo

            EditorUtility.ClearProgressBar();
            return(firstExists);
        }