Exemple #1
0
        public static void BuildFolder(string folderPath, FolderPackInfo parentInfo)
        {
            if (mFolderPackInfo == null)
            {
                TextAsset t = AssetDatabase.LoadMainAssetAtPath("Assets/Sprites/packInfo.json") as TextAsset;
                if (t)
                {
                    mFolderPackInfo = LitJson.JsonMapper.ToObject <Dictionary <string, FolderPackInfo> > (t.text);
                }
            }

            folderPath = GameFramework.Utility.Path.GetRegularPath(folderPath);

            if (folderPath == "Assets")
            {
                BuildFolder("Assets/Sprites", parentInfo);
                return;
            }

            if (folderPath.Contains("Assets/GameMain"))
            {
                throw new System.Exception($"GameMain里面是热更资源,需要打包的散图应该放在这个目录外面");
            }

            FolderPackInfo info = parentInfo;
            FolderPackInfo platformInfo;

            if (mFolderPackInfo != null && mFolderPackInfo.ContainsKey(folderPath))
            {
                mFolderPackInfo.TryGetValue(folderPath, out platformInfo);

                info = platformInfo;

                info.algorithm     = info.algorithm ?? parentInfo.algorithm;
                info.trimmode      = info.trimmode ?? parentInfo.trimmode;
                info.forcesquared  = info.forcesquared ?? parentInfo.forcesquared;
                info.extension     = info.extension ?? parentInfo.extension;
                info.dithertype    = info.dithertype ?? parentInfo.dithertype;
                info.textureformat = info.textureformat ?? parentInfo.textureformat;
                info.maxsize       = info.maxsize == 0 ? parentInfo.maxsize : info.maxsize;
                info.pixelformat   = info.pixelformat ?? parentInfo.pixelformat;
            }

            if (!Directory.Exists(folderPath))
            {
                throw new System.Exception($"{folderPath} is not directory path");
            }

            BuildOneTP(folderPath, info);

            foreach (string sub in Directory.GetDirectories(folderPath))
            {
                BuildFolder(sub, info);
            }
        }
Exemple #2
0
        public static void BuildOneTP(string folderPath, FolderPackInfo info)
        {
            if (Directory.Exists(folderPath))
            {
                if (!folderPath.Contains(" "))
                {
                    StringBuilder sb       = new StringBuilder("");
                    string[]      fileName = Directory.GetFiles(folderPath).Where(t => (Path.GetExtension(t) == ".png" || Path.GetExtension(t) == ".jpg")).ToArray();
                    string[]      tpsfile  = Directory.GetFiles(folderPath).Where(t => (Path.GetExtension(t) == ".tps")).ToArray();

                    if (tpsfile.Length > 0)
                    {
                        string sheetName = OutPutDirRoot + GetSheetName(folderPath);

                        foreach (var tps in tpsfile)
                        {
                            UnityEngine.Debug.Log($"使用 {tps} 配置打包图集,此文件夹对应的Json配置将失效");

                            string command = $" --sheet {sheetName}.{info.extension} --data {sheetName}.tpsheet ";
                            AutoBuild.processCommand(TPInstallDir, command + tps);
                        }
                    }
                    else
                    {
                        if (fileName.Length > 0)
                        {
                            GetImageName(fileName, ref sb);

                            string sheetName = OutPutDirRoot + GetSheetName(folderPath);

                            string command = $" --sheet {sheetName}.{info.extension} --data {sheetName}.tpsheet --extrude 0 --format unity-texture2d --trim-mode {info.trimmode} --default-pivot-point 0.5,0.5 --pack-mode Best --algorithm {info.algorithm} --max-size {info.maxsize} --size-constraints POT --opt {info.pixelformat} --texture-format {info.textureformat} --dither-type {info.dithertype} --scale 1 --disable-rotation ";
                            if (info.forcesquared == "true")
                            {
                                command = command + " --force-squared ";
                            }

                            AutoBuild.processCommand(TPInstallDir, command + sb.ToString());
                        }
                    }
                }
                else
                {
                    UnityEngine.Debug.LogError($"{folderPath} 不能有空格");
                }
            }
            else
            {
                UnityEngine.Debug.LogError($"{folderPath} is not directory path");
            }
        }