예제 #1
0
        void Show_Config(SpriteToolConfigData config)
        {
            {
                GUILayout.Space(10);
                GUILayout.BeginVertical();
                // 路径
                GUILayout.Label("TexturePacker 路径");
                GUILayout.BeginHorizontal();
                if (!File.Exists(config._strTPExePath))
                {
                    GUILayout.Label("<color=red>请重新选择TexturePacker.exe的路径</color>", _style);
                }
                else
                {
                    GUILayout.Label("<color=green>" + config._strTPExePath + "</color>", _style);
                }
                if (GUILayout.Button("浏览...", GUILayout.MinWidth(20)))
                {
                    config._strTPExePath = EditorUtility.OpenFilePanel("选择TexturePacker.exe", "", "exe");
                    Debug.Log("<color=green>[log]</color>---" + config._strTPExePath);
                }
                GUILayout.EndHorizontal();

                //GUILayout.BeginHorizontal();
                _config._nMaxWidth  = EditorGUILayout.IntField("最大尺寸_宽:", _config._nMaxWidth);
                _config._nMaxHeight = EditorGUILayout.IntField("最大尺寸_高:", _config._nMaxHeight);
                //GUILayout.EndHorizontal();

                _config._eAlgorithm = (SpriteToolConfigData.Algorithm)EditorGUILayout.EnumPopup("Algorithm:", _config._eAlgorithm);

                //// 自动使用TrueColor
                //_config._bPackAutoTrueColor = GUILayout.Toggle(_config._bPackAutoTrueColor, "打出的图集自动使用TrueColor");

                //// 自动不使用mipmap
                //_config._bPackAutoNoMipmap = GUILayout.Toggle(_config._bPackAutoNoMipmap, "打出的图集不使用mipmap");


                GUILayout.EndVertical();
            }
        }
예제 #2
0
        private void PackSprites(string strPackFolderAbsPath, DefaultPackType packType)
        {
            // 检测配置是否有
            SpriteToolConfigData configData = AssetDatabase.LoadAssetAtPath <SpriteToolConfigData>(SpriteToolConfigData._strConfigAssetPath);

            if (configData == null ||
                !File.Exists(configData._strTPExePath))
            {
                if (EditorUtility.DisplayDialog("错误", "请先配置TexturPacker.exe的路径!", "去配置", "Cancel"))
                {
                    SpriteToolConfigEditor.AddWindow();
                }
                return;
            }

            // 打包的图集所在文件夹
            string packFolder = strPackFolderAbsPath;

            string strTpsheetPath = string.Empty;
            string strPngPath     = string.Empty;

            if (_owObj == null)
            {
                // 选择保存路径
                string strTargetPath = EditorUtility.SaveFilePanel("保存", Application.dataPath, Path.GetFileNameWithoutExtension(strPackFolderAbsPath), "png");
                if (strTargetPath.Length == 0)
                {
                    return;
                }
                string strSaveFileName = Path.GetFileNameWithoutExtension(strTargetPath);
                strTargetPath = Path.GetDirectoryName(strTargetPath);

                strTpsheetPath = strTargetPath + "/" + strSaveFileName + ".txml";
                strPngPath     = strTargetPath + "/" + strSaveFileName + ".png";
            }
            else
            {
                string strOWObjAssetPath = AssetDatabase.GetAssetPath(_owObj);
                // 源文件所在文件夹
                string strOWFileFolder = Path.GetDirectoryName(TranslateAssetPathToAbspath(strOWObjAssetPath));
                // 源文件名称,没有后缀名
                string strOWPngFileName = Path.GetFileNameWithoutExtension(strOWObjAssetPath);

                strTpsheetPath = strOWFileFolder + "/" + strOWPngFileName + ".txml";
                strPngPath     = strOWFileFolder + "/" + strOWPngFileName + ".png";
            }


            // 先删除当前已经存在的同名文件
            if (File.Exists(strTpsheetPath))
            {
                File.Delete(strTpsheetPath);
            }
            if (File.Exists(strPngPath))
            {
                File.Delete(strPngPath);
            }
            //   string commandText = " --sheet {0}.png --data {1}.xml --format sparrow --trim-mode None --pack-mode Best  --algorithm MaxRects --max-size 2048 --size-constraints POT  --disable-rotation --scale 1 {2}";
            string strPackCmd = "--sheet {0} {1} --data {2} --format {3} --trim-mode {4} --pack-mode {5} --max-width {6} ";

            strPackCmd += "--max-height {7} --algorithm {8} --size-constraints {9} --opt {10}";
            strPackCmd  = string.Format(strPackCmd,
                                        strPngPath,
                                        packFolder,
                                        strTpsheetPath,
                                        "sparrow",
                                        "None",
                                        "Best",
                                        configData._nMaxWidth,
                                        configData._nMaxWidth,
                                        configData._eAlgorithm,
                                        "POT",
                                        GeneratePackExtraParam(packType)
                                        );
            // 生成执行参数
            //         string strPackCmd = string.Format("--data {0} --format sparrow --trim-mode None --pack-mode Best  --sheet {1} {2} --max-width {3} --max-height {4} --algorithm {5} {6}",
            //             strTpsheetPath,
            //             strPngPath,
            //             packFolder,
            //             configData._nMaxWidth, configData._nMaxHeight,
            //             configData._eAlgorithm.ToString(),
            //             GeneratePackExtraParam(packType));
            Debug.Log("<color=green>参数:" + strPackCmd + "</color>");

            // 执行命令行
            try
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName        = configData._strTPExePath;
                p.StartInfo.Arguments       = strPackCmd;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow  = true;
                p.Start();
            }
            catch (System.Exception ex)
            {
                Debug.LogError("<color=red>[Error]</color>---" + "Process Error : " + ex.Message);
                EditorUtility.DisplayDialog("执行出错", "执行出错:" + ex.Message, "好吧");
            }
        }
예제 #3
0
 void Show_OutPut(SpriteToolConfigData config)
 {
     GUILayout.Space(10);
     GUILayout.BeginVertical();
 }