diff options
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/UI/Core')
-rw-r--r-- | Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontData.cs | 2 | ||||
-rw-r--r-- | Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontUpdateTracker.cs | 10 | ||||
-rw-r--r-- | Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/Text.cs (renamed from Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Text.cs) | 7 | ||||
-rw-r--r-- | Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/Text.cs.meta (renamed from Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Text.cs.meta) | 0 |
4 files changed, 14 insertions, 5 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontData.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontData.cs index 760c9ee..3a85af1 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontData.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontData.cs @@ -82,7 +82,7 @@ namespace UnityEngine.UI public int fontSize { get { return m_FontSize; } - set { m_FontSize = value; } + set { Debug.Log("FontData.fontSize"); m_FontSize = value; } } public FontStyle fontStyle diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontUpdateTracker.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontUpdateTracker.cs index 2228457..a63d62b 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontUpdateTracker.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/FontUpdateTracker.cs @@ -4,6 +4,8 @@ using UnityEngine; namespace UnityEngine.UI { + // 全局记录使用了某个Font字体的所有Text,当这个Font的GlyphAtlas大小改变的时候通知这些Text重建mesh(更新UV) + // 因为GlyphAtlas大小改变了,原先的UV已经不对了 public static class FontUpdateTracker { static Dictionary<Font, HashSet<Text>> m_Tracked = new Dictionary<Font, HashSet<Text>>(); @@ -16,10 +18,12 @@ namespace UnityEngine.UI HashSet<Text> exists; m_Tracked.TryGetValue(t.font, out exists); if (exists == null) - { - // The textureRebuilt event is global for all fonts, so we add our delegate the first time we register *any* Text + {
+ // font texture重新生成的时候会调这个回调,然后需要Text组件重建mesh的UV数据,因为原先的fontGlyph里的UV已经不准了
+ // https://docs.unity3d.com/ScriptReference/Font-textureRebuilt.html
+ // The textureRebuilt event is global for all fonts, so we add our delegate the first time we register *any* Text
if (m_Tracked.Count == 0) - Font.textureRebuilt += RebuildForFont; + Font.textureRebuilt += RebuildForFont; exists = new HashSet<Text>(); m_Tracked.Add(t.font, exists); diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Text.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/Text.cs index c087983..3d3d17b 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Text.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/Text.cs @@ -32,6 +32,7 @@ namespace UnityEngine.UI useLegacyMeshGeneration = false; } + // text generator,得到字符串在glyph atlas中的UV,构建mesh /// <summary> /// Get or set the material used by this Text. /// </summary> @@ -260,6 +261,7 @@ namespace UnityEngine.UI } set { + // font size改变的时候重建mesh if (m_FontData.fontSize == value) return; m_FontData.fontSize = value; @@ -391,6 +393,7 @@ namespace UnityEngine.UI font = Resources.GetBuiltinResource<Font>("Arial.ttf"); } + // 根据FontData设置TextGenerationSettings public TextGenerationSettings GetGenerationSettings(Vector2 extents) { var settings = new TextGenerationSettings(); @@ -407,7 +410,7 @@ namespace UnityEngine.UI settings.textAnchor = m_FontData.alignment; settings.alignByGeometry = m_FontData.alignByGeometry; settings.scaleFactor = pixelsPerUnit; - settings.color = color; + settings.color = color; // 这里是顶点颜色 settings.font = font; settings.pivot = rectTransform.pivot; settings.richText = m_FontData.richText; @@ -451,6 +454,7 @@ namespace UnityEngine.UI Vector2 extents = rectTransform.rect.size; + // 生成对应的网格数据(顶点、UV) var settings = GetGenerationSettings(extents); cachedTextGenerator.PopulateWithErrors(text, settings, gameObject); @@ -543,6 +547,7 @@ namespace UnityEngine.UI base.OnRebuildRequested(); } + // 当编辑器里修改了参数值的时候调这个回调,setDirty,后续重建mesh // The Text inspector editor can change the font, and we need a way to track changes so that we get the appropriate rebuild callbacks // We can intercept changes in OnValidate, and keep track of the previous font reference protected override void OnValidate() diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Text.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/Text.cs.meta index ea6d1d8..ea6d1d8 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Text.cs.meta +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Font/Text.cs.meta |