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