diff --git a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js index 8cb3947..d30ee35 100644 --- a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js +++ b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js @@ -106,11 +106,34 @@ function s2t(t) { return stringIDToTypeID(t) } if (this.saveFolder === null) { return; } + this.documentName = app.activeDocument.name.slice(0, -4); + + // 导出整个psd作为png参考图 + var i, j, k, len, ref1, removeFiles; + var baseFolder = Folder(this.saveFolder + "/" + this.documentName); + if (baseFolder.exists) { + removeFiles = baseFolder.getFiles(); + for (i = j = 0, ref1 = removeFiles.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) { + if (removeFiles[i].name.startsWith(this.documentName) && removeFiles[i].name.endsWith('.png')) { + removeFiles[i].remove(); + } + } + baseFolder.remove(); + } + baseFolder.create(); + saveFile = new File(baseFolder.fsName + "/" + "__background__.png"); + options = new ExportOptionsSaveForWeb(); + options.format = SaveDocumentType.PNG; + options.PNG8 = false; + options.optimized = true; + options.interlaced = false; + app.activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, options); + + copiedDoc = app.activeDocument.duplicate(app.activeDocument.name.slice(0, -4) + '.copy.psd'); copiedDoc.quickMaskMode = false; Util.deselectLayers(); - var legal = this.checkLayerName(copiedDoc); if (!legal) { copiedDoc.close(SaveOptions.DONOTSAVECHANGES); @@ -135,7 +158,20 @@ function s2t(t) { return stringIDToTypeID(t) } if (after_close) { return app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); } - return alert('导出完成!'); + + var scriptFolder = new File($.fileName).path; + var batFileName = scriptFolder + "/run_step2.bat"; + + var batFile = new File(batFileName); + batFile.open("w"); + batFile.writeln("cd /d %~dp0"); + // -src image -dst image_3 + batFile.writeln("start step2.exe -src " + baseFolder.fsName + " -dst "+ baseFolder.fsName + "_output"); + batFile.close(); + + batFile = new File(batFileName); + batFile.execute(); + return; }; Baum.prototype.selectDocumentArea = function (document) { @@ -242,6 +278,42 @@ function s2t(t) { return stringIDToTypeID(t) } var ref1 = root.layers for (var j = 0; j < ref1.length; j++) { var layer = ref1[j]; + //使用别名替换关键字符 + if (layer.typename === 'ArtLayer') + { + if (layer.kind !== LayerKind.TEXT) // 图片 + { + var ss = layer.name.split("@"); + var opt = Util.parseOption(ss[1]); + + if (layer.name.startsWith("%")) + { + layer.name = layer.name.substring(1, layer.name.length); + if (Util.isEmptyObject(opt) || !opt["图片"]) + { + layer.name += "@图片"; + } + }else if (layer.name.startsWith("$")) + { + layer.name = layer.name.substring(1, layer.name.length); + if (Util.isEmptyObject(opt)) + { + layer.name += "@图片"; + } + else + { + layer.name += ",图片"; + } + layer.name += "=导出"; + } + + if (layer.name.indexOf("@图片") < 0 && layer.name.indexOf(",图片") < 0) + { + layer.name = "#" + layer.name; + } + } + } + var ss = layer.name.split("@"); //忽略但保留父节点宽高影响,则不移除 if (Util.isInferiorIgnoreByName(ss[0])) { @@ -311,9 +383,9 @@ function s2t(t) { return stringIDToTypeID(t) } } //文件名合规检测 - var reg = /^[0-9a-zA-Z"_""\-"]*$/g; + var reg = /^[0-9a-zA-Z\u4e00-\u9fa5"_""\-"]*$/g; if (!reg.test(ss[0])) { - alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_") + alert("\"" + layer.name + "\" 名字不合法,只能含有中文、英文、数字、-、_") return false; } @@ -663,7 +735,6 @@ function s2t(t) { return stringIDToTypeID(t) } if (opt['全屏']) { hash['full'] = "True"; hash['stretchxy'] = "True"; } if (opt['竖直列表']) { hash['type'] = "List"; hash['scroll'] = "vertical"; } if (opt['水平列表']) { hash['type'] = "List"; hash['scroll'] = "horizontal"; } - if (opt['图片']) { hash['imageName'] = opt['图片']; } else { hash['imageName'] = name; } if (opt['遮罩']) { hash['type'] = "Mask"; hash['mask'] = "hard" } //按钮可以覆盖遮罩,并在按钮上用遮罩组件 if (opt['按钮']) { hash['type'] = "Button"; } @@ -673,6 +744,7 @@ function s2t(t) { return stringIDToTypeID(t) } if (opt['进度条']) { hash['type'] = "Slider"; } if (opt['滚动条']) { hash['type'] = "Scrollbar"; } if (opt['开关']) { hash['type'] = "Toggle"; } + if (opt['图片']) { hash['imageName'] = name; } if (opt['预制体']) { hash['type'] = "Prefab"; if (layer.typename !== 'ArtLayer') { @@ -863,28 +935,8 @@ function s2t(t) { return stringIDToTypeID(t) } var outputDoc PsdToImage.prototype.run = function (document, saveFolder, documentName) { - var i, j, k, len, ref1, removeFiles, results, snapShotId, target, targets; + var k, len, results, snapShotId, target, targets; this.baseFolder = Folder(saveFolder + "/" + documentName); - if (this.baseFolder.exists) { - removeFiles = this.baseFolder.getFiles(); - for (i = j = 0, ref1 = removeFiles.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) { - if (removeFiles[i].name.startsWith(documentName) && removeFiles[i].name.endsWith('.png')) { - removeFiles[i].remove(); - } - } - this.baseFolder.remove(); - } - - this.baseFolder.create(); - - // 导出整个psd作为png参考图 - saveFile = new File(this.baseFolder.fsName + "/" + "__background__.png"); - options = new ExportOptionsSaveForWeb(); - options.format = SaveDocumentType.PNG; - options.PNG8 = false; - options.optimized = true; - options.interlaced = false; - document.exportDocument(saveFile, ExportType.SAVEFORWEB, options); targets = this.allLayers(document); //snapShotId = Util.takeSnapshot(document); @@ -943,7 +995,7 @@ function s2t(t) { return stringIDToTypeID(t) } return } //预制体不切图 - if (opt['预制体']) { + if (opt['预制体'] || !opt['图片']) { return } fileNames.push(fileName); @@ -981,6 +1033,16 @@ function s2t(t) { return stringIDToTypeID(t) } // } if (!layer.isBackgroundLayer) { + if (opt['图片'] !== "导出") + { + fileName += "-noexport"; + } + + if (opt['九宫格']) + { + fileName += "-slice"; + } + this.snipImage(outputDoc, layer, opt); } @@ -1587,6 +1649,10 @@ function s2t(t) { return stringIDToTypeID(t) } } }; + Util.isEmptyObject = function (obj) { + for (var key in obj) { if (obj.hasOwnProperty(key)) { return false; } } return true; + } + Util.parseOption = function (text) { var elements, j, len, opt, optText, ref1; if (!text) { diff --git a/.PhotoshopScript/JSZXPsd2Unity/run_step2.bat b/.PhotoshopScript/JSZXPsd2Unity/run_step2.bat new file mode 100644 index 0000000..3773845 --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity/run_step2.bat @@ -0,0 +1,2 @@ +cd /d %~dp0 +start step2.exe -src C:\Users\93685\Desktop\Sample -dst C:\Users\93685\Desktop\Sample_output diff --git a/.PhotoshopScript/JSZXPsd2Unity/step2.exe b/.PhotoshopScript/JSZXPsd2Unity/step2.exe new file mode 100644 index 0000000..eac7dde Binary files /dev/null and b/.PhotoshopScript/JSZXPsd2Unity/step2.exe differ diff --git a/.psd2uguiExamples/Sample.psd b/.psd2uguiExamples/Sample.psd index 2e8c8cd..ca2002d 100644 Binary files a/.psd2uguiExamples/Sample.psd and b/.psd2uguiExamples/Sample.psd differ diff --git a/README.md b/README.md index 4d20cf5..357cae1 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ ## 如何操作 ### psd数据导出 #### 图层名关键字 -1. `$<图层名>` : 图片切图导出、吸附用 -2. `!<图层名>` : 图片吸附用 +1. `$<图层名>` : 图片切图导出、吸附用,别名 `<图层名>@图片=导出` +2. `!<图层名>` : 图片吸附用,别名 `<图层名>@图片` 3. `<图层名>预制体:<资源唯一名称>` : 引用预制体 4. `<图层名>@九宫格` : 九宫格切图