添加字体样式

This commit is contained in:
biaosong 2024-12-02 22:14:39 +08:00
parent 778a307732
commit b8f841a35b
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.removeCommentoutLayers(copiedDoc, copiedDoc);
this.cropLayers(copiedDoc);
this.resizePsd(copiedDoc);
// this.resizePsd(copiedDoc);
this.selectDocumentArea(copiedDoc);
this.ungroupArtboard(copiedDoc);
this.clipping(copiedDoc, copiedDoc);
@ -312,37 +312,54 @@ function s2t(t) { return stringIDToTypeID(t) }
{
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 (Util.isInferiorIgnoreByName(ss[0])) {
//解锁图层
if (layer.allLocked)
layer.allLocked = false
if (Util.isIgnoreByName(layer.name)) {
removeLayers.push(layer)
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中去
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)
}
}
var ss = layer.name.split("@");
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;
if (!reg.test(ss[0])) {
alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_")
return false;
// if (!reg.test(ss[0])) {
// alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_")
// 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) {
return name.startsWith('#') || Util.isInferiorIgnoreByName(name)
};
// 忽略,但保留父节点宽高影响
Util.isInferiorIgnoreByName = function (name) {
return name.startsWith('$')
return name.startsWith('#')
};
Util.UpdateHash = function (hashTarget, hashRes) {

View File

@ -1,2 +1,2 @@
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);
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
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Sirenix.OdinInspector;
using Sirenix.Utilities;
using System.Linq;
using TMPro;
using Unity.Mathematics;
using UnityEditor;
using UnityEngine;
using UnityEngine.TextCore.Text;
using UnityEngine.UI;
using static UguiToolkit.Editor.LayoutInfo;
namespace UguiToolkit.Editor
{
@ -26,8 +31,7 @@ namespace UguiToolkit.Editor
ui.color = ElementInfo.color;
ui.alignment = TextAlignmentOptions.Center;
var rectTransform = ui.rectTransform;
rectTransform.sizeDelta = new Vector2(ElementInfo.w + 10, ElementInfo.h + 10);
SetTMPByTextInfo(ui, ElementInfo);
}
public override void InitPreview()
@ -42,6 +46,63 @@ namespace UguiToolkit.Editor
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")
{
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()
{
name = layoutElementJsonData.name,
text = layoutElementJsonData.text,
font = layoutElementJsonData.font,
strokeSize = layoutElementJsonData.strokeSize,
strokeColor = strokeColor,
size = layoutElementJsonData.size,
align = layoutElementJsonData.align,
color = color,
color = fontColor,
x = layoutElementJsonData.x,
y = layoutElementJsonData.y,
w = layoutElementJsonData.w,
@ -113,6 +119,8 @@ namespace UguiToolkit.Editor
public string color;
public string align;
public string font;
public float strokeSize;
public string strokeColor;
}
}

View File

@ -77,6 +77,10 @@ namespace UguiToolkit.Editor
{
entity.ApplyData(text);
}
else if (tf.TryGetComponent<TMPro.TextMeshProUGUI>(out var temp))
{
entity.ApplyData(temp);
}
m_lastSelectionGo = m_curSelectionGo;
m_lastSelectionEntity = entity;
@ -160,11 +164,12 @@ namespace UguiToolkit.Editor
private void OnSelectionChanged()
{
if (m_noSelection) return;
m_curSelectionGo = null;
m_selectionEntities.Clear();
m_entityRoot.gameObject.SetActive(false);
if (m_noSelection) return;
if (Selection.activeGameObject != null && m_panelCache != null)
{
var activeGameObject = Selection.activeGameObject;
@ -196,7 +201,8 @@ namespace UguiToolkit.Editor
else {
imgEntity.SetTransform(rotScale.rotiation, rotScale.scale, false);
}
imgEntity.ApplyTransform(imgEntity.transform);
imgEntity.ShowSelectionImg(true);
m_selectionEntities.Add(imgEntity);
@ -225,7 +231,8 @@ namespace UguiToolkit.Editor
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;
m_entityRoot.gameObject.SetActive(true);
@ -291,6 +298,11 @@ namespace UguiToolkit.Editor
m_entityRoot.localRotation = Quaternion.identity;
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_textEntities = 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 string align;
public string font;
public float strokeSize;
public Color strokeColor;
public bool IsStroke => strokeSize != 0;
}
}

View File

@ -1,16 +1,42 @@
#if UNITY_EDITOR
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
namespace UguiToolkit.Editor
{
public class SettingScriptObject : ScriptableObject
public class SettingScriptObject : SerializedScriptableObject
{
[LabelText("ui预制体存放的路径"), FolderPath]
public string prefabForUIDirPath;
public float distanceDifference = 0.2f;
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

View File

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