Esempio n. 1
0
    /// <summary>
    /// 运行texturePacker打包图集
    /// </summary>
    void ProcessTexturePacker(name_dic dic)
    {
        //创建目录
        string dicPath = atlasResPath + "/" + dic._atlasName;

        if (Directory.Exists(dicPath))
        {
            Directory.Delete(dicPath, true);
        }

        Directory.CreateDirectory(dicPath);
        AssetDatabase.Refresh();
        string pngPath = $"{dicPath}/{dic._atlasName}.png";
        int    _idx    = pngPath.IndexOf("Assets/");

        pngPath = pngPath.Substring(_idx);
        string dataPath = $"{dicPath}/{dic._atlasName}.txt";

        dataPath = dataPath.Substring(_idx);

        StringBuilder atlasPaths = new StringBuilder();
        string        inPath     = $"{_textureDic}/{dic._atlasName}";

        if (!Directory.Exists(inPath))
        {
            return;
        }

        string[] paths = Directory.GetFiles(inPath);
        foreach (var VARIABLE in paths)
        {
            if (VARIABLE.Contains(".meta"))
            {
                continue;
            }
            int    idx         = VARIABLE.IndexOf("Assets/");
            string _assetsPath = VARIABLE.Substring(idx);
            atlasPaths.Append(_assetsPath);
            atlasPaths.Append(" ");
        }
        string AtlasSize = "1024";
        //核心代码:  传入四个参数, 依次是commond命令载体, 打成整图后的图片路径, 生成的txt文件位置,   需要被打成图集的图片们(依次用空格间隔开)
        string commond = @" --sheet {0} --data {1} --format unity-texture2d --trim-mode None --pack-mode Best --algorithm Polygon --max-size " + AtlasSize + @" --size-constraints POT --disable-rotation --scale 1 {2}";
        string arg     = string.Format(commond, pngPath, dataPath, atlasPaths.ToString());

        EditorUtility.DisplayProgressBar("message", "texturePacker", 0.1f);
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        process.StartInfo.Arguments              = arg;
        process.StartInfo.UseShellExecute        = false;
        process.StartInfo.FileName               = @"TexturePacker.exe";
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError  = true;
        process.Start();
        process.WaitForExit();
        process.Dispose();
        EditorUtility.ClearProgressBar();
        AssetDatabase.Refresh();
    }
Esempio n. 2
0
 private void OnEnable()
 {
     atlasResPath = Application.dataPath + "/PracticeAssets/Resources/atlas";
     _textureDic  = Application.dataPath + "/PracticeAssets/Resources/texture";
     _atlasDic    = Directory.GetDirectories(_textureDic);
     list_dic.Clear();
     foreach (var variable in _atlasDic)
     {
         string [] split     = variable.Split('\\');
         string    atlasName = split[split.Length - 1];
         name_dic  dic       = new name_dic();
         dic._atlasDic  = variable;
         dic._atlasName = atlasName;
         list_dic.Add(dic);
     }
 }