此插件是Unity的内置包,可在包管理中找到,作用是识别PSD格式的图片图层。
先写一个编辑器脚本,命名为 “PSDImporterOverride”,放在Editor目录下 :
1 using UnityEditor.Experimental; 2 using UnityEditor.Experimental.AssetImporters; 3 using UnityEngine; 4 5 namespace UnityEditor.U2D.PSD 6 { 7 [ScriptedImporter(1, "psd", AutoSelect = false)] 8 internal class PSDImporterOverride : PSDImporter 9 { 10 11 [MenuItem("Assets/2D Importer/Change PSD File Importer", false, 30)] 12 static void ChangeImporter() 13 { 14 foreach (var obj in Selection.objects) 15 { 16 var path = AssetDatabase.GetAssetPath(obj); 17 var ext = System.IO.Path.GetExtension(path); 18 if (ext == ".psd") 19 { 20 var importer = AssetImporter.GetAtPath(path); 21 if (importer is PSDImporterOverride) 22 { 23 Debug.Log(string.Format("{0} is now imported with TextureImporter", path)); 24 AssetDatabaseExperimental.ClearImporterOverride(path); 25 } 26 else 27 { 28 Debug.Log(string.Format("{0} is now imported with PSDImporter", path)); 29 AssetDatabaseExperimental.SetImporterOverride<PSDImporterOverride>(path); 30 } 31 } 32 } 33 } 34 } 35 }
将PSD文件放到Unity资源中,右键选择 2DImporter >> Change PSD File Importer
然后psd文件就成了一个预制体,里面包含了图层哦~ 每个图层都是一个Sprite图像。