This commit is contained in:
Soviby 2024-12-03 00:43:23 +08:00
commit 6b9f045749
9 changed files with 168 additions and 32 deletions

View File

@ -148,7 +148,7 @@ function s2t(t) { return stringIDToTypeID(t) }
this.layerBlendAll(copiedDoc, copiedDoc); this.layerBlendAll(copiedDoc, copiedDoc);
// this.removeCommentoutLayers(copiedDoc, copiedDoc); // this.removeCommentoutLayers(copiedDoc, copiedDoc);
this.cropLayers(copiedDoc); this.cropLayers(copiedDoc);
this.resizePsd(copiedDoc); // this.resizePsd(copiedDoc);
this.selectDocumentArea(copiedDoc); this.selectDocumentArea(copiedDoc);
this.ungroupArtboard(copiedDoc); this.ungroupArtboard(copiedDoc);
this.clipping(copiedDoc, copiedDoc); this.clipping(copiedDoc, copiedDoc);
@ -312,37 +312,54 @@ function s2t(t) { return stringIDToTypeID(t) }
{ {
layer.name = "#" + layer.name; layer.name = "#" + layer.name;
} }
}else{ // 文字
if (layer.name.startsWith("%"))
{
layer.name = layer.name.substring(1, layer.name.length);
}
else
{
layer.name = "#" + layer.name.substring(1, layer.name.length);
}
} }
} }
var ss = layer.name.split("@"); //解锁图层
//忽略但保留父节点宽高影响,则不移除 if (layer.allLocked)
if (Util.isInferiorIgnoreByName(ss[0])) { layer.allLocked = false
if (Util.isIgnoreByName(layer.name)) {
removeLayers.push(layer)
continue continue
} }
// 去空格
layer.name = layer.name.replace(/\s+/g, "");
// 特殊符号处理
layer.name = layer.name.replace(/¥/g, "-").replace(/\./g, "-")
.replace(/\[/g, "-").replace(/\]/g, "-").replace(/\#/g, "-")
.replace(/\:/g, "-").replace(/\%/g, "-").replace(/\/g, "-")
.replace(/\+/g, "-");
//移除不可见图层 //移除不可见图层
if (layer.visible === false || Util.isIgnoreByName(ss[0])) { if (layer.visible === false) {
// 不可见的就push到移除layer中去 // 不可见的就push到移除layer中去
removeLayers.push(layer) removeLayers.push(layer)
continue continue
} }
if (layer.bounds[0].value === 0 && layer.bounds[1].value === 0 && layer.bounds[2].value === 0 && layer.bounds[3].value === 0) { if (layer.bounds[0].value === 0 && layer.bounds[1].value === 0 && layer.bounds[2].value === 0 && layer.bounds[3].value === 0) {
removeLayers.push(layer) removeLayers.push(layer)
continue continue
} }
//解锁所有图层
if (layer.allLocked)
layer.allLocked = false
//光栅所有图层 //光栅所有图层
if (layer.typename === 'ArtLayer') { if (layer.typename === 'ArtLayer') {
if (layer.kind !== LayerKind.TEXT) { if (layer.kind !== LayerKind.TEXT) {
this.rasterize(layer) this.rasterize(layer)
} }
} }
var ss = layer.name.split("@");
opt = Util.parseOption(ss[1]); opt = Util.parseOption(ss[1]);
//检查大小命名格式 //检查大小命名格式
@ -384,11 +401,23 @@ function s2t(t) { return stringIDToTypeID(t) }
} }
//文件名合规检测 //文件名合规检测
//var reg = /^[0-9a-zA-Z\u4e00-\u9fa5"_""\-"]*$/g; var regCn = /^[0-9a-zA-Z\u4e00-\u9fa5"_""\-"]*$/g;
var reg = /^[0-9a-zA-Z"_""\-"]*$/g; var reg = /^[0-9a-zA-Z"_""\-"]*$/g;
if (!reg.test(ss[0])) { // if (!reg.test(ss[0])) {
alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_") // alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_")
return false; // return false;
// }
if (layer.typename === 'ArtLayer' && layer.kind !== LayerKind.TEXT)
{
if (!reg.test(ss[0])) {
alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_")
return false;
}
}else{
if (!regCn.test(ss[0])) {
alert("\"" + layer.name + "\" 名字不合法,只能含有中文、英文、数字、-、_")
return false;
}
} }
//递归检测 //递归检测
@ -1482,12 +1511,7 @@ function s2t(t) { return stringIDToTypeID(t) }
// 忽略 // 忽略
Util.isIgnoreByName = function (name) { Util.isIgnoreByName = function (name) {
return name.startsWith('#') || Util.isInferiorIgnoreByName(name) return name.startsWith('#')
};
// 忽略,但保留父节点宽高影响
Util.isInferiorIgnoreByName = function (name) {
return name.startsWith('$')
}; };
Util.UpdateHash = function (hashTarget, hashRes) { Util.UpdateHash = function (hashTarget, hashRes) {

View File

@ -1,2 +1,2 @@
cd /d %~dp0 cd /d %~dp0
start step2.exe -src C:\Users\93685\Desktop\Sample -dst C:\Users\93685\Desktop\Sample_output start step2.exe -src C:\Users\biaosong\Desktop\yueka -dst C:\Users\biaosong\Desktop\yueka_output

View File

@ -70,7 +70,7 @@ namespace UguiToolkit.Editor
rtf.sizeDelta = new Vector2(m_elementInfo.w, m_elementInfo.h); rtf.sizeDelta = new Vector2(m_elementInfo.w, m_elementInfo.h);
m_selectionImg = go.AddComponent<UnityEngine.UI.Image>(); m_selectionImg = go.AddComponent<UnityEngine.UI.Image>();
m_selectionImg.color = new Color(0, 1, 0, 0.15f); m_selectionImg.color = new Color(0, 1, 0, 0.2f);
} }
} }
} }

View File

@ -1,10 +1,15 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using Sirenix.Utilities;
using System.Linq;
using TMPro; using TMPro;
using Unity.Mathematics; using Unity.Mathematics;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.TextCore.Text;
using UnityEngine.UI; using UnityEngine.UI;
using static UguiToolkit.Editor.LayoutInfo;
namespace UguiToolkit.Editor namespace UguiToolkit.Editor
{ {
@ -26,8 +31,7 @@ namespace UguiToolkit.Editor
ui.color = ElementInfo.color; ui.color = ElementInfo.color;
ui.alignment = TextAlignmentOptions.Center; ui.alignment = TextAlignmentOptions.Center;
var rectTransform = ui.rectTransform; SetTMPByTextInfo(ui, ElementInfo);
rectTransform.sizeDelta = new Vector2(ElementInfo.w + 10, ElementInfo.h + 10);
} }
public override void InitPreview() public override void InitPreview()
@ -42,6 +46,63 @@ namespace UguiToolkit.Editor
ApplyTransform(transform); ApplyTransform(transform);
} }
private static void SetTMPByTextInfo(TextMeshProUGUI ui, LayoutInfo.TextInfo textInfo)
{
// TODO: ×ÔÐÐÀ©Õ¹
if (GetTextFontPreset(textInfo, out var textFontPreset))
{
ui.font = textFontPreset.tmpAsset;
if (!string.IsNullOrEmpty(textFontPreset.materialPreset))
{
var materialPresets = TMPro.EditorUtilities.TMP_EditorUtility.FindMaterialReferences(textFontPreset.tmpAsset);
if (materialPresets != null)
{
var material = materialPresets.FirstOrDefault((material) => {
if (material.name == textFontPreset.materialPreset) return true;
return false;
});
if (material) ui.fontMaterial = material;
}
}
var rectTransform = ui.rectTransform;
rectTransform.sizeDelta = new Vector2(textInfo.w + textFontPreset.sizeOffset.x, textInfo.h + textFontPreset.sizeOffset.y);
}
}
private static bool GetTextFontPreset(LayoutInfo.TextInfo textInfo, out TextFontPresetOfUnity textFontPreset)
{
textFontPreset = null;
var setting = GlobalManager.Instance.setting;
if (setting != null && setting.textFontList != null)
{
foreach (var textFontInfoOfPsd in setting.textFontList)
{
if (textFontInfoOfPsd.fontNameOfPsd != null && textFontInfoOfPsd.fontNameOfPsd.Contains(textInfo.font))
{
if (textFontInfoOfPsd.stroke)
{
if (!textInfo.IsStroke) return false;
if (!textFontInfoOfPsd.allStrokeColor && textFontInfoOfPsd.strokeColor != textInfo.strokeColor) return false;
textFontPreset = textFontInfoOfPsd;
return true;
}
else
{
if (!textInfo.IsStroke) {
textFontPreset = textFontInfoOfPsd;
return true;
}
}
}
}
}
return false;
}
} }
} }

View File

@ -37,16 +37,22 @@ namespace UguiToolkit.Editor
} }
else if (layoutElementJsonData.type == "Text") else if (layoutElementJsonData.type == "Text")
{ {
ColorUtility.TryParseHtmlString("#" + layoutElementJsonData.color, out var color); ColorUtility.TryParseHtmlString("#" + layoutElementJsonData.color, out var fontColor);
Color strokeColor = Color.white;
if (!string.IsNullOrEmpty(layoutElementJsonData.strokeColor))
ColorUtility.TryParseHtmlString("#" + layoutElementJsonData.strokeColor, out strokeColor);
elementInfos.Add(new LayoutInfo.TextInfo() elementInfos.Add(new LayoutInfo.TextInfo()
{ {
name = layoutElementJsonData.name, name = layoutElementJsonData.name,
text = layoutElementJsonData.text, text = layoutElementJsonData.text,
font = layoutElementJsonData.font, font = layoutElementJsonData.font,
strokeSize = layoutElementJsonData.strokeSize,
strokeColor = strokeColor,
size = layoutElementJsonData.size, size = layoutElementJsonData.size,
align = layoutElementJsonData.align, align = layoutElementJsonData.align,
color = color, color = fontColor,
x = layoutElementJsonData.x, x = layoutElementJsonData.x,
y = layoutElementJsonData.y, y = layoutElementJsonData.y,
w = layoutElementJsonData.w, w = layoutElementJsonData.w,
@ -113,6 +119,8 @@ namespace UguiToolkit.Editor
public string color; public string color;
public string align; public string align;
public string font; public string font;
public float strokeSize;
public string strokeColor;
} }
} }

View File

@ -77,6 +77,10 @@ namespace UguiToolkit.Editor
{ {
entity.ApplyData(text); entity.ApplyData(text);
} }
else if (tf.TryGetComponent<TMPro.TextMeshProUGUI>(out var temp))
{
entity.ApplyData(temp);
}
m_lastSelectionGo = m_curSelectionGo; m_lastSelectionGo = m_curSelectionGo;
m_lastSelectionEntity = entity; m_lastSelectionEntity = entity;
@ -160,11 +164,12 @@ namespace UguiToolkit.Editor
private void OnSelectionChanged() private void OnSelectionChanged()
{ {
if (m_noSelection) return;
m_curSelectionGo = null; m_curSelectionGo = null;
m_selectionEntities.Clear(); m_selectionEntities.Clear();
m_entityRoot.gameObject.SetActive(false); m_entityRoot.gameObject.SetActive(false);
if (m_noSelection) return;
if (Selection.activeGameObject != null && m_panelCache != null) if (Selection.activeGameObject != null && m_panelCache != null)
{ {
var activeGameObject = Selection.activeGameObject; var activeGameObject = Selection.activeGameObject;
@ -196,7 +201,8 @@ namespace UguiToolkit.Editor
else { else {
imgEntity.SetTransform(rotScale.rotiation, rotScale.scale, false); imgEntity.SetTransform(rotScale.rotiation, rotScale.scale, false);
} }
imgEntity.ApplyTransform(imgEntity.transform);
imgEntity.ShowSelectionImg(true); imgEntity.ShowSelectionImg(true);
m_selectionEntities.Add(imgEntity); m_selectionEntities.Add(imgEntity);
@ -225,7 +231,8 @@ namespace UguiToolkit.Editor
textEntity.gameObject.SetActive(false); textEntity.gameObject.SetActive(false);
} }
} }
else if (activeGameObject.TryGetComponent<UnityEngine.UI.Text>(out var text)) else if (activeGameObject.TryGetComponent<UnityEngine.UI.Text>(out var _)
|| activeGameObject.TryGetComponent<TMPro.TextMeshProUGUI>(out var _))
{ {
bool IsInside = false; bool IsInside = false;
m_entityRoot.gameObject.SetActive(true); m_entityRoot.gameObject.SetActive(true);
@ -291,6 +298,11 @@ namespace UguiToolkit.Editor
m_entityRoot.localRotation = Quaternion.identity; m_entityRoot.localRotation = Quaternion.identity;
m_entityRoot.localScale = Vector3.one; m_entityRoot.localScale = Vector3.one;
var canvas = m_entityRoot.gameObject.AddComponent<Canvas>();
canvas.pixelPerfect = true;
canvas.overrideSorting = true;
canvas.sortingOrder = 200;
m_imageEntities = new(m_panelCache.layoutInfo.Count); m_imageEntities = new(m_panelCache.layoutInfo.Count);
m_textEntities = new(m_panelCache.layoutInfo.Count); m_textEntities = new(m_panelCache.layoutInfo.Count);
m_selectionEntities = new(m_panelCache.layoutInfo.Count); m_selectionEntities = new(m_panelCache.layoutInfo.Count);

View File

@ -228,6 +228,10 @@ namespace UguiToolkit.Editor
public Color color; public Color color;
public string align; public string align;
public string font; public string font;
public float strokeSize;
public Color strokeColor;
public bool IsStroke => strokeSize != 0;
} }
} }

View File

@ -1,16 +1,42 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine; using UnityEngine;
namespace UguiToolkit.Editor namespace UguiToolkit.Editor
{ {
public class SettingScriptObject : ScriptableObject public class SettingScriptObject : SerializedScriptableObject
{ {
[LabelText("ui预制体存放的路径"), FolderPath] [LabelText("ui预制体存放的路径"), FolderPath]
public string prefabForUIDirPath; public string prefabForUIDirPath;
public float distanceDifference = 0.2f; public float distanceDifference = 0.2f;
public bool useTMP; public bool useTMP;
// 项目配置
public List <TextFontPresetOfUnity> textFontList = new ();
}
[Serializable]
public class TextFontPresetOfUnity
{
[Title("Ps属性")]
public string name;
public List<string> fontNameOfPsd;
public bool stroke; // 使用描边
public Color strokeColor;
public bool allStrokeColor;
public bool shadow; // 使用阴影
public Color shadowColor;
public bool allShadowColor;
[Title("Unity属性")]
public float2 sizeOffset;
public TMPro.TMP_FontAsset tmpAsset;
public string materialPreset;
} }
} }
#endif #endif

View File

@ -3,7 +3,8 @@
"rootNamespace": "", "rootNamespace": "",
"references": [ "references": [
"GUID:d8b63aba1907145bea998dd612889d6b", "GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:6055be8ebefd69e48b49212b09b47b2f" "GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:6546d7765b4165b40850b3667f981c26"
], ],
"includePlatforms": [ "includePlatforms": [
"Editor", "Editor",