commit 40a3afb50b836a0cde6052777d6342a7804ac9c2 Author: Soviby <936858871@qq.com> Date: Tue Oct 8 23:19:05 2024 +0800 初版 diff --git a/.PhotoshopScript/JSZXPsd2Unity.meta b/.PhotoshopScript/JSZXPsd2Unity.meta new file mode 100644 index 0000000..f056eab --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b9fb3fa7ca06e2642a3bf907705706f9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js new file mode 100644 index 0000000..fb9cd15 --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js @@ -0,0 +1,1623 @@ +// 日本語認識用 +"object" != typeof JSON && (JSON = {}), function () { "use strict"; function f(t) { return 10 > t ? "0" + t : t } function this_value() { return this.valueOf() } function quote(t) { return rx_escapable.lastIndex = 0, rx_escapable.test(t) ? '"' + t.replace(rx_escapable, function (t) { var e = meta[t]; return "string" == typeof e ? e : "\\u" + ("0000" + t.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + t + '"' } function str(t, e) { var r, n, o, u, f, a = gap, i = e[t]; switch (i && "object" == typeof i && "function" == typeof i.toJSON && (i = i.toJSON(t)), "function" == typeof rep && (i = rep.call(e, t, i)), typeof i) { case "string": return quote(i); case "number": return isFinite(i) ? i + "" : "null"; case "boolean": case "null": return i + ""; case "object": if (!i) return "null"; if (gap += indent, f = [], "[object Array]" === Object.prototype.toString.apply(i)) { for (u = i.length, r = 0; u > r; r += 1)f[r] = str(r, i) || "null"; return o = 0 === f.length ? "[]" : gap ? "[\n" + gap + f.join(",\n" + gap) + "\n" + a + "]" : "[" + f.join(",") + "]", gap = a, o } if (rep && "object" == typeof rep) for (u = rep.length, r = 0; u > r; r += 1)"string" == typeof rep[r] && (n = rep[r], o = str(n, i), o && f.push(quote(n) + (gap ? ": " : ":") + o)); else for (n in i) Object.prototype.hasOwnProperty.call(i, n) && (o = str(n, i), o && f.push(quote(n) + (gap ? ": " : ":") + o)); return o = 0 === f.length ? "{}" : gap ? "{\n" + gap + f.join(",\n" + gap) + "\n" + a + "}" : "{" + f.join(",") + "}", gap = a, o } } var rx_one = /^[\],:{}\s]*$/, rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, rx_four = /(?:^|:|,)(?:\s*\[)+/g, rx_escapable = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; "function" != typeof Date.prototype.toJSON && (Date.prototype.toJSON = function () { return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z" : null }, Boolean.prototype.toJSON = this_value, Number.prototype.toJSON = this_value, String.prototype.toJSON = this_value); var gap, indent, meta, rep; "function" != typeof JSON.stringify && (meta = { "\b": "\\b", " ": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" }, JSON.stringify = function (t, e, r) { var n; if (gap = "", indent = "", "number" == typeof r) for (n = 0; r > n; n += 1)indent += " "; else "string" == typeof r && (indent = r); if (rep = e, e && "function" != typeof e && ("object" != typeof e || "number" != typeof e.length)) throw Error("JSON.stringify"); return str("", { "": t }) }), "function" != typeof JSON.parse && (JSON.parse = function (text, reviver) { function walk(t, e) { var r, n, o = t[e]; if (o && "object" == typeof o) for (r in o) Object.prototype.hasOwnProperty.call(o, r) && (n = walk(o, r), void 0 !== n ? o[r] = n : delete o[r]); return reviver.call(t, e, o) } var j; if (text += "", rx_dangerous.lastIndex = 0, rx_dangerous.test(text) && (text = text.replace(rx_dangerous, function (t) { return "\\u" + ("0000" + t.charCodeAt(0).toString(16)).slice(-4) })), rx_one.test(text.replace(rx_two, "@").replace(rx_three, "]").replace(rx_four, ""))) return j = eval("(" + text + ")"), "function" == typeof reviver ? walk({ "": j }, "") : j; throw new SyntaxError("JSON.parse") }) }(); +// Generated by CoffeeScript 1.12.7 + +//查看ps字段用 +function checkDesc(desc) { + var c = desc.count, + str = ''; + for (var i = 0; i < c; i++) { + str += 'Key ' + i + ' = ' + t2s(desc.getKey(i)) + ': ' + desc.getType(desc.getKey(i)) + ' = ' + getValues(desc, i) + '\n'; + }; + $.writeln(str); + alert(str); +}; +function getValues(desc, keyNum) { + var kTypeID = desc.getKey(keyNum); + switch (desc.getType(kTypeID)) { + case DescValueType.OBJECTTYPE: + return (desc.getObjectValue(kTypeID) + "_" + t2s(desc.getObjectType(kTypeID))); + break; + case DescValueType.LISTTYPE: + + return desc.getList(kTypeID); + break; + case DescValueType.REFERENCETYPE: + return desc.getReference(kTypeID); + break; + case DescValueType.BOOLEANTYPE: + return desc.getBoolean(kTypeID); + break; + case DescValueType.STRINGTYPE: + return desc.getString(kTypeID); + break; + case DescValueType.INTEGERTYPE: + return desc.getInteger(kTypeID); + break; + case DescValueType.LARGEINTEGERTYPE: + return desc.getLargeInteger(kTypeID); + break; + case DescValueType.DOUBLETYPE: + return desc.getDouble(kTypeID); + break; + case DescValueType.ALIASTYPE: + return desc.getPath(kTypeID); + break; + case DescValueType.CLASSTYPE: + return desc.getClass(kTypeID); + break; + case DescValueType.UNITDOUBLE: + return (desc.getUnitDoubleValue(kTypeID) + "_" + t2s(desc.getUnitDoubleType(kTypeID))); + break; + case DescValueType.ENUMERATEDTYPE: + return (t2s(desc.getEnumerationValue(kTypeID)) + + "_" + t2s(desc.getEnumerationType(kTypeID))); + break; + case DescValueType.RAWTYPE: + var tempStr = desc.getData(kTypeID); + var rawData = new Array(); + for (var tempi = 0; tempi < tempStr.length; tempi++) { + rawData[tempi] = tempStr.charCodeAt(tempi); + } + return rawData; + break; + default: + + break; + }; +}; +function t2s(t) { return typeIDToStringID(t) } +function s2t(t) { return stringIDToTypeID(t) } + + +(function () { + var Baum, PsdToImage, PsdToJson, Util, baum, setup, + bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; }, + indexOf = [].indexOf || function (item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + + Baum = (function () { + function Baum() { + this.runOneFile = bind(this.runOneFile, this); + } + + Baum.version = '0.6.1'; + Baum.maxLength = 2048; + + Baum.prototype.run = function () { + var filePath, filePaths, j, len; + this.saveFolder = null; + if (app.documents.length === 0) { + filePaths = File.openDialog("Select a file", "*", true); + for (j = 0, len = filePaths.length; j < len; j++) { + filePath = filePaths[j]; + app.activeDocument = app.open(File(filePath)); + this.runOneFile(true); + } + } else { + this.runOneFile(false); + } + }; + + Baum.prototype.runOneFile = function (after_close) { + var copiedDoc; + if (this.saveFolder === null) { + this.saveFolder = Folder.selectDialog("选择目标文件夹"); + } + if (this.saveFolder === null) { + return; + } + this.documentName = app.activeDocument.name.slice(0, -4); + 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); + return; + } + + // this.removeUnvisibleLayers(copiedDoc) + // this.unlockAll(copiedDoc); + // this.rasterizeAll(copiedDoc); + this.unvisibleAll(copiedDoc); + this.layerBlendAll(copiedDoc, copiedDoc); + // this.removeCommentoutLayers(copiedDoc, copiedDoc); + this.cropLayers(copiedDoc); + this.resizePsd(copiedDoc); + this.selectDocumentArea(copiedDoc); + this.ungroupArtboard(copiedDoc); + this.clipping(copiedDoc, copiedDoc); + copiedDoc.selection.deselect(); + this.psdToJson(copiedDoc); + this.psdToImage(copiedDoc); + copiedDoc.close(SaveOptions.DONOTSAVECHANGES); + if (after_close) { + return app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); + } + return alert('导出完成!'); + }; + + Baum.prototype.selectDocumentArea = function (document) { + var selReg, x1, x2, y1, y2; + x1 = 0; + y1 = 0; + x2 = document.width.value; + y2 = document.height.value; + selReg = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]; + return document.selection.select(selReg); + }; + + Baum.prototype.clipping = function (document, root) { + var h, w, x1, x2, y1, y2; + document.resizeImage(document.width, document.height, 72, ResampleMethod.BICUBICAUTOMATIC); + if (document.selection.bounds[0].value === 0 && document.selection.bounds[1].value === 0 && document.selection.bounds[2].value === document.width.value && document.selection.bounds[3].value === document.height.value) { + return; + } + document.selection.invert(); + this.clearAll(document, root); + document.selection.invert(); + x1 = document.selection.bounds[0]; + y1 = document.selection.bounds[1]; + x2 = document.selection.bounds[2]; + y2 = document.selection.bounds[3]; + document.resizeCanvas(x2, y2, AnchorPosition.TOPLEFT); + w = x2 - x1; + h = y2 - y1; + return activeDocument.resizeCanvas(w, h, AnchorPosition.BOTTOMRIGHT); + }; + + Baum.prototype.clearAll = function (document, root) { + var j, layer, len, ref1, results; + ref1 = root.layers; + results = []; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.typename === 'LayerSet') { + results.push(this.clearAll(document, layer)); + } else if (layer.typename === 'ArtLayer') { + if (layer.kind !== LayerKind.TEXT) { + document.activeLayer = layer; + results.push(document.selection.clear()); + } else { + results.push(void 0); + } + } else { + results.push(alert(layer)); + } + } + return results; + }; + + Baum.prototype.resizePsd = function (doc) { + var height, tmp, width; + width = doc.width; + height = doc.height; + if (width < Baum.maxLength && height < Baum.maxLength) { + return; + } + tmp = 0; + if (width > height) { + tmp = width / Baum.maxLength; + } else { + tmp = height / Baum.maxLength; + } + width = width / tmp; + height = height / tmp; + return doc.resizeImage(width, height, doc.resolution, ResampleMethod.BICUBICAUTOMATIC); + }; + + Baum.prototype.removeUnvisibleLayers = function (root) { + var i, j, k, layer, len, ref1, ref2, removeLayers, results; + removeLayers = []; + ref1 = root.layers; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.visible === false) { + // layer.visible = true; + // 不可见的就push到移除layer中去 + removeLayers.push(layer); + continue; + } + if (layer.bounds[0].value === 0 && layer.bounds[1].value === 0 && layer.bounds[2].value === 0 && layer.bounds[3].value === 0) { + removeLayers.push(layer); + continue; + } + if (layer.typename === 'LayerSet') { + this.removeUnvisibleLayers(layer); + } + } + if (removeLayers.length > 0) { + results = []; + for (i = k = ref2 = removeLayers.length - 1; ref2 <= 0 ? k <= 0 : k >= 0; i = ref2 <= 0 ? ++k : --k) { + results.push(removeLayers[i].remove()); + } + return results; + } + }; + + Baum.prototype.checkLayerName = function (root) { + //检查名字是否合规,同时移除不可见图层,同时解锁、光栅 + var removeLayers = [] + var ref1 = root.layers + for (var j = 0; j < ref1.length; j++) { + var layer = ref1[j]; + var ss = layer.name.split("@"); + //忽略但保留父节点宽高影响,则不移除 + if (Util.isInferiorIgnoreByName(ss[0])) { + continue + } + + //移除不可见图层 + if (layer.visible === false || Util.isIgnoreByName(ss[0])) { + // 不可见的就push到移除layer中去 + removeLayers.push(layer) + continue + } + + if (layer.bounds[0].value === 0 && layer.bounds[1].value === 0 && layer.bounds[2].value === 0 && layer.bounds[3].value === 0) { + removeLayers.push(layer) + continue + } + + //解锁所有图层 + if (layer.allLocked) + layer.allLocked = false + + //光栅所有图层 + if (layer.typename === 'ArtLayer') { + if (layer.kind !== LayerKind.TEXT) { + this.rasterize(layer) + } + } + opt = Util.parseOption(ss[1]); + + //检查大小命名格式 + if (opt['高度']) { + var s = opt['高度'] + for (var i = 0; i < s.length; i++) { + if (isNaN(s[i])) { + alert(layer.name + " 高度数值错误") + return false + } + } + } + if (opt['宽度']) { + var s = opt['宽度'] + for (var i = 0; i < s.length; i++) { + if (isNaN(s[i])) { + alert(layer.name + " 宽度数值错误") + return false + } + } + } + + //检查九宫格命名格式 + if (opt['九宫格'] && opt['九宫格'] != 'true') { + var param = opt['九宫格'] + var nums = param.toString().split("|"); + if (nums.length == 1 || nums.length == 4) { + for (var i = 0; i < nums.length; i++) { + if (!isNumber(nums[i])) { + alert(layer.name + " 九宫格格式不对") + return false; + } + } + } + else { + alert(layer.name + " 九宫格格式不对") + return false; + } + } + + //文件名合规检测 + var reg = /^[0-9a-zA-Z"_""\-"]*$/g; + if (!reg.test(ss[0])) { + alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_") + return false; + } + + //递归检测 + if (layer.typename === 'LayerSet') { + if (!this.checkLayerName(layer)) + return false + } + } + + if (removeLayers.length > 0) { + for (i = k = ref2 = removeLayers.length - 1; ref2 <= 0 ? k <= 0 : k >= 0; i = ref2 <= 0 ? ++k : --k) { + removeLayers[i].remove() + } + } + + return true + } + + function isChinese(temp) { + var re = /[^\u4E00-\u9FA5]/; + if (re.test(temp)) return false; + return true; + } + + function isNumber(val) { + var regPos = /^\d+(\.\d+)?$/; //非负浮点数 + var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数 + if (regPos.test(val) || regNeg.test(val)) { + return true; + } else { + return false; + } + } + + Baum.prototype.removeCommentoutLayers = function (document, root) { + var i, j, k, layer, len, ref1, ref2, removeLayers, results; + removeLayers = []; + ref1 = root.layers; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (Util.isIgnoreByName(layer.name)) { + removeLayers.push(layer); + continue; + } + if (layer.typename === 'LayerSet') { + this.removeCommentoutLayers(document, layer); + } + } + if (root.typename === 'LayerSet') { + document.activeLayer = root; + } + if (removeLayers.length > 0) { + results = []; + for (i = k = ref2 = removeLayers.length - 1; ref2 <= 0 ? k <= 0 : k >= 0; i = ref2 <= 0 ? ++k : --k) { + results.push(removeLayers[i].remove()); + } + return results; + } + }; + + Baum.prototype.cropLayers = function (root) { + var bounds; + bounds = [0, 0, root.width, root.height]; + return root.crop(bounds); + }; + + Baum.prototype.rasterizeAll = function (root) { + var j, layer, len, ref1, results, t; + ref1 = root.layers; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.name.startsWith('*')) { + layer.name = layer.name.slice(1).strip(); + if (layer.typename === 'LayerSet') { + Util.mergeGroup(layer); + } else { + this.rasterize(layer); + } + } else if (layer.typename === 'LayerSet') { + this.rasterizeAll(layer); + } else if (layer.typename === 'ArtLayer') { + if (layer.kind !== LayerKind.TEXT) { + this.rasterize(layer); + } + } else { + alert(layer); + } + } + t = 0; + results = []; + while (t < root.layers.length) { + if (root.layers[t].visible && root.layers[t].grouped) { + results.push(root.layers[t].merge()); + } else { + results.push(t += 1); + } + } + return results; + }; + + Baum.prototype.rasterize = function (layer) { + var tmp; + tmp = app.activeDocument.activeLayer; + app.activeDocument.activeLayer = layer; + if (layer.blendMode !== BlendMode.OVERLAY && layer.kind !== LayerKind.HUESATURATION && layer.opacity > 1) { + Util.rasterizeLayerStyle(layer); + } + layer.rasterize(RasterizeType.ENTIRELAYER); + Util.rasterizeLayerMask(layer); + return app.activeDocument.activeLayer = tmp; + }; + + Baum.prototype.ungroupArtboard = function (document) { + var j, layer, len, ref1, results; + ref1 = document.layers; + results = []; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.name.startsWith('Artboard') && layer.typename === 'LayerSet') { + results.push(this.ungroup(layer)); + } else { + results.push(void 0); + } + } + return results; + }; + + Baum.prototype.ungroup = function (root) { + var i, j, layer, layers, ref1; + layers = (function () { + var j, len, ref1, results; + ref1 = root.layers; + results = []; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + results.push(layer); + } + return results; + })(); + for (i = j = 0, ref1 = layers.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) { + layers[i].moveBefore(root); + } + return root.remove(); + }; + + Baum.prototype.unlockAll = function (root) { + var j, layer, len, ref1, results; + ref1 = root.layers; + results = []; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.typename === 'LayerSet') { + results.push(this.unlockAll(layer)); + } else { + if (layer.allLocked) { + results.push(layer.allLocked = false); + } else { + results.push(void 0); + } + } + } + return results; + }; + + Baum.prototype.unvisibleAll = function (root) { + var j, layer, len, ref1, results; + ref1 = root.layers; + results = []; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.typename === 'LayerSet') { + results.push(this.unvisibleAll(layer)); + } else { + results.push(layer.visible = false); + } + } + return results; + }; + + Baum.prototype.layerBlendAll = function (document, root) { + var i, j, layer, newLayer, ref1, results; + if (root.layers.length === 0) { + return; + } + results = []; + for (i = j = ref1 = root.layers.length - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) { + layer = root.layers[i]; + if (layer.typename === 'LayerSet') { + results.push(this.layerBlendAll(document, layer)); + } else { + layer.visible = true; + if (layer.blendMode !== BlendMode.OVERLAY && layer.kind !== LayerKind.HUESATURATION) { + continue; + } + document.activeLayer = layer; + try { + Util.selectTransparency(); + document.selection.bounds; + document.selection.copy(true); + } catch (error) { + layer.copy(true); + } + document.paste(); + newLayer = document.activeLayer; + newLayer.name = layer.name; + document.activeLayer = layer; + Util.selectTransparency(); + document.selection.invert(); + document.activeLayer = newLayer; + try { + document.selection.bounds; + document.selection.cut(); + } catch (error) { } + results.push(layer.remove()); + } + } + return results; + }; + + Baum.prototype.psdToJson = function (targetDocument) { + var json, toJson; + toJson = new PsdToJson(); + json = toJson.run(targetDocument, this.documentName); + return Util.saveText(this.saveFolder + "/" + this.documentName + ".layout.txt", json); + }; + + Baum.prototype.psdToImage = function (targetDocument) { + var json, toImage; + toImage = new PsdToImage(); + return json = toImage.run(targetDocument, this.saveFolder, this.documentName); + }; + + return Baum; + + })(); + + PsdToJson = (function () { + function PsdToJson() { } + + PsdToJson.prototype.run = function (document, documentName) { + var bounds, canvasBase, canvasLayer, canvasSize, imageSize, json, layers; + layers = this.allLayers(document, document); + imageSize = [document.width.value, document.height.value]; + canvasSize = [document.width.value, document.height.value]; + canvasBase = [document.width.value / 2, document.height.value / 2]; + canvasLayer = this.findLayer(document, '#Canvas'); + if (canvasLayer) { + bounds = canvasLayer.bounds; + canvasSize = [bounds[2].value - bounds[0].value, bounds[3].value - bounds[1].value]; + canvasBase = [(bounds[2].value + bounds[0].value) / 2, (bounds[3].value + bounds[1].value) / 2]; + } + json = JSON.stringify({ + info: { + version: Baum.version, + canvas: { + image: { + w: imageSize[0], + h: imageSize[1] + }, + size: { + w: canvasSize[0], + h: canvasSize[1] + }, + base: { + x: canvasBase[0], + y: canvasBase[1] + } + } + }, + root: { + type: 'Root', + name: documentName, + elements: layers + } + }); + return json; + }; + + PsdToJson.prototype.findLayer = function (root, name) { + var j, layer, len, ref1; + ref1 = root.layers; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.name === name) { + return layer; + } + } + return null; + }; + + PsdToJson.prototype.allLayers = function (document, root) { + var hash, j, layer, layers, len, name, opt, ref1; + layers = []; + ref1 = root.layers; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (!layer.visible || Util.isIgnoreByName(layer.name)) { + continue; + } + hash = null; + name = layer.name.split("@")[0]; + opt = Util.parseOption(layer.name.split("@")[1]); + if (layer.typename === 'ArtLayer') { + hash = this.layerToHash(document, name, opt, layer); + } else { + hash = this.groupToHash(document, name, opt, layer); + } + if (hash) { + hash['name'] = name; + layers.push(hash); + } + } + return layers; + }; + + PsdToJson.prototype.parseOption = function (text) { + var elements, j, len, opt, optText, ref1; + if (!text) { + return {}; + } + opt = {}; + ref1 = text.split(","); + for (j = 0, len = ref1.length; j < len; j++) { + optText = ref1[j]; + elements = optText.split("="); + if (elements.length === 1) { + elements[1] = 'true'; + } + opt[elements[0].toLowerCase()] = elements[1].toLowerCase(); + } + return opt; + }; + + PsdToJson.prototype.opt2hash = function (opt, hash, name, layer) { + // 一些中文快捷参数 + if (opt['上']) { hash['pivot'] = "top"; } + if (opt['左']) { hash['pivot'] = "left"; } + if (opt['右']) { hash['pivot'] = "right"; } + if (opt['下']) { hash['pivot'] = "bottom"; } + if (opt['左上']) { hash['pivot'] = "topleft"; } + if (opt['右上']) { hash['pivot'] = "topright"; } + if (opt['左下']) { hash['pivot'] = "bottomleft"; } + if (opt['右下']) { hash['pivot'] = "bottomright"; } + if (opt['水平伸展']) { hash['stretchx'] = "True"; } + if (opt['竖直伸展']) { hash['stretchy'] = "True"; } + 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"; } + //自定义了大小需要在unity端setnative + if (opt['高度'] || opt['宽度']) { hash['native'] = "True" } + if (opt['列表']) { hash['type'] = "List"; } + if (opt['进度条']) { hash['type'] = "Slider"; } + if (opt['滚动条']) { hash['type'] = "Scrollbar"; } + if (opt['开关']) { hash['type'] = "Toggle"; } + if (opt['预制体']) { + hash['type'] = "Prefab"; + if (layer.typename !== 'ArtLayer') { + var x = layer.bounds[0].value + var y = layer.bounds[1].value + var w = layer.bounds[2].value - layer.bounds[0].value + var h = layer.bounds[3].value - layer.bounds[1].value + Util.UpdateHash(hash, { + x: x, + y: y, + w: w, + h: h, + }) + } + hash['prefabName'] = opt['预制体']; + } + }; + + PsdToJson.prototype.layerToHash = function (document, name, opt, layer) { + var align, bounds, e, hash, hh, originalText, pos, scale, text, textCenterOffset, textColor, textSize, textType, vh, vx, vy, ww, font; + document.activeLayer = layer; + hash = {}; + var x = layer.bounds[0].value + var y = layer.bounds[1].value + var w = layer.bounds[2].value - layer.bounds[0].value + var h = layer.bounds[3].value - layer.bounds[1].value + if (layer.kind === LayerKind.TEXT) { + text = layer.textItem; + textSize = parseFloat(this.getTextSize()); + originalText = ''; + align = ''; + //默认字体 + font = 'AdobeHeitiStd-Regular'; + textColor = 0x000000; + try { + originalText = text.contents.replace(/\r\n/g, '__CRLF__').replace(/\r/g, '__CRLF__').replace(/\n/g, '__CRLF__').replace(/__CRLF__/g, '\r\n'); + } catch (error) { + e = error; + originalText = ''; + } + try { + font = text.font; + } catch (error) { + e = error; + font = 'AdobeHeitiStd-Regular'; + } + try { + textColor = text.color.rgb.hexValue; + } catch (error) { + e = error; + textColor = 0x000000; + } + try { + align = text.justification.toString().slice(14).toLowerCase(); + } catch (error) { + e = error; + align = 'left'; + } + hash = { + type: 'Text', + text: originalText, + font: font, + size: textSize, + color: textColor, + align: align, + x: x, + y: y, + w: w, + h: h, + opacity: Math.round(layer.opacity * 10.0) / 10.0 + }; + if (Util.hasStroke(document, layer)) { + hash['strokeSize'] = Util.getStrokeSize(document, layer); + hash['strokeColor'] = Util.getStrokeColor(document, layer).rgb.hexValue; + } + if (Util.hasShadow(document, layer)) { + hash['shadowColor'] = Util.getShadowColor(document, layer).rgb.hexValue + hash['shadowDis'] = Util.getShadowDis(document, layer) + hash['shadowBlur'] = Util.getShadowBlur(document, layer) + hash['shadowAngle'] = Util.getShadowAngle(document, layer) + } + if (Util.isVertical(document, layer)) { + hash['vertical'] = 'True' + } + if (Util.isItalic(document, layer)) { + hash['isItalic'] = 'True' + } + if (Util.hasGradient(document, layer)) { + hash['gradientAngle'] = Util.getGradientAngle(document, layer) + hash['gradientColor0'] = Util.getGradientColor(document, layer, 0).rgb.hexValue + hash['gradientColor1'] = Util.getGradientColor(document, layer, 1).rgb.hexValue + //渐变反向 + if (Util.isGradientReverse(document, layer)) { + var tmp = hash['gradientColor0'] + hash['gradientColor0'] = hash['gradientColor1'] + hash['gradientColor1'] = tmp + } + } + } else { + hash = { + type: 'Image', + image: Util.layerToImageName(layer), + x: x, + y: y, + w: w, + h: h, + opacity: Math.round(layer.opacity * 10.0) / 10.0 + }; + if (opt['九宫格']) { + hash['slice'] = opt['九宫格']; + } + } + + this.opt2hash(opt, hash, name, layer); + return hash; + }; + + PsdToJson.prototype.angleFromMatrix = function (yy, xy) { + var toDegs; + toDegs = 180 / Math.PI; + return Math.atan2(yy, xy) * toDegs - 90; + }; + + PsdToJson.prototype.getActiveLayerTransform = function () { + var desc, ref, xx, xy, yx, yy; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')); + if (desc.hasKey(stringIDToTypeID('transform'))) { + desc = desc.getObjectValue(stringIDToTypeID('transform')); + xx = desc.getDouble(stringIDToTypeID('xx')); + xy = desc.getDouble(stringIDToTypeID('xy')); + yy = desc.getDouble(stringIDToTypeID('yy')); + yx = desc.getDouble(stringIDToTypeID('yx')); + return { + xx: xx, + xy: xy, + yy: yy, + yx: yx + }; + } + return { + xx: 0, + xy: 0, + yy: 0, + yx: 0 + }; + }; + + PsdToJson.prototype.getTextSize = function () { + var desc, mFactor, ref, textSize; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')); + textSize = desc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getDouble(stringIDToTypeID('size')); + if (desc.hasKey(stringIDToTypeID('transform'))) { + mFactor = desc.getObjectValue(stringIDToTypeID('transform')).getUnitDoubleValue(stringIDToTypeID("yy")); + textSize = (textSize * mFactor).toFixed(2); + } + return textSize; + }; + + PsdToJson.prototype.groupToHash = function (document, name, opt, layer) { + var hash; + hash = { + type: 'Group', + }; + hash['elements'] = this.allLayers(document, layer); + + this.opt2hash(opt, hash, name, layer); + return hash; + }; + + return PsdToJson; + + })(); + + + PsdToImage = (function () { + var baseFolder, fileNames; + + function PsdToImage() { } + + baseFolder = null; + + fileNames = []; + + var outputDoc + + PsdToImage.prototype.run = function (document, saveFolder, documentName) { + var i, j, k, len, ref1, removeFiles, 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(); + targets = this.allLayers(document); + //snapShotId = Util.takeSnapshot(document); + results = []; + for (k = 0, len = targets.length; k < len; k++) { + target = targets[k]; + target.visible = true; + this.outputLayer(document, target); + target.visible = false + // results.push(Util.revertToSnapshot(document, snapShotId)); + } + outputDoc.close(SaveOptions.DONOTSAVECHANGES) + return results; + }; + + PsdToImage.prototype.allLayers = function (root) { + var j, layer, len, list, ref1; + ref1 = root.layers; + for (j = 0, len = ref1.length; j < len; j++) { + layer = ref1[j]; + if (layer.kind === LayerKind.TEXT) { + layer.visible = false; + } + } + list = (function () { + var k, len1, ref2, results; + ref2 = root.layers; + results = []; + for (k = 0, len1 = ref2.length; k < len1; k++) { + layer = ref2[k]; + if (layer.visible || Util.isIgnoreByName(layer.name)) { + if (layer.typename === 'ArtLayer') { + layer.visible = false; + results.push(layer); + } else { + results.push(this.allLayers(layer)); + } + } + } + return results; + }).call(this); + return Array.prototype.concat.apply([], list); + }; + + PsdToImage.prototype.outputLayer = function (doc, layer) { + var fileName, layerName, opt, options, saveFile; + layer.opacity = 100.0; + fileName = Util.layerToImageName(layer); + var ss = layer.name.split("@"); + layerName = ss[0]; + opt = Util.parseOption(ss[1]); + + //重名图片不覆盖不切图 + if (indexOf.call(fileNames, fileName) >= 0) { + return + } + //预制体不切图 + if (opt['预制体']) { + return + } + fileNames.push(fileName); + + if (outputDoc == null) + outputDoc = app.documents.add(doc.width, doc.height, doc.resolution, doc.name + 'output.psd') + app.activeDocument = doc + layer.duplicate(outputDoc) + app.activeDocument = outputDoc + outputDoc.layers[1].remove() + layer = outputDoc.layers[0] + + if (opt['九宫格']) { + if (!layer.isBackgroundLayer) { + var param; + if (opt['九宫格']) { + param = opt['九宫格']; + } + + if (opt['九宫格'] === "true") { + this.snipImage(outputDoc, layer, opt); + fileName += "-slice"; + } + else { + outputDoc = this.sliceCutImg(outputDoc, layerName, param); + fileName += "-noslice"; + } + } + } + else { + fileName += "-noslice"; + if (!layer.isBackgroundLayer) { + this.snipImage(outputDoc, layer, opt); + } + } + + saveFile = new File(this.baseFolder.fsName + "/" + fileName + ".png"); + options = new ExportOptionsSaveForWeb(); + options.format = SaveDocumentType.PNG; + options.PNG8 = false; + options.optimized = true; + options.interlaced = false; + outputDoc.exportDocument(saveFile, ExportType.SAVEFORWEB, options); + + app.activeDocument = doc + }; + + PsdToImage.prototype.snipImage = function (doc, layer, opt) { + layer.translate(-layer.bounds[0], -layer.bounds[1]); + var canvasWidth = layer.bounds[2] - layer.bounds[0] + var canvasHeight = layer.bounds[3] - layer.bounds[1] + var doTrim = true + if (opt['宽度']) { + canvasWidth = parseInt(opt['宽度']) + //摆到中间 + layer.translate(-(canvasWidth - layer.bounds[2]) / 2, 0) + doTrim = false + } + if (opt['高度']) { + canvasHeight = parseInt(opt['高度']) + //摆到中间 + layer.translate(0, (-(canvasHeight - layer.bounds[3]) / 2)) + doTrim = false + } + doc.resizeCanvas(canvasWidth, canvasHeight, AnchorPosition.TOPLEFT); + if (doTrim) + doc.trim(TrimType.TRANSPARENT); + } + + PsdToImage.prototype.sliceCutImg = function (doc, layerName, param) { + // 创建图层组 + var _obj = doc.activeLayer + var stemGroup = doc.layerSets.add(); + stemGroup.name = layerName + // _obj.move(stemGroup,ElementPlacement.PLACEATEND) + doc.mergeVisibleLayers(); + doc.trim(TrimType.TRANSPARENT, true, true, true, true); + var width = doc.width; + var height = doc.height; + + var nums = param.toString().split("|"); + var sliceArr = new Array(0, 0, 0, 0); + if (nums.length == 1) { + for (var j = 0; j < sliceArr.length; j++) { + sliceArr[j] = parseInt(nums[0]); + } + } + else if (nums.length == 4) { + for (var j = 0; j < sliceArr.length; j++) { + var num = parseInt(nums[j]) + if (num == 0) { + if ((j) % 2 == 0) { + var symNumber = parseInt(nums[2 - j]); + num = height - symNumber; + } else { + var symNumber = parseInt(nums[4 - j]); + num = width - symNumber; + } + } + sliceArr[j] = num; + } + } else { + alert("图层名为:" + layerName + "的九宫格格式不对!应为name@九宫格=xx或name@九宫格=xx|xx|xx|xx"); + return; + } + + var _obj = doc.activeLayer + //左下左上,右上右下 + var selRegion = Array( + Array(Array(0, sliceArr[1]), Array(0, 0), Array(sliceArr[0], 0), Array(sliceArr[0], sliceArr[1])), + Array(Array(width - sliceArr[2], sliceArr[1]), Array(width - sliceArr[2], 0), Array(width, 0), Array(width, sliceArr[1])), + Array(Array(0, height), Array(0, height - sliceArr[3]), Array(sliceArr[0], height - sliceArr[3]), Array(sliceArr[0], height)), + Array(Array(width - sliceArr[2], height), Array(width - sliceArr[2], height - sliceArr[3]), Array(width, height - sliceArr[3]), Array(width, height)), + ); + for (var i = 0; i < selRegion.length; i++) { + doc.activeLayer = _obj; + doc.selection.select(selRegion[i]); + // doc.selection.copy(); + executeAction(charIDToTypeID("CpTL")); + // var newStem = doc.paste(); + var newStem = doc.activeLayer; + newStem.name = layerName + "_"; + var deltaX = 0; + var deltaY = 0; + if (selRegion[i][0][0] != 0) { + deltaX = - (width - sliceArr[0] - sliceArr[2]); + } + if (selRegion[i][1][1] != 0) { + deltaY = - (height - sliceArr[1] - sliceArr[3]); + } + newStem.translate(deltaX, deltaY); + } + _obj.visible = false; + doc.mergeVisibleLayers(); + doc.trim(TrimType.TRANSPARENT, true, true, true, true); + return doc; + } + + return PsdToImage; + + })(); + + Util = (function () { + function Util() { } + + Util.saveText = function (filePath, text) { + var file; + file = File(filePath); + file.encoding = "UTF8"; + file.open("w", "TEXT"); + file.write(text); + return file.close(); + }; + + Util.layerToImageName = function (layer) { + return layer.name.split("@")[0];//encodeURI(Util.layerToImageNameLoop(layer)).replace(/%/g, ''); + }; + + Util.layerToImageNameLoop = function (layer) { + var image, imageName; + if (layer instanceof Document) { + return ""; + } + image = Util.layerToImageName(layer.parent); + imageName = image; + if (imageName !== "") { + imageName = imageName + "_"; + } + return imageName + layer.name.split("@")[0].replace('_', '').replace(' ', '-').toLowerCase(); + }; + + Util.getLastSnapshotID = function (doc) { + var hsLength, hsObj, i, j, ref1; + hsObj = doc.historyStates; + hsLength = hsObj.length; + for (i = j = ref1 = hsLength - 1; ref1 <= -1 ? j <= -1 : j >= -1; i = ref1 <= -1 ? ++j : --j) { + if (hsObj[i].snapshot) { + return i; + } + } + }; + + Util.takeSnapshot = function (doc) { + var desc153, ref119, ref120; + desc153 = new ActionDescriptor(); + ref119 = new ActionReference(); + ref119.putClass(charIDToTypeID("SnpS")); + desc153.putReference(charIDToTypeID("null"), ref119); + ref120 = new ActionReference(); + ref120.putProperty(charIDToTypeID("HstS"), charIDToTypeID("CrnH")); + desc153.putReference(charIDToTypeID("From"), ref120); + executeAction(charIDToTypeID("Mk "), desc153, DialogModes.NO); + return Util.getLastSnapshotID(doc); + }; + + Util.revertToSnapshot = function (doc, snapshotID) { + return doc.activeHistoryState = doc.historyStates[snapshotID]; + }; + + Util.hasStroke = function (doc, layer) { + var desc1, desc2, hasFX, hasStroke, ref, res; + doc.activeLayer = layer; + res = false; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects')); + if (hasFX) { + hasStroke = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('frameFX')); + if (hasStroke) { + desc1 = executeActionGet(ref); + desc2 = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX')); + if (desc1.getBoolean(stringIDToTypeID('layerFXVisible')) && desc2.getBoolean(stringIDToTypeID('enabled'))) { + res = true; + } + } + } + return res; + }; + + Util.hasShadow = function (doc, layer) { + var desc1, desc2, hasFX, hasShadow, ref, res; + doc.activeLayer = layer; + res = false; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects')); + if (hasFX) { + hasShadow = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('dropShadow')); + if (hasShadow) { + desc1 = executeActionGet(ref); + desc2 = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow')); + if (desc1.getBoolean(stringIDToTypeID('layerFXVisible')) && desc2.getBoolean(stringIDToTypeID('enabled'))) { + res = true; + } + } + } + return res; + }; + + Util.isItalic = function (doc, layer) { + var desc1, desc2, hasFX, hasShadow, ref, res; + doc.activeLayer = layer; + res = false; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + var l = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')).getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')) + var flag = l.hasKey(stringIDToTypeID('syntheticItalic')) && l.getBoolean(stringIDToTypeID('syntheticItalic')) + return flag + }; + + Util.isVertical = function (doc, layer) { + var desc1, desc2, hasFX, hasShadow, ref, res; + doc.activeLayer = layer; + res = false; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + var hType = typeIDToStringID(executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')).getEnumerationValue(stringIDToTypeID('orientation'))) + return hType == "vertical" + }; + + Util.hasGradient = function (doc, layer) { + var desc1, desc2, hasFX, hasGradient, ref, res; + doc.activeLayer = layer; + res = false; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects')); + if (hasFX) { + hasGradient = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('gradientFill')); + if (hasGradient) { + desc1 = executeActionGet(ref); + desc2 = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill')); + if (desc1.getBoolean(stringIDToTypeID('layerFXVisible')) && desc2.getBoolean(stringIDToTypeID('enabled'))) { + res = true; + } + } + } + return res; + }; + + Util.getStrokeSize = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX')); + return desc.getUnitDoubleValue(stringIDToTypeID('size')); + }; + + Util.getGradientColor = function (doc, layer, index) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + + var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill')) + var color = desc.getObjectValue(stringIDToTypeID('gradient')).getList(stringIDToTypeID('colors')).getObjectValue(index) + return Util.getColorFromDescriptor(color.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(color.getClass(stringIDToTypeID("color")))) + }; + + Util.isGradientReverse = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + + var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill')) + return desc.getBoolean(stringIDToTypeID('reverse')) + }; + + Util.getGradientAngle = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + + var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill')) + return desc.getUnitDoubleValue(stringIDToTypeID('angle')); + }; + + Util.getShadowColor = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow')); + //alert(Util.getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color"))))) + return Util.getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color")))); + }; + + Util.getShadowDis = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow')); + //alert(desc.getUnitDoubleValue(stringIDToTypeID('distance'))) + return desc.getUnitDoubleValue(stringIDToTypeID('distance')); + }; + + Util.getShadowBlur = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow')); + //alert(desc.getUnitDoubleValue(stringIDToTypeID('blur'))) + return desc.getUnitDoubleValue(stringIDToTypeID('blur')); + }; + + Util.getShadowAngle = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow')); + return desc.getBoolean(stringIDToTypeID('useGlobalAngle')) ? executeActionGet(ref).getUnitDoubleValue(stringIDToTypeID('globalAngle')) : desc.getUnitDoubleValue(stringIDToTypeID('localLightingAngle')) + }; + + Util.getStrokeColor = function (doc, layer) { + var desc, ref; + doc.activeLayer = layer; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX')); + return Util.getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color")))); + }; + + Util.getColorFromDescriptor = function (colorDesc, keyClass) { + var colorObject; + colorObject = new SolidColor(); + if (keyClass === "Grsc") { + colorObject.grey.grey = color.getDouble(charIDToTypeID('Gry ')); + } + if (keyClass === "RGBC") { + colorObject.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd ')); + colorObject.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn ')); + colorObject.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl ')); + } + if (keyClass === "CMYC") { + colorObject.cmyk.cyan = colorDesc.getDouble(charIDToTypeID('Cyn ')); + colorObject.cmyk.magenta = colorDesc.getDouble(charIDToTypeID('Mgnt')); + colorObject.cmyk.yellow = colorDesc.getDouble(charIDToTypeID('Ylw ')); + colorObject.cmyk.black = colorDesc.getDouble(charIDToTypeID('Blck')); + } + if (keyClass === "LbCl") { + colorObject.lab.l = colorDesc.getDouble(charIDToTypeID('Lmnc')); + colorObject.lab.a = colorDesc.getDouble(charIDToTypeID('A ')); + colorObject.lab.b = colorDesc.getDouble(charIDToTypeID('B ')); + } + return colorObject; + }; + + Util.deselectLayers = function () { + var desc01, ref01; + desc01 = new ActionDescriptor(); + ref01 = new ActionReference(); + ref01.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt')); + desc01.putReference(charIDToTypeID('null'), ref01); + return executeAction(stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO); + }; + + Util.selectTransparency = function () { + var actionDesc, actionSelect, actionTransparent, idChnl; + idChnl = charIDToTypeID("Chnl"); + actionSelect = new ActionReference(); + actionSelect.putProperty(idChnl, charIDToTypeID("fsel")); + actionTransparent = new ActionReference(); + actionTransparent.putEnumerated(idChnl, idChnl, charIDToTypeID("Trsp")); + actionDesc = new ActionDescriptor(); + actionDesc.putReference(charIDToTypeID("null"), actionSelect); + actionDesc.putReference(charIDToTypeID("T "), actionTransparent); + return executeAction(charIDToTypeID("setd"), actionDesc, DialogModes.NO); + }; + + Util.getTextYScale = function (text_item) { + var bounds, desc, height, ref, transform, width, x_scale, y_scale; + app.activeDocument.activeLayer = text_item.parent; + ref = new ActionReference(); + ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); + desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')); + bounds = desc.getObjectValue(stringIDToTypeID('bounds')); + width = bounds.getUnitDoubleValue(stringIDToTypeID('right')); + height = bounds.getUnitDoubleValue(stringIDToTypeID('bottom')); + x_scale = 1; + y_scale = 1; + if (desc.hasKey(stringIDToTypeID('transform'))) { + transform = desc.getObjectValue(stringIDToTypeID('transform')); + x_scale = transform.getUnitDoubleValue(stringIDToTypeID('xx')); + y_scale = transform.getUnitDoubleValue(stringIDToTypeID('yy')); + } + return y_scale; + }; + + Util.rasterizeLayerStyle = function (layer) { + var desc5, idLyr, idOrdn, idTrgt, idWhat, idlayerStyle, idnull, idrasterizeItem, idrasterizeLayer, ref4; + app.activeDocument.activeLayer = layer; + idrasterizeLayer = stringIDToTypeID("rasterizeLayer"); + desc5 = new ActionDescriptor(); + idnull = charIDToTypeID("null"); + ref4 = new ActionReference(); + idLyr = charIDToTypeID("Lyr "); + idOrdn = charIDToTypeID("Ordn"); + idTrgt = charIDToTypeID("Trgt"); + ref4.putEnumerated(idLyr, idOrdn, idTrgt); + desc5.putReference(idnull, ref4); + idWhat = charIDToTypeID("What"); + idrasterizeItem = stringIDToTypeID("rasterizeItem"); + idlayerStyle = stringIDToTypeID("layerStyle"); + desc5.putEnumerated(idWhat, idrasterizeItem, idlayerStyle); + return executeAction(idrasterizeLayer, desc5, DialogModes.NO); + }; + + Util.rasterizeLayerMask = function (layer) { + app.activeDocument.activeLayer = layer; + if (Util.hasVectorMask()) { + Util.rasterizeLayer(); + Util.selectVectorMask(); + Util.rasterizeVectorMask(); + Util.applyLayerMask(); + } + if (Util.hasLayerMask()) { + Util.rasterizeLayer(); + Util.selectLayerMask(); + return Util.applyLayerMask(); + } + }; + + // 忽略 + Util.isIgnoreByName = function (name) { + return name.startsWith('#') || Util.isInferiorIgnoreByName(name) + }; + + // 忽略,但保留父节点宽高影响 + Util.isInferiorIgnoreByName = function (name) { + return name.startsWith('$') + }; + + Util.UpdateHash = function (hashTarget, hashRes) { + for (var key in hashRes) { + hashTarget[key] = hashRes[key]; + } + }; + + Util.hasVectorMask = function () { + var desc, e, hasVectorMask, keyKind, keyVectorMaskEnabled, kindValue, ref; + hasVectorMask = false; + try { + ref = new ActionReference(); + keyVectorMaskEnabled = app.stringIDToTypeID('vectorMask'); + keyKind = app.charIDToTypeID('Knd '); + ref.putEnumerated(app.charIDToTypeID('Path'), app.charIDToTypeID('Ordn'), keyVectorMaskEnabled); + desc = executeActionGet(ref); + if (desc.hasKey(keyKind)) { + kindValue = desc.getEnumerationValue(keyKind); + if (kindValue === keyVectorMaskEnabled) { + hasVectorMask = true; + } + } + } catch (error) { + e = error; + hasVectorMask = false; + } + return hasVectorMask; + }; + + Util.hasLayerMask = function () { + var desc, e, hasLayerMask, keyUserMaskEnabled, ref; + hasLayerMask = false; + try { + ref = new ActionReference(); + keyUserMaskEnabled = app.charIDToTypeID('UsrM'); + ref.putProperty(app.charIDToTypeID('Prpr'), keyUserMaskEnabled); + ref.putEnumerated(app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt')); + desc = executeActionGet(ref); + if (desc.hasKey(keyUserMaskEnabled)) { + hasLayerMask = true; + } + } catch (error) { + e = error; + hasLayerMask = false; + } + return hasLayerMask; + }; + + Util.rasterizeLayer = function () { + var desc245, id1242, id1243, id1244, id1245, id1246, ref184; + try { + id1242 = stringIDToTypeID("rasterizeLayer"); + desc245 = new ActionDescriptor(); + id1243 = charIDToTypeID("null"); + ref184 = new ActionReference(); + id1244 = charIDToTypeID("Lyr "); + id1245 = charIDToTypeID("Ordn"); + id1246 = charIDToTypeID("Trgt"); + ref184.putEnumerated(id1244, id1245, id1246); + desc245.putReference(id1243, ref184); + return executeAction(id1242, desc245, DialogModes.NO); + } catch (error) { + + } + }; + + Util.selectVectorMask = function () { + var desc15, e, id55, id56, id57, id58, id59, id60, id61, id62, ref13; + try { + id55 = charIDToTypeID("slct"); + desc15 = new ActionDescriptor(); + id56 = charIDToTypeID("null"); + ref13 = new ActionReference(); + id57 = charIDToTypeID("Path"); + id58 = charIDToTypeID("Path"); + id59 = stringIDToTypeID("vectorMask"); + ref13.putEnumerated(id57, id58, id59); + id60 = charIDToTypeID("Lyr "); + id61 = charIDToTypeID("Ordn"); + id62 = charIDToTypeID("Trgt"); + ref13.putEnumerated(id60, id61, id62); + desc15.putReference(id56, ref13); + return executeAction(id55, desc15, DialogModes.NO); + } catch (error) { + e = error; + } + }; + + Util.selectLayerMask = function () { + var desc153, e, id759, id760, id761, id762, id763, id764, ref92; + try { + id759 = charIDToTypeID("slct"); + desc153 = new ActionDescriptor(); + id760 = charIDToTypeID("null"); + ref92 = new ActionReference(); + id761 = charIDToTypeID("Chnl"); + id762 = charIDToTypeID("Chnl"); + id763 = charIDToTypeID("Msk "); + ref92.putEnumerated(id761, id762, id763); + desc153.putReference(id760, ref92); + id764 = charIDToTypeID("MkVs"); + desc153.putBoolean(id764, false); + return executeAction(id759, desc153, DialogModes.NO); + } catch (error) { + e = error; + } + }; + + Util.rasterizeVectorMask = function () { + var desc44, e, id488, id489, id490, id491, id492, id493, id494, id495, ref29; + try { + id488 = stringIDToTypeID("rasterizeLayer"); + desc44 = new ActionDescriptor(); + id489 = charIDToTypeID("null"); + ref29 = new ActionReference(); + id490 = charIDToTypeID("Lyr "); + id491 = charIDToTypeID("Ordn"); + id492 = charIDToTypeID("Trgt"); + ref29.putEnumerated(id490, id491, id492); + desc44.putReference(id489, ref29); + id493 = charIDToTypeID("What"); + id494 = stringIDToTypeID("rasterizeItem"); + id495 = stringIDToTypeID("vectorMask"); + desc44.putEnumerated(id493, id494, id495); + return executeAction(id488, desc44, DialogModes.NO); + } catch (error) { + e = error; + } + }; + + Util.applyLayerMask = function () { + var desc154, e, id765, id766, id767, id768, id769, id770, ref93; + try { + id765 = charIDToTypeID("Dlt "); + desc154 = new ActionDescriptor(); + id766 = charIDToTypeID("null"); + ref93 = new ActionReference(); + id767 = charIDToTypeID("Chnl"); + id768 = charIDToTypeID("Ordn"); + id769 = charIDToTypeID("Trgt"); + ref93.putEnumerated(id767, id768, id769); + desc154.putReference(id766, ref93); + id770 = charIDToTypeID("Aply"); + desc154.putBoolean(id770, true); + return executeAction(id765, desc154, DialogModes.NO); + } catch (error) { + e = error; + } + }; + + Util.mergeGroup = function (layer) { + var desc15, e, idMrgtwo; + app.activeDocument.activeLayer = layer; + try { + idMrgtwo = charIDToTypeID("Mrg2"); + desc15 = new ActionDescriptor(); + return executeAction(idMrgtwo, desc15, DialogModes.NO); + } catch (error) { + e = error; + } + }; + + Util.parseOption = function (text) { + var elements, j, len, opt, optText, ref1; + if (!text) { + return {}; + } + opt = {}; + ref1 = text.split(","); + for (j = 0, len = ref1.length; j < len; j++) { + optText = ref1[j]; + elements = optText.split("="); + if (elements.length === 1) { + elements[1] = 'true'; + } + opt[elements[0].toLowerCase()] = elements[1].toLowerCase(); + } + return opt; + }; + + return Util; + + })(); + + String.prototype.startsWith = function (str) { + return this.slice(0, str.length) === str; + }; + + String.prototype.endsWith = function (suffix) { + return this.indexOf(suffix, this.length - suffix.length) !== -1; + }; + + String.prototype.strip = function () { + if (String.prototype.trim != null) { + return this.trim(); + } else { + return this.replace(/^\s+|\s+$/g, ""); + } + }; + + setup = function () { + preferences.rulerUnits = Units.PIXELS; + return preferences.typeUnits = TypeUnits.PIXELS; + }; + + setup(); + + baum = new Baum(); + + baum.run(); + +}).call(this); diff --git a/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js.meta b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js.meta new file mode 100644 index 0000000..00dd234 --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity/PSD导出Unity.js.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ed511f3a351ac1840a9e64a11644d50b +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/.PhotoshopScript/JSZXPsd2Unity/lib.meta b/.PhotoshopScript/JSZXPsd2Unity/lib.meta new file mode 100644 index 0000000..0bc59dc --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity/lib.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4613883d849a29f40a54e49bfb746fd8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/.PhotoshopScript/JSZXPsd2Unity/lib/json2.min.js b/.PhotoshopScript/JSZXPsd2Unity/lib/json2.min.js new file mode 100644 index 0000000..18596c3 --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity/lib/json2.min.js @@ -0,0 +1,2 @@ +// 日本語認識用 +"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(t){return 10>t?"0"+t:t}function this_value(){return this.valueOf()}function quote(t){return rx_escapable.lastIndex=0,rx_escapable.test(t)?'"'+t.replace(rx_escapable,function(t){var e=meta[t];return"string"==typeof e?e:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+t+'"'}function str(t,e){var r,n,o,u,f,a=gap,i=e[t];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(t)),"function"==typeof rep&&(i=rep.call(e,t,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?i+"":"null";case"boolean":case"null":return i+"";case"object":if(!i)return"null";if(gap+=indent,f=[],"[object Array]"===Object.prototype.toString.apply(i)){for(u=i.length,r=0;u>r;r+=1)f[r]=str(r,i)||"null";return o=0===f.length?"[]":gap?"[\n"+gap+f.join(",\n"+gap)+"\n"+a+"]":"["+f.join(",")+"]",gap=a,o}if(rep&&"object"==typeof rep)for(u=rep.length,r=0;u>r;r+=1)"string"==typeof rep[r]&&(n=rep[r],o=str(n,i),o&&f.push(quote(n)+(gap?": ":":")+o));else for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(o=str(n,i),o&&f.push(quote(n)+(gap?": ":":")+o));return o=0===f.length?"{}":gap?"{\n"+gap+f.join(",\n"+gap)+"\n"+a+"}":"{"+f.join(",")+"}",gap=a,o}}var rx_one=/^[\],:{}\s]*$/,rx_two=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,rx_three=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,rx_four=/(?:^|:|,)(?:\s*\[)+/g,rx_escapable=/[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,rx_dangerous=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},Boolean.prototype.toJSON=this_value,Number.prototype.toJSON=this_value,String.prototype.toJSON=this_value);var gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(t,e,r){var n;if(gap="",indent="","number"==typeof r)for(n=0;r>n;n+=1)indent+=" ";else"string"==typeof r&&(indent=r);if(rep=e,e&&"function"!=typeof e&&("object"!=typeof e||"number"!=typeof e.length))throw Error("JSON.stringify");return str("",{"":t})}),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(t,e){var r,n,o=t[e];if(o&&"object"==typeof o)for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(n=walk(o,r),void 0!==n?o[r]=n:delete o[r]);return reviver.call(t,e,o)}var j;if(text+="",rx_dangerous.lastIndex=0,rx_dangerous.test(text)&&(text=text.replace(rx_dangerous,function(t){return"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})),rx_one.test(text.replace(rx_two,"@").replace(rx_three,"]").replace(rx_four,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(); diff --git a/.PhotoshopScript/JSZXPsd2Unity/lib/json2.min.js.meta b/.PhotoshopScript/JSZXPsd2Unity/lib/json2.min.js.meta new file mode 100644 index 0000000..801a984 --- /dev/null +++ b/.PhotoshopScript/JSZXPsd2Unity/lib/json2.min.js.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c5aca7c37ed8912408cb936e4b18d10e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/.PhotoshopScript/README.txt b/.PhotoshopScript/README.txt new file mode 100644 index 0000000..fb72eb5 --- /dev/null +++ b/.PhotoshopScript/README.txt @@ -0,0 +1 @@ +拷贝到 \Presets\Scripts\Baum2 \ No newline at end of file diff --git a/.PhotoshopScript/README.txt.meta b/.PhotoshopScript/README.txt.meta new file mode 100644 index 0000000..28888f9 --- /dev/null +++ b/.PhotoshopScript/README.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7aa15847f0dfaf54f9401dc0a307d6ab +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/.psd2uguiExamples/FZYASHJW_ZHUN.TTF b/.psd2uguiExamples/FZYASHJW_ZHUN.TTF new file mode 100644 index 0000000..eb2dd67 Binary files /dev/null and b/.psd2uguiExamples/FZYASHJW_ZHUN.TTF differ diff --git a/.psd2uguiExamples/Sample.psd b/.psd2uguiExamples/Sample.psd new file mode 100644 index 0000000..c69a92a Binary files /dev/null and b/.psd2uguiExamples/Sample.psd differ diff --git a/.psd2uguiExamples/readme.txt b/.psd2uguiExamples/readme.txt new file mode 100644 index 0000000..c9a01c8 --- /dev/null +++ b/.psd2uguiExamples/readme.txt @@ -0,0 +1 @@ +用这个psd试试整个流程吧 \ No newline at end of file diff --git a/.tools/result_rot_scale/image/test-1.jpg b/.tools/result_rot_scale/image/test-1.jpg new file mode 100644 index 0000000..9f47eba Binary files /dev/null and b/.tools/result_rot_scale/image/test-1.jpg differ diff --git a/.tools/result_rot_scale/image/test-10.jpg b/.tools/result_rot_scale/image/test-10.jpg new file mode 100644 index 0000000..f5cc0b6 Binary files /dev/null and b/.tools/result_rot_scale/image/test-10.jpg differ diff --git a/.tools/result_rot_scale/image/test-20.jpg b/.tools/result_rot_scale/image/test-20.jpg new file mode 100644 index 0000000..9afec24 Binary files /dev/null and b/.tools/result_rot_scale/image/test-20.jpg differ diff --git a/.tools/result_rot_scale/image/test-30.jpg b/.tools/result_rot_scale/image/test-30.jpg new file mode 100644 index 0000000..193f743 Binary files /dev/null and b/.tools/result_rot_scale/image/test-30.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-11.jpg b/.tools/result_rot_scale/image_2/test-11.jpg new file mode 100644 index 0000000..1546306 Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-11.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-2.jpg b/.tools/result_rot_scale/image_2/test-2.jpg new file mode 100644 index 0000000..38c0cec Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-2.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-21.jpg b/.tools/result_rot_scale/image_2/test-21.jpg new file mode 100644 index 0000000..e07a910 Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-21.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-3.jpg b/.tools/result_rot_scale/image_2/test-3.jpg new file mode 100644 index 0000000..8155709 Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-3.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-31.jpg b/.tools/result_rot_scale/image_2/test-31.jpg new file mode 100644 index 0000000..40142b3 Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-31.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-4.jpg b/.tools/result_rot_scale/image_2/test-4.jpg new file mode 100644 index 0000000..f3d2e7d Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-4.jpg differ diff --git a/.tools/result_rot_scale/image_2/test-5.jpg b/.tools/result_rot_scale/image_2/test-5.jpg new file mode 100644 index 0000000..8155709 Binary files /dev/null and b/.tools/result_rot_scale/image_2/test-5.jpg differ diff --git a/.tools/result_rot_scale/main.exe b/.tools/result_rot_scale/main.exe new file mode 100644 index 0000000..25a1a77 Binary files /dev/null and b/.tools/result_rot_scale/main.exe differ diff --git a/.tools/result_rot_scale/start.bat b/.tools/result_rot_scale/start.bat new file mode 100644 index 0000000..d481630 --- /dev/null +++ b/.tools/result_rot_scale/start.bat @@ -0,0 +1,3 @@ +call main.exe -src image -target image_2 -distance_difference 0.06 + +pause \ No newline at end of file diff --git a/Assets.meta b/Assets.meta new file mode 100644 index 0000000..6f78c6c --- /dev/null +++ b/Assets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 57cc2dd092a664e4fbd95da444355a2e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor.meta b/Assets/Editor.meta new file mode 100644 index 0000000..b4c31ef --- /dev/null +++ b/Assets/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4937e0a4826e0834d9fe00bb4cf2ee64 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/EditorConst.cs b/Assets/Editor/EditorConst.cs new file mode 100644 index 0000000..4d11fc7 --- /dev/null +++ b/Assets/Editor/EditorConst.cs @@ -0,0 +1,12 @@ +namespace UguiToolkit.Editor +{ + public class EditorConst + { + public const string WorkspaceDirPath = "Assets/Editor/UguiToolkit"; + public const string SettingFilePath = WorkspaceDirPath + "/setting.asset"; + public const string CacheFilePath = WorkspaceDirPath + "/cache.asset"; + public const string RotScaleInfoFilePath = "Temp/result_rot_scale.json"; + public const string RotScaleInfoToolFilePath = "Packages/com.soviby.unity.ui.ugui-toolkit/.tools/result_rot_scale/main.exe"; + + } +} \ No newline at end of file diff --git a/Assets/Editor/EditorConst.cs.meta b/Assets/Editor/EditorConst.cs.meta new file mode 100644 index 0000000..34270ca --- /dev/null +++ b/Assets/Editor/EditorConst.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f2268976a28f4f9791aa52b904748da8 +timeCreated: 1718808905 \ No newline at end of file diff --git a/Assets/Editor/EditorDefine.cs b/Assets/Editor/EditorDefine.cs new file mode 100644 index 0000000..692c106 --- /dev/null +++ b/Assets/Editor/EditorDefine.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using Unity.Mathematics; + +namespace UguiToolkit.Editor +{ + [Serializable] + public class RotScaleJsonData + { + public Dictionary> data; + } + + [Serializable] + public struct RotScaleJsonItemData + { + public string targetPath; + public float rot; + public float[] scale; + } +} \ No newline at end of file diff --git a/Assets/Editor/EditorDefine.cs.meta b/Assets/Editor/EditorDefine.cs.meta new file mode 100644 index 0000000..de1c40d --- /dev/null +++ b/Assets/Editor/EditorDefine.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5164a8e1a26945d8a70a23c678306ce6 +timeCreated: 1719241384 \ No newline at end of file diff --git a/Assets/Editor/Helper.meta b/Assets/Editor/Helper.meta new file mode 100644 index 0000000..a588eaf --- /dev/null +++ b/Assets/Editor/Helper.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 578d542dd0864e8eaa73f7ade426fbae +timeCreated: 1718725128 \ No newline at end of file diff --git a/Assets/Editor/Helper/CommandHelper.cs b/Assets/Editor/Helper/CommandHelper.cs new file mode 100644 index 0000000..52b877a --- /dev/null +++ b/Assets/Editor/Helper/CommandHelper.cs @@ -0,0 +1,55 @@ + +using System.Collections.Generic; +using UnityEngine; +using System.IO; +using Newtonsoft.Json; + +namespace UguiToolkit.Editor +{ + public static class CommandHelper + { + public static RotScaleJsonData CalcRotScale(in string srcImgDirPath, in string targetImgDirPath, Dictionary> rotScaleInfos) + { + var rotScaleInfoFilePath = Path.GetFullPath(EditorConst.RotScaleInfoFilePath); + var rotScaleInfoToolFilePath = Path.GetFullPath(EditorConst.RotScaleInfoToolFilePath); + if (File.Exists(rotScaleInfoFilePath)) File.Delete(rotScaleInfoFilePath); + + RunCmd(string.Format("{0} -src {1} -target {2} -distance_difference 0.06 -output_path {3}", + rotScaleInfoToolFilePath, + Path.GetFullPath(srcImgDirPath), + Path.GetFullPath(targetImgDirPath), + Path.GetFullPath(rotScaleInfoFilePath))); + if (!File.Exists(rotScaleInfoFilePath)) + { + Debug.LogError($"[E] 文件{rotScaleInfoFilePath} 未能正确获得"); + return null; + } + + using (StreamReader reader = File.OpenText(rotScaleInfoFilePath)) + { + var jsonData = reader.ReadToEnd(); + RotScaleJsonData rotScaleJsonData = JsonConvert.DeserializeObject(jsonData); + return rotScaleJsonData; + } + } + + // 执行 cmd 命令 + public static void RunCmd(in string cmd) + { + var p = new System.Diagnostics.Process(); + p.StartInfo.FileName = "cmd.exe"; + p.StartInfo.Arguments = "/c " + cmd; // 使用 /c 参数执行命令并关闭 cmd 窗口 + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.RedirectStandardError = true; + + p.Start(); + var output = p.StandardOutput.ReadToEnd(); + var error = p.StandardError.ReadToEnd(); + p.WaitForExit(); + + Debug.Log("cmd output : " + output); + Debug.Log("cmd error : " + error); + } + } +} \ No newline at end of file diff --git a/Assets/Editor/Helper/CommandHelper.cs.meta b/Assets/Editor/Helper/CommandHelper.cs.meta new file mode 100644 index 0000000..b275b00 --- /dev/null +++ b/Assets/Editor/Helper/CommandHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c5a6dac91d434baab2b66ee97122eaf3 +timeCreated: 1718813946 \ No newline at end of file diff --git a/Assets/Editor/Helper/InitHelper.cs b/Assets/Editor/Helper/InitHelper.cs new file mode 100644 index 0000000..e433c55 --- /dev/null +++ b/Assets/Editor/Helper/InitHelper.cs @@ -0,0 +1,49 @@ +using UnityEngine; +using UnityEditor; +using System.IO; +namespace UguiToolkit.Editor +{ + public static class InitHelper + { + [InitializeOnLoadMethod] + public static void InitToolkit() + { + if (!Directory.Exists(EditorConst.WorkspaceDirPath)) + { + Directory.CreateDirectory(EditorConst.WorkspaceDirPath); + } + + var G = GlobalManager.Instance; + + SettingScriptObject settingScriptObject = null; + // 查找配置 + if (!File.Exists(EditorConst.SettingFilePath)) + { + // 生成配置 + settingScriptObject = SettingScriptObject.CreateInstance(); + AssetDatabase.CreateAsset(settingScriptObject, EditorConst.SettingFilePath); + } + else + { + settingScriptObject = AssetDatabase.LoadAssetAtPath(EditorConst.SettingFilePath); + } + + G.setting = settingScriptObject; + Debug.Log("prefabForUIDirPath " + G.setting.prefabForUIDirPath); + + CacheScriptObject cacheScriptObject = null; + // 查找配置 + if (!File.Exists(EditorConst.CacheFilePath)) + { + // 生成配置 + cacheScriptObject = CacheScriptObject.CreateInstance(); + AssetDatabase.CreateAsset(cacheScriptObject, EditorConst.CacheFilePath); + } + else + { + cacheScriptObject = AssetDatabase.LoadAssetAtPath(EditorConst.CacheFilePath); + } + G.cache = cacheScriptObject; + } + } +} \ No newline at end of file diff --git a/Assets/Editor/Helper/InitHelper.cs.meta b/Assets/Editor/Helper/InitHelper.cs.meta new file mode 100644 index 0000000..1dced15 --- /dev/null +++ b/Assets/Editor/Helper/InitHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1b65657d48eb4a7b814ab2e60b28757a +timeCreated: 1718725159 \ No newline at end of file diff --git a/Assets/Editor/Helper/PanelHelper.cs b/Assets/Editor/Helper/PanelHelper.cs new file mode 100644 index 0000000..2180bd6 --- /dev/null +++ b/Assets/Editor/Helper/PanelHelper.cs @@ -0,0 +1,35 @@ +using UguiToolkit.Editor.Windows; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; + +namespace UguiToolkit.Editor +{ + public static class PanelHelper + { + [InitializeOnLoadMethod] + public static void AddListener() + { + PrefabStage.prefabStageOpened += OnPrefabStageOpened; + PrefabStage.prefabStageClosing += OnPrefabStageClosing; + + } + + private static void OnPrefabStageOpened(PrefabStage stage) + { + var setting = GlobalManager.Instance.setting; + Debug.Log(stage.assetPath); + Debug.Log(setting.prefabForUIDirPath); + if (!stage.assetPath.StartsWith(setting.prefabForUIDirPath)) return; + + // 打开配置界面 + PanelCacheWindow.ShowWindow(stage); + } + + private static void OnPrefabStageClosing(PrefabStage stage) + { + // 关闭配置界面 + PanelCacheWindow.CloseWindow(); + } + } +} \ No newline at end of file diff --git a/Assets/Editor/Helper/PanelHelper.cs.meta b/Assets/Editor/Helper/PanelHelper.cs.meta new file mode 100644 index 0000000..e1e9d13 --- /dev/null +++ b/Assets/Editor/Helper/PanelHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 431971bf0f7e47b8bb71094641fcf1a6 +timeCreated: 1718725294 \ No newline at end of file diff --git a/Assets/Editor/Manager.meta b/Assets/Editor/Manager.meta new file mode 100644 index 0000000..13492db --- /dev/null +++ b/Assets/Editor/Manager.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eca2e2404300497883981b0e0ade0aa2 +timeCreated: 1718808714 \ No newline at end of file diff --git a/Assets/Editor/Manager/GlobalManager.cs b/Assets/Editor/Manager/GlobalManager.cs new file mode 100644 index 0000000..ae6b46d --- /dev/null +++ b/Assets/Editor/Manager/GlobalManager.cs @@ -0,0 +1,24 @@ +using UguiToolkit.Editor; + +namespace UguiToolkit +{ + public class GlobalManager + { + private static GlobalManager m_instance; + public static GlobalManager Instance + { + get + { + if (m_instance == null) + { + m_instance = new(); + } + + return m_instance; + } + } + + public SettingScriptObject setting; + public CacheScriptObject cache; + } +} \ No newline at end of file diff --git a/Assets/Editor/Manager/GlobalManager.cs.meta b/Assets/Editor/Manager/GlobalManager.cs.meta new file mode 100644 index 0000000..17319ef --- /dev/null +++ b/Assets/Editor/Manager/GlobalManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: db61dea3021343d386672377c5212671 +timeCreated: 1718808545 \ No newline at end of file diff --git a/Assets/Editor/ScriptObject.meta b/Assets/Editor/ScriptObject.meta new file mode 100644 index 0000000..4961d11 --- /dev/null +++ b/Assets/Editor/ScriptObject.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 19ac86eedc8f471eb19551f616fc3cbe +timeCreated: 1718724991 \ No newline at end of file diff --git a/Assets/Editor/ScriptObject/CacheScriptObject.cs b/Assets/Editor/ScriptObject/CacheScriptObject.cs new file mode 100644 index 0000000..4bd3978 --- /dev/null +++ b/Assets/Editor/ScriptObject/CacheScriptObject.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using Unity.Mathematics; +using UnityEngine; +using Sirenix.OdinInspector; + +namespace UguiToolkit.Editor +{ + public class CacheScriptObject : SerializedScriptableObject + { + public Dictionary panelCaches = new(); + } + + [Serializable] + public class PanelCache + { + [LabelText("源图片文件夹路径"), FolderPath] + public string srcImgDirPath; + [LabelText("目标图片信息文件(psd导出)"), FolderPath] + public string layoutInfoFilePath; // Sample.layout.txt + + [LabelText("目标图片文件夹路径")] + public string TargetImgDirPath + { + get + { + if (string.IsNullOrWhiteSpace(layoutInfoFilePath)) return ""; + var dirName = System.IO.Path.GetDirectoryName(layoutInfoFilePath); + var fileName = System.IO.Path.GetFileName(layoutInfoFilePath); + var split = fileName.Split("."); + if (split.Length == 0) return ""; + + return System.IO.Path.Join(dirName, split[0]); + } + } + + // 图片路径 -> 旋转缩放信息 + public Dictionary> rotScaleInfos = new(); + } + + [Serializable] + public struct rotScaleInfoItem + { + public string imgPath; + public float rotiation; + public float2 scale; + } +} + diff --git a/Assets/Editor/ScriptObject/CacheScriptObject.cs.meta b/Assets/Editor/ScriptObject/CacheScriptObject.cs.meta new file mode 100644 index 0000000..9264ba4 --- /dev/null +++ b/Assets/Editor/ScriptObject/CacheScriptObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 08e8e0ec7fe20dc49944597a9fcef9d2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/ScriptObject/SettingScriptObject.cs b/Assets/Editor/ScriptObject/SettingScriptObject.cs new file mode 100644 index 0000000..d9e2241 --- /dev/null +++ b/Assets/Editor/ScriptObject/SettingScriptObject.cs @@ -0,0 +1,11 @@ +using Sirenix.OdinInspector; +using UnityEngine; + +namespace UguiToolkit.Editor +{ + public class SettingScriptObject : ScriptableObject + { + [LabelText("ui预制体存放的路径"), FolderPath] + public string prefabForUIDirPath; + } +} \ No newline at end of file diff --git a/Assets/Editor/ScriptObject/SettingScriptObject.cs.meta b/Assets/Editor/ScriptObject/SettingScriptObject.cs.meta new file mode 100644 index 0000000..b615339 --- /dev/null +++ b/Assets/Editor/ScriptObject/SettingScriptObject.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: da9b1de6f8c64a8da942aed28dcd111d +timeCreated: 1718725010 \ No newline at end of file diff --git a/Assets/Editor/UguiToolkit.Editor.asmdef b/Assets/Editor/UguiToolkit.Editor.asmdef new file mode 100644 index 0000000..5b78ab3 --- /dev/null +++ b/Assets/Editor/UguiToolkit.Editor.asmdef @@ -0,0 +1,19 @@ +{ + "name": "UguiToolkit.Editor", + "rootNamespace": "", + "references": [ + "GUID:d8b63aba1907145bea998dd612889d6b", + "GUID:f5bcd4641e14bde4c8ba640a2285abc5" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/Editor/UguiToolkit.Editor.asmdef.meta b/Assets/Editor/UguiToolkit.Editor.asmdef.meta new file mode 100644 index 0000000..839da46 --- /dev/null +++ b/Assets/Editor/UguiToolkit.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b2a36b11213ce2548897e799a58bbcbc +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Windows.meta b/Assets/Editor/Windows.meta new file mode 100644 index 0000000..1d19bf8 --- /dev/null +++ b/Assets/Editor/Windows.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8f90099ce01c4a319d2d67d4c5c58bcb +timeCreated: 1718811517 \ No newline at end of file diff --git a/Assets/Editor/Windows/PanelCacheWindow.cs b/Assets/Editor/Windows/PanelCacheWindow.cs new file mode 100644 index 0000000..9631b09 --- /dev/null +++ b/Assets/Editor/Windows/PanelCacheWindow.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; +using Sirenix.OdinInspector; +using Sirenix.OdinInspector.Editor; +using Unity.Mathematics; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; +using UnityEngine.Serialization; + +namespace UguiToolkit.Editor.Windows +{ + public class PanelCacheWindow : OdinEditorWindow + { + private static PanelCacheWindow _window; + + + [LabelText("源图片文件夹路径"), FolderPath, SerializeField] + private string m_srcImgDirPath; + [LabelText("目标图片信息文件(psd导出)"), Sirenix.OdinInspector.FilePath(Extensions = "layout.txt"), SerializeField] + private string m_layoutInfoFilePath; + + private PrefabStage m_prefabStage; + private GameObject m_prefab; + private bool m_cacheExist; + private PanelCache panelCache; + + [Button("开启助手", ButtonSizes.Medium)] + private void Start() + { + panelCache.srcImgDirPath = m_srcImgDirPath; + panelCache.layoutInfoFilePath = m_layoutInfoFilePath; + if (!m_cacheExist) + { + panelCache.rotScaleInfos = new(); + CalcRotScaleInfos(); + } + + var cache = GlobalManager.Instance.cache; + cache.panelCaches[m_prefab] = panelCache; + + UguiToolkit.StageManager.CreateStageManager(m_prefabStage.scene, m_prefabStage.prefabContentsRoot); + CloseWindow(); + } + + [Button("重新计算旋转和缩放信息", ButtonSizes.Medium), ShowIf(nameof(m_cacheExist))] + private void CalcRotScaleInfos() + { + // 执行cmd + var jsonData = CommandHelper.CalcRotScale(panelCache.srcImgDirPath, panelCache.TargetImgDirPath, panelCache.rotScaleInfos); + if (jsonData == null || jsonData.data == null) return; + var rotScaleInfos = panelCache.rotScaleInfos; + foreach (var kv in jsonData.data) + { + List rotScaleItemList = new(); + rotScaleInfos[kv.Key] = rotScaleItemList; + foreach (var jsonItemData in kv.Value) + { + rotScaleItemList.Add(new () + { + imgPath = jsonItemData.targetPath, + rotiation = jsonItemData.rot, + scale = new float2(jsonItemData.scale[0], jsonItemData.scale[1]) + }); + } + } + } + + private void Init() + { + var cache = GlobalManager.Instance.cache; + if (cache.panelCaches.TryGetValue(m_prefab, out panelCache)) + { + m_srcImgDirPath = panelCache.srcImgDirPath; + m_layoutInfoFilePath = panelCache.layoutInfoFilePath; + + m_cacheExist = true; + } + else + { + panelCache = new PanelCache(); + } + } + + public static PanelCacheWindow ShowWindow(PrefabStage stage) + { + if (_window) _window.Close(); + _window = CreateWindow(); + _window.titleContent = new ("请选择信息后开启助手"); + _window.m_prefabStage = stage; + _window.m_prefab = AssetDatabase.LoadAssetAtPath(stage.assetPath); + + _window.Show(); + _window.Init(); + + return _window; + } + + public static void CloseWindow() + { + if (_window) + { + _window.Close(); + _window = null; + } + } + } +} \ No newline at end of file diff --git a/Assets/Editor/Windows/PanelCacheWindow.cs.meta b/Assets/Editor/Windows/PanelCacheWindow.cs.meta new file mode 100644 index 0000000..c305047 --- /dev/null +++ b/Assets/Editor/Windows/PanelCacheWindow.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ff70d2b9c2ba4e88bf10b7087a568d07 +timeCreated: 1718811805 \ No newline at end of file diff --git a/Assets/Scripts.meta b/Assets/Scripts.meta new file mode 100644 index 0000000..ecbb271 --- /dev/null +++ b/Assets/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 558d96c5ace2fc7408f8fa23ef43414e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Manager.meta b/Assets/Scripts/Manager.meta new file mode 100644 index 0000000..fb9e424 --- /dev/null +++ b/Assets/Scripts/Manager.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d62d1ab93d3c4beaa6f0d6cf680583da +timeCreated: 1718725983 \ No newline at end of file diff --git a/Assets/Scripts/Manager/ImageActorManager.cs b/Assets/Scripts/Manager/ImageActorManager.cs new file mode 100644 index 0000000..7035d88 --- /dev/null +++ b/Assets/Scripts/Manager/ImageActorManager.cs @@ -0,0 +1,20 @@ +using System; +using UnityEngine; + +namespace UguiToolkit +{ + public class ImageActorManager : MonoBehaviour + { + private void Start() + { + // 初始化所有ImageActor + } + + private void Update() + { + // 检测Image是否被选中,并长按2秒,进入选中状态 + + // 选中状态下,每0.3秒检测 + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Manager/ImageActorManager.cs.meta b/Assets/Scripts/Manager/ImageActorManager.cs.meta new file mode 100644 index 0000000..902ec4a --- /dev/null +++ b/Assets/Scripts/Manager/ImageActorManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c0bceef231ae47849a692ff9fb726646 +timeCreated: 1719934421 \ No newline at end of file diff --git a/Assets/Scripts/Manager/StageManager.cs b/Assets/Scripts/Manager/StageManager.cs new file mode 100644 index 0000000..bbe2b19 --- /dev/null +++ b/Assets/Scripts/Manager/StageManager.cs @@ -0,0 +1,58 @@ +using System; +using UnityEngine; +using UnityEditor; +using UnityEngine.SceneManagement; + +namespace UguiToolkit +{ + [ExecuteAlways] + public class StageManager : MonoBehaviour + { + private Scene m_scene; + public Scene Scene => m_scene; + private GameObject m_prefabContentsRoot; + public GameObject PrefabContentsRoot => m_prefabContentsRoot; + + private static StageManager m_instance; + public static StageManager Instance + { + get + { + if (!m_instance) + { + Debug.LogError("[E] stageManager 不存在,请先进入预制体SceneStage场景"); + } + + return m_instance; + } + } + + public static void CreateStageManager(Scene scene, GameObject prefabContentsRoot) + { + var go = new GameObject(); + go.name = "StageManager"; + go.transform.parent = prefabContentsRoot.transform; + m_instance = go.AddComponent(); + m_instance.m_scene = scene; + m_instance.m_prefabContentsRoot = prefabContentsRoot; + + go.hideFlags = HideFlags.DontSave; + } + + private T CreateSubManager() where T : MonoBehaviour + { + var go = new GameObject(); + go.name = typeof(T).Name; + go.transform.parent = PrefabContentsRoot.transform; + var t = go.AddComponent(); + + go.hideFlags = HideFlags.DontSave; + return t; + } + + private void Start() + { + CreateSubManager(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Manager/StageManager.cs.meta b/Assets/Scripts/Manager/StageManager.cs.meta new file mode 100644 index 0000000..5b76e0f --- /dev/null +++ b/Assets/Scripts/Manager/StageManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7649968946ba4e1fbf16181d36d339ba +timeCreated: 1718726030 \ No newline at end of file diff --git a/Assets/Scripts/UguiToolkit.asmdef b/Assets/Scripts/UguiToolkit.asmdef new file mode 100644 index 0000000..fd2c2c1 --- /dev/null +++ b/Assets/Scripts/UguiToolkit.asmdef @@ -0,0 +1,18 @@ +{ + "name": "UguiToolkit", + "rootNamespace": "", + "references": [], + "includePlatforms": [ + "Editor", + "WindowsStandalone32", + "WindowsStandalone64" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/Scripts/UguiToolkit.asmdef.meta b/Assets/Scripts/UguiToolkit.asmdef.meta new file mode 100644 index 0000000..65f2854 --- /dev/null +++ b/Assets/Scripts/UguiToolkit.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f5bcd4641e14bde4c8ba640a2285abc5 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..1580de8 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "com.soviby.unity.ui.ugui-toolkit", + "displayName": "UguiToolkit", + "description": "Ugui拼接辅助帮手", + "version": "0.0.1", + "unity": "2022.3", + "author": "Soviby", + "dependencies": { + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..01b9e72 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5260e23a46c07ca4099a65b4a9011199 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: