UnityPSDLayoutTool2
This project is explicitly based on the original UnityPSDLayoutTool and adds compatibility fixes and workflow improvements for newer Unity versions.
Install / Use
/learn @mesakas/UnityPSDLayoutTool2README
![]()
UnityPSDLayoutTool2
本项目基于 UnityPSDLayoutTool,并在其基础上增加了新版本 Unity 兼容修复与工作流改进。
This project is explicitly based on the original UnityPSDLayoutTool and adds compatibility fixes and workflow improvements for newer Unity versions.
中文说明
Unity 版本支持
- 已验证可用:Unity 6000.3.7f1
- 原版插件面向较早期 Unity 版本;本项目在其基础上增加了对新版本 Unity 的适配。
相比 UnityPSDLayoutTool 的修改
- 适配新版 Unity 编辑器 API。
- 修复 PSD Unicode 解码,支持中文图层名与中文文本正确导入。
- 增加中文友好的字体回退策略,降低中文文本乱码/方块字问题。
- 增加更稳定的渲染顺序,减少相机角度变化导致的图层遮挡异常。
- 增加导出目录可配置能力(资源输出目录可调整)。
- 增加 Prefab 输出位置可配置:
- 默认:Prefab 输出到生成资源文件夹的同级目录
- 可选:Prefab 输出到生成资源文件夹内部
- 增加可选“目标 Canvas”对齐:
- 选择场景中的 Canvas 后,导入 UI 会按该 Canvas 像素坐标对齐
- 不选择时保持旧行为,自动创建 World Space Canvas
- 增加目标 Canvas 尺寸映射策略:
- 支持按 Canvas 尺寸缩放
- 支持“保持宽高比(不拉伸)”与“宽高独立缩放(可拉伸)”切换
- 修复透明度导入:
- 正确叠加 PSD 图层 Opacity 与蒙版 Alpha
- 文本对象同样会应用图层透明度
- 支持 Inspector 中英文切换(可持久化保存)。
- 本分支重命名:
- 插件目录:
Assets/PSDLayoutTool2 - 命名空间:
PsdLayoutTool2
安装
把以下目录复制到 Unity 项目中:
Assets/PSDLayoutTool2
使用方式
- 将
.psd文件放到 Unity 项目的Assets目录下。 - 在
Project面板选中该 PSD 文件。 - 在
Inspector中使用 PSD Layout Tool 2 的选项和按钮。

主要选项:
最大深度(Z)像素到单位(PPU)界面语言(中文 / English)使用 Unity UI目标 Canvas(可选)匹配目标 Canvas 尺寸保持宽高比(不拉伸)按名称自动设置锚点ROOT 默认使用全局锚点资源输出位置输出文件夹名Prefab 输出位置
主要操作:
导出图层为纹理在当前场景中布局生成预制体
Canvas 对齐模式(UI)
使用 Unity UI = true且目标 Canvas(可选)已选择:生成的根节点会作为RectTransform挂到目标 Canvas 下,坐标按 PSD 像素映射,便于与现有 UI 版式对齐。匹配目标 Canvas 尺寸 = true(默认):会按目标 Canvas 尺寸进行缩放映射,解决 PSD 分辨率与 Canvas 分辨率不一致导致的错位。- 若 Canvas 使用
Canvas Scaler / Scale With Screen Size,会优先按Reference Resolution对齐。
- 若 Canvas 使用
匹配目标 Canvas 尺寸 = false:保持 PSD 1:1 像素映射,适合你已经保证 PSD 与 Canvas 尺寸一致的情况。保持宽高比(不拉伸) = true(默认):等比缩放,避免 X/Y 比例不一致造成拉伸。保持宽高比(不拉伸) = false:按宽高分别缩放,可能出现拉伸,但能完全铺满目标 Canvas 尺寸。目标 Canvas(可选)留空或当前场景找不到该 Canvas:回退为旧行为,自动创建一个 World Space Canvas。目标 Canvas(可选)是按场景层级路径保存的;如果你重命名或移动了 Canvas,请在 Inspector 里重新选择一次。
透明度说明
- PSD 图层透明度(Opacity)会参与导出纹理与场景对象生成。
- 图层蒙版 Alpha 会与图层 Alpha 正确相乘,不再出现透明度异常。
- 文本层(UI Text / TextMesh)也会应用图层透明度。
隐藏层与重名处理
- 在 Photoshop 中隐藏的图层,包括被父文件夹隐藏的子图层,现在默认只导出贴图资源,不会生成场景对象,也不会进入 Prefab 结构。
- 隐藏的文本层也会按栅格化结果导出为贴图资源。
- 同一父级下如果存在同名图层或同名文件夹,导入时会自动追加稳定后缀,例如
_2、_3。 - 如果图层或文件夹名称包含文件系统非法字符(如
\\ / : * ? \" < > |),导出时会自动替换为安全名称。 - 这个唯一命名规则会参与重复导入时的更新/删除匹配;只要父级结构和同名项相对顺序不变,旧资源路径就会稳定复用。
命名锚点与图片保比例
- 仅在
Use Unity UI = true时生效。 - 同时适用于“目标 Canvas 对齐”模式和“自动创建 World Space Canvas”模式。
- 该功能通过 Inspector 选项控制,不会在导入时额外弹出确认框。
- 当图层或文件夹名称以这些前缀开头时,会自动设置锚点:
左上、左下、右上、右下、中间、左中、右中、上中、下中、上、下、左、右、全局。 - 前缀必须写在名称开头,例如:
左上关闭按钮、全局背景。 上 / 下 / 左 / 右会按单点锚点处理,不会做边缘拉伸。全局会让 UI 节点四边距为 0;如果该节点是图片,则会在四边距为 0 的基础上按比例覆盖父节点,不会被拉伸变形。- 如果文件夹本身带锚点前缀,则其中没有前缀的子项会默认继承父级锚点。
- 最外层 ROOT 可通过 Inspector 的
ROOT 默认使用全局锚点控制;开启后即使 ROOT 名称本身没有前缀,也会默认全拉伸到父 Canvas。 - 所有导入生成的 Unity UI
Image都会默认开启Image.preserveAspect = true,用于降低运行时意外拉伸风险。 - Inspector 中的
保持宽高比(不拉伸)只控制 PSD 到目标 Canvas 的坐标缩放策略,不等同于Image.preserveAspect。
Photoshop 兼容性(栅格化)
Photoshop 的智能对象(Smart Objects)不在此插件的解析支持范围内。导入前建议先对相关图层进行栅格化。
操作路径:
- 在 Photoshop 顶部菜单点击 Layer
- 点击 Rasterize
- 点击 All Layers(或按需栅格化目标图层)

特殊标签(与原版标签规则兼容)
标签解析规则:
- 标签匹配不区分大小写(例如
|button与|Button等效)。 - 可以在同一层名里组合多个标签(例如
Run|Animation|FPS=12)。 - 识别到的标签会从生成对象的名称中移除。
- 只有特定模式下标签才会生效(见下方“生效条件”说明)。
组图层标签(Folder / Group Layer)
|Animation:作用:把该组的子图层作为帧,生成 Sprite 动画;生效条件:Use Unity UI = false;备注:会生成.anim和.controller,并自动挂到对象上。|FPS=数字:作用:指定|Animation的帧率;生效条件:与|Animation同时使用;备注:示例:|FPS=12、|FPS=24。|Button:作用:把该组作为一个按钮容器并读取子图层状态;生效条件:Use Unity UI = true;备注:非 UI 模式下不会创建按钮。
动画命名示例:
- 组名:
HeroRun|Animation|FPS=12 - 子图层:
run_01,run_02,run_03...
按钮命名示例:
- 组名:
PlayButton|Button - 子图层:
Play_Up|Normal,Play_Down|Pressed,Play_Hover|Highlighted,Play_Disabled|Disabled
普通图层标签(Art Layer)
|Default/|Enabled/|Normal/|Up:作用:作为按钮默认状态(同义标签);适用场景:|Button组内。|Pressed:作用:作为按钮按下状态;适用场景:|Button组内。|Highlighted:作用:作为按钮高亮状态;适用场景:|Button组内。|Disabled:作用:作为按钮禁用状态;适用场景:|Button组内。|Text:作用:将“非文本图层”作为按钮文字图像子节点;适用场景:|Button组内,且该层不是文本层。
当前实现限制:
|Animation在Use Unity UI = true时暂未实现 UI 动画生成。|Button在Use Unity UI = false时暂未实现非 UI 按钮生成。|Button组中的“文本图层(Text Layer)”子节点尚未自动生成为按钮子文本对象。
许可证
MIT License,见 LICENSE.md。
Unity Version Support
- Verified working on: Unity 6000.3.7f1
- The original plugin targets much older Unity versions; this fork adds fixes to run on current Unity.
What Was Changed Compared to UnityPSDLayoutTool
The following changes were added on top of the original UnityPSDLayoutTool:
- Updated API compatibility for modern Unity editor versions.
- Fixed PSD Unicode string decoding so Chinese layer names/text import correctly.
- Added Chinese-friendly font fallback strategy for text import.
- Added deterministic render ordering to reduce angle-dependent layer overlap issues.
- Added configurable output folder behavior for generated assets.
- Added configurable prefab output mode:
- default: prefab saved as a sibling of the generated output folder
- optional: prefab saved inside the generated output folder
- Added optional target-canvas alignment for Unity UI:
- when a scene canvas is selected, generated UI is aligned in that canvas coordinate space
- when empty or not found, importer falls back to creating a world-space canvas
- Added target-canvas scaling strategy options:
- scale to target canvas size
- choose between "preserve aspect ratio (no stretch)" and "independent X/Y scaling (may stretch)"
- Fixed transparency import:
- correctly composes PSD layer opacity with mask alpha
- text objects also apply layer opacity
- Added inspector language switch (Chinese / English), persisted in EditorPrefs.
- Renamed plugin folder and namespace for this fork:
- Folder:
Assets/PSDLayoutTool2 - Namespace:
PsdLayoutTool2
Installation
Copy the folder below into your Unity project:
Assets/PSDLayoutTool2
Usage
- Put a
.psdfile under your Unity project'sAssetsdirectory. - Select the PSD file in the Project window.
- In Inspector, use PSD Layout Tool 2 options and buttons.

Main options include:
Maximum Depth (Z)Pixels To Units (PPU)Inspector Language(Chinese / English)Use Unity UITarget Canvas (Optional)Scale To Target CanvasPreserve Aspect Ratio (No Stretch)Auto Anchor By NameRoot Uses Global By DefaultOutput DirectoryOutput Folder NamePrefab Output
Actions:
Export Layers As TexturesLayout In Current SceneGenerate Prefab
Canvas Alignment Mode (UI)
- When
Use Unity UI = trueandTarget Canvas (Optional)is set, the generated root is created as aRectTransformunder that canvas and positioned in PSD pixel space. Scale To Target Canvas = true(default) scales PSD positions and sizes to the selected canvas rect, which fixes mismatches when PSD and canvas resolutions differ.- If the canvas uses
Canvas Scaler / Scale With Screen Size, mapping usesReference Resolutionfirst.
- If the canvas uses
Scale To Target Canvas = falsekeeps a strict 1:1 PSD pixel mapping.Preserve Aspect Ratio (No Stretch) = true(default) uses uniform scaling to avoid stretch when aspect ratios differ.Preserve Aspect Ratio (No Stretch) = falsescales X/Y independently, which may stretch but fills target canvas size exactly.- When
Target Canvasis empty or no longer found in scene, importer falls back to legacy behavior and creates a world-space canvas. Target Canvasis persisted by hierarchy path; if you rename or move the canvas, reselect it in Inspector.
Transparency Notes
- PSD layer opacity is applied during texture export and object generation.
- Mask alpha is correctly multiplied with layer alpha.
- Text layers (UI Text / TextMesh) also apply layer opacity.
Hidden Layers And Duplicate Names
- Layers hidden in Photoshop, including layers hidden by a parent folder, now export only texture assets by default. They do not create scene objects and are not included in generated prefabs.
- Hidden text layers are also rasterized and exported as texture assets.
- When sibling layers or folders share the same name, the importer adds stable suffixes such as
_2,_3to keep generated assets unique. - If a layer or folder name contains filesystem-illegal characters such as
\\ / : * ? \" < > |, the importer replaces them automatically with safe names. - The same stable naming is used by re-import conflict matching, so existing generated files continue to match as long as the parent structure and relative order of same-name siblings stay the same.
Name-Based Anchors And Image Aspect
- This only applies when
Use Unity UI = true. - It works in both target-canvas alignment mode and the fallback world-space canvas mode.
- This behavior is controlled through Inspector options and does not show an extra import-time confirmation dialog.
- When a layer or folder name starts with one of these prefixes, the importer automatically sets the anchor:
左上,左下,右上,右下,中间,左中,右中,上中,下中,上,下,左,右,全局. - The prefix must be at the start of the name, for example
左上CloseButtonor全局Background. 上 / 下 / 左 / 右are treated as point anchors, not edge stretch instructions.全局gives the UI node zero margins; if that node is an image, it additionally covers the parent while preserving aspect ratio instead of stretching.- If a folder has an anchor prefix, child items without their own prefix inherit the parent's anchor.
- The outer ROOT can default to `全
