{"id":19482549,"url":"https://github.com/zeroultra/psd2unity","last_synced_at":"2025-05-08T00:28:02.177Z","repository":{"id":64854869,"uuid":"461211308","full_name":"ZeroUltra/PSD2Unity","owner":"ZeroUltra","description":"PS中自动切图导入到Unity生成UGUI界面或场景","archived":false,"fork":false,"pushed_at":"2024-11-01T07:10:08.000Z","size":12469,"stargazers_count":50,"open_issues_count":1,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-16T13:34:16.231Z","etag":null,"topics":["photoshop","psd","unity"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZeroUltra.png","metadata":{"files":{"readme":".github/README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-19T14:12:18.000Z","updated_at":"2024-11-29T01:31:25.000Z","dependencies_parsed_at":"2023-11-07T13:28:23.653Z","dependency_job_id":"5f631790-2172-4030-a889-aed82dcdf42f","html_url":"https://github.com/ZeroUltra/PSD2Unity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FPSD2Unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FPSD2Unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FPSD2Unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroUltra%2FPSD2Unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZeroUltra","download_url":"https://codeload.github.com/ZeroUltra/PSD2Unity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231468021,"owners_count":18381174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["photoshop","psd","unity"],"created_at":"2024-11-10T20:11:08.902Z","updated_at":"2025-05-08T00:28:02.168Z","avatar_url":"https://github.com/ZeroUltra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSD2Unity\nPS中导出切图到Untiy生成UGUI界面和场景\n\n## How to use\n\n**注: 图层名不要重名,不然只会保存一个**\n\n1. 通过UnityPackageManager导入包\n\n2. 将`ExportToPNG` ps脚本放在PhotoShop软件`Scripts`文件夹\n\n   ![image-20220219221748479](img/image-20220219221748479.png)\n\n3. PS中操作\n\n   ![image-20220219221854573](img/image-20220219221854573.png)\n\n   ​\t\t\t\t\t![image-20220219221920658](img/image-20220219221920658.png)\n\n   * `Write Layer Pngs`  将ps中图层导出png\n   * `Ignore hidden Layer` 忽略隐藏图层 ,如果勾选则不导出PS中隐藏图层\n   * `Write a template PNG` 写入一张模板\n   * `User groups` 是否使用组,勾选会按PS组导出\n   * `Write Json` 是否导出json, Unity中会用到\n   * `Trim Whitespace` 是否去除空白,不勾选则导出原始画布尺寸\n\n   ***\n\n   \n\n   ![](img/0.gif)\n\n   等待一段时间之后,在对应的文件夹会生成相应的资源文件\n\n   ![image-20220219222232023](img/image-20220219222232023.png)\n\n   ***\n\n   tip:添加快捷键\n\n   ![](img/ps.png)\n\n4. 将生成的文件导入Unity中,然后将图片格式设置成`Sprite`\n\n5. 选中生成的`xxx.ps.json`,然后右键`PSDTools/PSD2Scene`或者`PSDTools/PSD2UGUI`生成界面\n\n   ![gif](img/1.gif)\n\n6. 可以导入示例查看具体使用\n\n   ![](img/20230728172510.png)\n\n---\n\n### ChangeLog\n\n### 1.0.7\n\n* 增加了当未找到图时两个回调事件,方便使用通用的小图\n\n  ```c#\n  /// \u003csummary\u003e\n  /// 当创建2d找不到png时，响应事件 返回值true表示打印错误路径信息，false表示忽略错误\n  /// \u003c/summary\u003e\n  public static event System.Func\u003cstring, SpriteRenderer, bool\u003e OnMissingPngWith2D;\n  \n  /// \u003csummary\u003e\n  /// 当创建UI找不到png时，响应事件 返回值true表示打印错误路径信息，false表示忽略错误\n  /// \u003c/summary\u003e\n  public static event System.Func\u003cstring, Image, bool\u003e OnMissingPngWithUI;\n  \n  //使用示例\n  [InitializeOnLoadMethod]\n  static void InitMethod()\n  {\n      //监听psd创建通用小物体\n      PSDCreateor.OnMissingPngWith2D -= OnMissingPng;\n      PSDCreateor.OnMissingPngWith2D += OnMissingPng;\n  }\n  \n  private static bool OnMissingPng(string pngPath, SpriteRenderer sr)\n  {\n      if (pngPath.Contains(\"Common\", StringComparison.OrdinalIgnoreCase))\n      {\n          string fileName = Path.GetFileName(pngPath);\n          string newPath = $\"Assets/Assetbundle/sprites/common/{fileName}\";\n          var sp = (Sprite)AssetDatabase.LoadAssetAtPath(newPath, typeof(Sprite));\n          if (sp != null)\n          {\n              sr.sprite = sp;\n          }\n          else\n          {\n              Debug.LogError(\"没有找到通用图：\" + newPath);\n          }\n      }\n      return false;\n  }\n  \n  ```\n\n  \n\n### 1.0.6\n\n* 之前保存为.ps.json格式,现在改成.ps.data格式(.json会默认为unity的textasset,会参与打AssetBundle, .data则不会,参考:[Unity - Manual: Text assets (unity3d.com)](https://docs.unity3d.com/Manual/class-TextAsset.html))\n* 不在自动生成Prefab预制体(自己手动拖一下吧)\n* 调整代码,将菜单order=1500\n\n### 1.0.5\n\n* 修改成UnityPackage\n\n### 1.0.4\n\n* 修改了json结构,更加清晰明了\n\n### 1.0.3\n\n* 添加提示:同一个组下有相同图层名,导致未能正确保存问题\n\n### 1.0.2\n\n* 修复User groups(按组导出)时没有按照ps中结构正确生成组的bug\n* 添加了导出png图片过大问题,也就是导出时写入了xmp数据导致图片内存异常大\n\n### 参考\n\n ❤️ ❤️ ❤️ ❤️ ❤️\n\n[Spine 2D - LayersToPNG.jsx fix for Photoshop CC (github.com)](https://gist.github.com/nzhul/5ef666d5960423fed0de)\n\n[EsotericSoftware/spine-scripts: Scripts to export from PhotoShop and other tools to Spine's JSON data format. (github.com)](https://github.com/EsotericSoftware/spine-scripts)\n\n[解决Photoshop CC导出JPG文件过大的问题)](https://www.peb.cc/windows/48.html)\n\n### 其他\n\n由于使用了`Newtonsoft.Json`(至少版本\u003e=unity2021.3.16自带了)\n\n如果提示缺失该程序集找到PSD2Unity下的`Editor/NewtonsoftJson~`把后面的`~`去除即可\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroultra%2Fpsd2unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeroultra%2Fpsd2unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroultra%2Fpsd2unity/lists"}