1.新增局部变量 int nextCharCode = 0; 它与方法内另一个局部变量 int charCode 在逻辑意义上相近。
1 2 3 4
............... int charCode = 0; // Holds the character code of the currently being processed character. int nextCharCode = 0; // by paperlens: Holds the character code of the next character of the processed character. ...............
2.在源代码记录charCode的同时,记录nextCharCode。
1 2 3 4 5 6 7 8 9 10 11
............... // Parse through Character buffer to read HTML tags and begin creating mesh. for (int i = 0; i < m_TextProcessingArray.Length && m_TextProcessingArray[i].unicode != 0; i++) { charCode = m_TextProcessingArray[i].unicode; // by paperlens: nextCharCode if (m_TextProcessingArray.Length > i + 1) nextCharCode = m_TextProcessingArray[i+1].unicode; else nextCharCode = 0; ...............
// Save State of Mesh Creation for handling of Word Wrapping ............... if ((isWhiteSpace || charCode == 0x200B || charCode == 0x2D || charCode == 0xAD) && (!m_isNonBreakingSpace || ignoreNonBreakingSpace) && charCode != 0xA0 && charCode != 0x2007 && charCode != 0x2011 && charCode != 0x202F && charCode != 0x2060) { // We store the state of numerous variables for the most recent Space, LineFeed or Carriage Return to enable them to be restored // for Word Wrapping. SaveWordWrappingState(ref m_SavedWordWrapState, i, m_characterCount); isFirstWordOfLine = false; //isLastCharacterCJK = false;
............... publicstatic Material[] FindMaterialReferences(TMP_FontAsset fontAsset) { List<Material> refs = new List<Material>(); Material mat = fontAsset.material; refs.Add(mat);
// Get materials matching the search pattern. string searchPattern = "t:Material" + " " + "TMPCommonMat"; string[] materialAssetGUIDs = AssetDatabase.FindAssets(searchPattern);
for (int i = 0; i < materialAssetGUIDs.Length; i++) { string materialPath = AssetDatabase.GUIDToAssetPath(materialAssetGUIDs[i]); Material targetMaterial = AssetDatabase.LoadAssetAtPath<Material>(materialPath); // by paperlens: 材质复用 // if (targetMaterial.HasProperty(ShaderUtilities.ID_MainTex) && targetMaterial.GetTexture(ShaderUtilities.ID_MainTex) != null && mat.GetTexture(ShaderUtilities.ID_MainTex) != null && targetMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() == mat.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID()) // { if (!refs.Contains(targetMaterial)) refs.Add(targetMaterial); // } // else // { // TODO: Find a more efficient method to unload resources. //Resources.UnloadAsset(targetMaterial.GetTexture(ShaderUtilities.ID_MainTex)); // } }
return refs.ToArray(); } ...............
在TMPro_UGUI_Private.cs的LoadFontAsset()中,删除判断逻辑:
1 2 3 4 5 6 7 8 9 10 11
............... // by paperlens: 材质复用 // If font atlas texture doesn't match the assigned material font atlas, switch back to default material specified in the Font Asset. if (m_sharedMaterial == null) // || m_sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex) == null || m_fontAsset.atlasTexture.GetInstanceID() != m_sharedMaterial.GetTexture(ShaderUtilities.ID_MainTex).GetInstanceID() { if (m_fontAsset.material == null) Debug.LogWarning("The Font Atlas Texture of the Font Asset " + m_fontAsset.name + " assigned to " + gameObject.name + " is missing.", this); else m_sharedMaterial = m_fontAsset.material; } ...............
// FONT ASSET EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_FontAssetProp, k_FontAssetLabel); if (EditorGUI.EndChangeCheck()) { m_HavePropertiesChanged = true; m_HasFontAssetChangedProp.boolValue = true;
// Get new Material Presets for the new font asset m_MaterialPresetNames = GetMaterialPresets(); m_MaterialPresetSelectionIndex = 0; // by paperlens: 修改fontAsset时标记MaterialPreset为脏,重置材质。 m_FontSharedMaterialProp.objectReferenceValue = m_MaterialPresets[m_MaterialPresetSelectionIndex]; m_HavePropertiesChanged = true;