优化tmp字体
This commit is contained in:
parent
7906c0c87c
commit
dc8b45964c
@ -10,7 +10,7 @@ namespace UguiToolkit.Editor
|
||||
{
|
||||
void ApplyTransform(Transform tf);
|
||||
bool IsInside(Transform tf);
|
||||
void ApplyData<T>(T ui) where T: MonoBehaviour;
|
||||
void ApplyData<T>(T ui) where T: Component;
|
||||
void InitPreview();
|
||||
void ShowSelectionImg(bool show);
|
||||
GameObject gameObject { get; }
|
||||
@ -51,7 +51,7 @@ namespace UguiToolkit.Editor
|
||||
CreateSelectionImg();
|
||||
}
|
||||
|
||||
public void ApplyData<T>(T ui) where T : MonoBehaviour
|
||||
public void ApplyData<T>(T ui) where T : Component
|
||||
{
|
||||
OnApplyData(ui as T1);
|
||||
}
|
||||
|
@ -74,6 +74,10 @@ namespace UguiToolkit.Editor
|
||||
|
||||
private static bool GetTextFontPreset(LayoutInfo.TextInfo textInfo, out TextFontPresetOfUnity textFontPreset)
|
||||
{
|
||||
float CalcColorDifference(in Color color1, in Color color2)
|
||||
{
|
||||
return math.abs(color1.r - color2.r) * 255 + math.abs(color1.g - color2.g) * 255 + math.abs(color1.b - color2.b) * 255;
|
||||
}
|
||||
textFontPreset = null;
|
||||
var setting = GlobalManager.Instance.setting;
|
||||
if (setting != null && setting.textFontList != null)
|
||||
@ -84,18 +88,15 @@ namespace UguiToolkit.Editor
|
||||
{
|
||||
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;
|
||||
if (!textInfo.IsStroke) continue;
|
||||
if (!textFontInfoOfPsd.allStrokeColor)
|
||||
{
|
||||
if (CalcColorDifference(textFontInfoOfPsd.strokeColor ,textInfo.strokeColor) > textFontInfoOfPsd.strokeColorThreshold) continue;
|
||||
}
|
||||
}
|
||||
|
||||
textFontPreset = textFontInfoOfPsd;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
#if UNITY_EDITOR
|
||||
using Sirenix.OdinInspector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
@ -27,6 +29,7 @@ namespace UguiToolkit.Editor
|
||||
[LabelText("脱离选择控制"), ShowInInspector]
|
||||
private bool m_noSelection;
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
private StageManager m_stageManager;
|
||||
private HashSet<string> m_checkImgPaths;
|
||||
private float m_lastCheckTime = 0f;
|
||||
@ -38,6 +41,8 @@ namespace UguiToolkit.Editor
|
||||
{
|
||||
var globalMng = GlobalManager.Instance;
|
||||
globalMng.showHierarchyOfEntityChanged += OnUpdateHierarchyOfEntityAllEntity;
|
||||
globalMng.showBackgroundChanged += OnUpdateBackgroundShow;
|
||||
globalMng.createAllTextEntity += CreateAllTextEntity;
|
||||
m_useTMP = globalMng.setting.useTMP;
|
||||
|
||||
Selection.selectionChanged += OnSelectionChanged;
|
||||
@ -47,7 +52,10 @@ namespace UguiToolkit.Editor
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GlobalManager.Instance.showHierarchyOfEntityChanged -= OnUpdateHierarchyOfEntityAllEntity;
|
||||
var globalMng = GlobalManager.Instance;
|
||||
globalMng.showHierarchyOfEntityChanged -= OnUpdateHierarchyOfEntityAllEntity;
|
||||
globalMng.showBackgroundChanged -= OnUpdateBackgroundShow;
|
||||
globalMng.createAllTextEntity -= CreateAllTextEntity;
|
||||
Selection.selectionChanged -= OnSelectionChanged;
|
||||
}
|
||||
|
||||
@ -130,6 +138,26 @@ namespace UguiToolkit.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateAllTextEntity()
|
||||
{
|
||||
var root = m_stageManager.PrefabContentsRoot;
|
||||
var textsTf = root.transform.Find("__texts__");
|
||||
if (textsTf) DestroyImmediate(textsTf.gameObject);
|
||||
|
||||
if (m_textEntities == null) return;
|
||||
var textsGo = new GameObject("__texts__", typeof(RectTransform));
|
||||
textsGo.transform.parent = root.transform;
|
||||
|
||||
Type textType = m_useTMP ? typeof(TextMeshProUGUI) : typeof(Text);
|
||||
foreach (var textEntity in m_textEntities)
|
||||
{
|
||||
var newText = new GameObject(textEntity.gameObject.name, typeof(RectTransform), textType);
|
||||
newText.transform.parent = textsGo.transform;
|
||||
textEntity.ApplyData(newText.GetComponent(textType));
|
||||
textEntity.ApplyTransform(newText.transform);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitBackground()
|
||||
{
|
||||
if (m_background) DestroyImmediate(m_background.gameObject);
|
||||
@ -315,6 +343,7 @@ namespace UguiToolkit.Editor
|
||||
public void InitAllEntity(PanelCache panelCache)
|
||||
{
|
||||
this.m_panelCache = panelCache;
|
||||
this.m_stageManager = StageManager.Instance;
|
||||
|
||||
// 创建所有实例
|
||||
CreateAllEntity();
|
||||
@ -324,6 +353,14 @@ namespace UguiToolkit.Editor
|
||||
CheckPanelCache();
|
||||
}
|
||||
|
||||
private void OnUpdateBackgroundShow(bool show)
|
||||
{
|
||||
if (m_background)
|
||||
{
|
||||
m_background.gameObject.SetActive(show);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpdateHierarchyOfEntityAllEntity(bool show)
|
||||
{
|
||||
UpdateHierarchyOfEntity(show, m_entityRoot.gameObject);
|
||||
|
@ -31,6 +31,16 @@ namespace UguiToolkit
|
||||
/// </summary>
|
||||
public Action<bool> showHierarchyOfEntityChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 背景显示发生改变
|
||||
/// </summary>
|
||||
public Action<bool> showBackgroundChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 创建所有TextEntity
|
||||
/// </summary>
|
||||
public Action createAllTextEntity;
|
||||
|
||||
public void SaveCache(GameObject asset, PanelCache panelCache)
|
||||
{
|
||||
cache.panelCaches[asset] = panelCache;
|
||||
|
@ -10,15 +10,20 @@ namespace UguiToolkit
|
||||
[ExecuteAlways]
|
||||
public class StageManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
private Scene m_scene;
|
||||
public Scene Scene => m_scene;
|
||||
[SerializeField, HideInInspector]
|
||||
private GameObject m_prefabContentsRoot;
|
||||
public GameObject PrefabContentsRoot => m_prefabContentsRoot;
|
||||
[SerializeField, HideInInspector]
|
||||
private Dictionary<Type, IManager> m_mngMap = new Dictionary<Type, IManager>();
|
||||
|
||||
public GameObject PrefabAsset => m_prefabAsset;
|
||||
[SerializeField, HideInInspector]
|
||||
private GameObject m_prefabAsset;
|
||||
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
private static StageManager m_instance;
|
||||
public static StageManager Instance
|
||||
{
|
||||
|
@ -1,7 +1,10 @@
|
||||
#if UNITY_EDITOR
|
||||
using Sirenix.OdinInspector;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro.EditorUtilities;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
@ -28,15 +31,28 @@ namespace UguiToolkit.Editor
|
||||
public List<string> fontNameOfPsd;
|
||||
public bool stroke; // 使用描边
|
||||
public Color strokeColor;
|
||||
public float strokeColorThreshold;
|
||||
public bool allStrokeColor;
|
||||
public bool shadow; // 使用阴影
|
||||
public Color shadowColor;
|
||||
public float shadowColorThreshold;
|
||||
public bool allShadowColor;
|
||||
|
||||
[Title("Unity属性")]
|
||||
public float2 sizeOffset;
|
||||
public TMPro.TMP_FontAsset tmpAsset;
|
||||
[ShowIf(nameof(ShowMaterialPreset)), ValueDropdown(nameof(GetAllMaterialPreset), IsUniqueList = true)]
|
||||
public string materialPreset;
|
||||
private bool ShowMaterialPreset => tmpAsset;
|
||||
|
||||
private IEnumerable GetAllMaterialPreset()
|
||||
{
|
||||
if (tmpAsset != null)
|
||||
return TMP_EditorUtility.FindMaterialReferences(tmpAsset)
|
||||
.Select(x => new ValueDropdownItem(x.name, x.name));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -9,8 +9,11 @@ namespace UguiToolkit.Editor.Windows
|
||||
[SerializeField, HideInInspector]
|
||||
private bool m_showHierarchyOfEntityChange = false;
|
||||
|
||||
[LabelText("实例Hierarchy是否显示"), ShowInInspector]
|
||||
public bool ShowHierarchyOfEntity
|
||||
[SerializeField, HideInInspector]
|
||||
private bool m_showBackground = true;
|
||||
|
||||
[LabelText("Hierarchy是否显示"), ShowInInspector]
|
||||
private bool ShowHierarchyOfEntity
|
||||
{
|
||||
get => m_showHierarchyOfEntityChange;
|
||||
set
|
||||
@ -21,6 +24,24 @@ namespace UguiToolkit.Editor.Windows
|
||||
}
|
||||
}
|
||||
|
||||
[LabelText("背景是否显示"), ShowInInspector]
|
||||
private bool ShowBackground
|
||||
{
|
||||
get => m_showBackground;
|
||||
set
|
||||
{
|
||||
m_showBackground = value;
|
||||
|
||||
GlobalManager.Instance.showBackgroundChanged?.Invoke(m_showBackground);
|
||||
}
|
||||
}
|
||||
|
||||
[Button("创建所有Text")]
|
||||
private void CreateAllTextEntity()
|
||||
{
|
||||
GlobalManager.Instance.createAllTextEntity?.Invoke();
|
||||
}
|
||||
|
||||
public override string GettitleContent()
|
||||
{
|
||||
return "助手编辑界面";
|
||||
|
Loading…
Reference in New Issue
Block a user