public void OnEnable() { font_atlas_prop = base.serializedObject.FindProperty("atlas"); font_material_prop = base.serializedObject.FindProperty("material"); fontWeights_prop = base.serializedObject.FindProperty("fontWeights"); m_list = new ReorderableList(base.serializedObject, base.serializedObject.FindProperty("fallbackFontAssets"), true, true, true, true); m_list.drawElementCallback = delegate(Rect rect, int index, bool isActive, bool isFocused) { SerializedProperty arrayElementAtIndex = m_list.serializedProperty.GetArrayElementAtIndex(index); rect.y += 2f; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), arrayElementAtIndex, GUIContent.none); }; m_list.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "<b>Fallback Font Asset List</b>", TMP_UIStyleManager.Label); }; font_normalStyle_prop = base.serializedObject.FindProperty("normalStyle"); font_normalSpacing_prop = base.serializedObject.FindProperty("normalSpacingOffset"); font_boldStyle_prop = base.serializedObject.FindProperty("boldStyle"); font_boldSpacing_prop = base.serializedObject.FindProperty("boldSpacing"); font_italicStyle_prop = base.serializedObject.FindProperty("italicStyle"); font_tabSize_prop = base.serializedObject.FindProperty("tabSize"); m_fontInfo_prop = base.serializedObject.FindProperty("m_fontInfo"); m_glyphInfoList_prop = base.serializedObject.FindProperty("m_glyphInfoList"); m_kerningInfo_prop = base.serializedObject.FindProperty("m_kerningInfo"); m_kerningPair_prop = base.serializedObject.FindProperty("m_kerningPair"); m_fontAsset = (base.target as TMP_FontAsset); m_kerningTable = m_fontAsset.kerningInfo; m_materialPresets = TMP_EditorUtility.FindMaterialReferences(m_fontAsset); TMP_UIStyleManager.GetUIStyles(); m_searchList = new List <int>(); }
static int DoVerticalAligmentControl(Rect position, SerializedProperty alignment) { var selected = TMP_EditorUtility.GetVerticalAlignmentGridValue(alignment.intValue); var values = new bool[6]; values[selected] = true; if (alignment.hasMultipleDifferentValues) { foreach (var obj in alignment.serializedObject.targetObjects) { var text = obj as TMP_Text; if (text != null) { values[TMP_EditorUtility.GetVerticalAlignmentGridValue((int)text.alignment)] = true; } } } position.width = k_AlignmentButtonWidth; for (var i = 0; i < values.Length; i++) { var oldValue = values[i]; var newValue = TMP_EditorUtility.EditorToggle(position, oldValue, TMP_UIStyleManager.alignContentB[i], i == 0 ? TMP_UIStyleManager.alignmentButtonLeft : (i == 5 ? TMP_UIStyleManager.alignmentButtonRight : TMP_UIStyleManager.alignmentButtonMid)); if (newValue != oldValue) { selected = i; } position.x += position.width; } return(selected); }
/// <summary> /// Method to retrieve the material presets that match the currently selected font asset. /// </summary> private string[] GetMaterialPresets() { TMP_FontAsset fontAsset = fontAsset_prop.objectReferenceValue as TMP_FontAsset; if (fontAsset == null) { return(null); } m_materialPresets = TMP_EditorUtility.FindMaterialReferences(fontAsset); m_materialPresetNames = new string[m_materialPresets.Length]; for (int i = 0; i < m_materialPresetNames.Length; i++) { m_materialPresetNames[i] = m_materialPresets[i].name; if (m_targetMaterial.GetInstanceID() == m_materialPresets[i].GetInstanceID()) { m_materialPresetSelectionIndex = i; } } m_isPresetListDirty = false; return(m_materialPresetNames); }
private void PerformDrop(Material droppedMaterial) { Texture texture = droppedMaterial.GetTexture(ShaderUtilities.ID_MainTex); if (!texture) { return; } Texture texture2 = material.GetTexture(ShaderUtilities.ID_MainTex); TMP_FontAsset tMP_FontAsset = null; if (texture != texture2) { tMP_FontAsset = TMP_EditorUtility.FindMatchingFontAsset(droppedMaterial); if (!tMP_FontAsset) { return; } } GameObject[] gameObjects = Selection.gameObjects; foreach (GameObject gameObject in gameObjects) { if ((bool)tMP_FontAsset) { TMP_Text component = gameObject.GetComponent <TMP_Text>(); if ((bool)(UnityEngine.Object)(object) component) { Undo.RecordObject((UnityEngine.Object)(object) component, "Font Asset Change"); component.font = tMP_FontAsset; } } TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(gameObject, material, droppedMaterial); EditorUtility.SetDirty(gameObject); } }
/// <summary> /// Method to retrieve the material presets that match the currently selected font asset. /// </summary> protected GUIContent[] GetMaterialPresets() { TMP_FontAsset fontAsset = m_FontAssetProp.objectReferenceValue as TMP_FontAsset; if (fontAsset == null) { return(null); } m_MaterialPresets = TMP_EditorUtility.FindMaterialReferences(fontAsset); m_MaterialPresetNames = new GUIContent[m_MaterialPresets.Length]; for (int i = 0; i < m_MaterialPresetNames.Length; i++) { m_MaterialPresetNames[i] = new GUIContent(m_MaterialPresets[i].name); if (m_TargetMaterial.GetInstanceID() == m_MaterialPresets[i].GetInstanceID()) { m_MaterialPresetSelectionIndex = i; } } m_IsPresetListDirty = false; return(m_MaterialPresetNames); }
void PerformDrop(Material droppedMaterial) { Texture droppedTex = droppedMaterial.GetTexture(ShaderUtilities.ID_MainTex); if (!droppedTex) { return; } Texture currentTex = material.GetTexture(ShaderUtilities.ID_MainTex); TMP_FontAsset requiredFontAsset = null; if (droppedTex != currentTex) { requiredFontAsset = TMP_EditorUtility.FindMatchingFontAsset(droppedMaterial); if (!requiredFontAsset) { return; } } foreach (GameObject o in Selection.gameObjects) { if (requiredFontAsset) { TMP_Text textComponent = o.GetComponent <TMP_Text>(); if (textComponent) { Undo.RecordObject(textComponent, "Font Asset Change"); textComponent.font = requiredFontAsset; } } TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(o, material, droppedMaterial); EditorUtility.SetDirty(o); } }
public override void OnInspectorGUI() { serializedObject.Update(); // Get a reference to the current material. SerializedProperty material_prop = m_Materials.GetArrayElementAtIndex(0); Material currentMaterial = material_prop.objectReferenceValue as Material; EditorGUI.BeginChangeCheck(); base.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { material_prop = m_Materials.GetArrayElementAtIndex(0); TMP_FontAsset newFontAsset = null; Material newMaterial = null; if (material_prop != null) { newMaterial = material_prop.objectReferenceValue as Material; } // Check if the new material is referencing a different font atlas texture. if (newMaterial != null && currentMaterial.GetInstanceID() != newMaterial.GetInstanceID()) { // Search for the Font Asset matching the new font atlas texture. newFontAsset = TMP_EditorUtility.FindMatchingFontAsset(newMaterial); } GameObject[] objects = Selection.gameObjects; for (int i = 0; i < objects.Length; i++) { // Assign new font asset if (newFontAsset != null) { TMP_Text textComponent = objects[i].GetComponent <TMP_Text>(); if (textComponent != null) { Undo.RecordObject(textComponent, "Font Asset Change"); textComponent.font = newFontAsset; } } TMPro_EventManager.ON_DRAG_AND_DROP_MATERIAL_CHANGED(objects[i], currentMaterial, newMaterial); } } }
static int DoVerticalAligmentControl(Rect position, SerializedProperty alignment) { var selected = TMP_EditorUtility.GetVerticalAlignmentGridValue(alignment.intValue); var values = new bool[6]; values[selected] = true; if (alignment.hasMultipleDifferentValues) { foreach (var obj in alignment.serializedObject.targetObjects) { var text = obj as TMP_Text; if (tex
public void OnEnable() { font_atlas_prop = serializedObject.FindProperty("atlas"); font_material_prop = serializedObject.FindProperty("material"); fontWeights_prop = serializedObject.FindProperty("fontWeights"); m_list = new ReorderableList(serializedObject, serializedObject.FindProperty("fallbackFontAssets"), true, true, true, true); m_list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = m_list.serializedProperty.GetArrayElementAtIndex(index); rect.y += 2; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element, GUIContent.none); }; m_list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "<b>Fallback Font Asset List</b>", TMP_UIStyleManager.Label); }; font_normalStyle_prop = serializedObject.FindProperty("normalStyle"); font_normalSpacing_prop = serializedObject.FindProperty("normalSpacingOffset"); font_boldStyle_prop = serializedObject.FindProperty("boldStyle"); font_boldSpacing_prop = serializedObject.FindProperty("boldSpacing"); font_italicStyle_prop = serializedObject.FindProperty("italicStyle"); font_tabSize_prop = serializedObject.FindProperty("tabSize"); m_fontInfo_prop = serializedObject.FindProperty("m_fontInfo"); m_glyphInfoList_prop = serializedObject.FindProperty("m_glyphInfoList"); m_kerningInfo_prop = serializedObject.FindProperty("m_kerningInfo"); m_kerningPair_prop = serializedObject.FindProperty("m_kerningPair"); m_kerningPairs_prop = m_kerningInfo_prop.FindPropertyRelative("kerningPairs"); m_fontAsset = target as TMP_FontAsset; m_kerningTable = m_fontAsset.kerningInfo; m_materialPresets = TMP_EditorUtility.FindMaterialReferences(m_fontAsset); // Get the UI Skin and Styles for the various Editors TMP_UIStyleManager.GetUIStyles(); m_GlyphSearchList = new List <int>(); m_KerningTableSearchList = new List <int>(); }
protected bool BeginPanel(string panel, bool expanded) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); Rect r = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(20, 18)); r.x += 20; r.width += 6; bool enabled = GUI.enabled; GUI.enabled = true; expanded = TMP_EditorUtility.EditorToggle(r, expanded, new GUIContent(panel), TMP_UIStyleManager.panelTitle); GUI.enabled = enabled; EditorGUI.indentLevel += 1; EditorGUI.BeginDisabledGroup(false); return(expanded); }
protected bool BeginPanel(string panel, ShaderFeature feature, bool expanded, bool readState = true) { EditorGUI.indentLevel = 0; if (readState) { feature.ReadState(m_Material); } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.BeginHorizontal(); Rect r = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(20, 20, GUILayout.Width(20f))); bool active = EditorGUI.Toggle(r, feature.Active); if (EditorGUI.EndChangeCheck()) { m_Editor.RegisterPropertyChangeUndo(feature.undoLabel); feature.SetActive(active, m_Material); } r = EditorGUI.IndentedRect(GUILayoutUtility.GetRect(20, 18)); r.width += 6; bool enabled = GUI.enabled; GUI.enabled = true; expanded = TMP_EditorUtility.EditorToggle(r, expanded, new GUIContent(panel), TMP_UIStyleManager.panelTitle); r.width -= 10; EditorGUI.LabelField(r, new GUIContent(expanded ? s_PanelStateLabel[0] : s_PanelStateLabel[1]), TMP_UIStyleManager.rightLabel); GUI.enabled = enabled; GUILayout.EndHorizontal(); EditorGUI.indentLevel += 1; EditorGUI.BeginDisabledGroup(!active); return(expanded); }
public override void OnInspectorGUI() { Event currentEvent = Event.current; serializedObject.Update(); m_IsStyleSheetDirty = false; int elementCount = m_StyleListProp.arraySize; int itemsPerPage = (Screen.height - 100) / 110; if (elementCount > 0) { // Display each Style entry using the StyleDrawer PropertyDrawer. for (int i = itemsPerPage * m_Page; i < elementCount && i < itemsPerPage * (m_Page + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginVertical(EditorStyles.helpBox); SerializedProperty styleProperty = m_StyleListProp.GetArrayElementAtIndex(i); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(styleProperty); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { // } // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedElement == i) { m_SelectedElement = -1; } else { m_SelectedElement = i; GUIUtility.keyboardControl = 0; } } // Handle Selection Highlighting if (m_SelectedElement == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); } } } // STYLE LIST MANAGEMENT Rect rect = EditorGUILayout.GetControlRect(false, 20); rect.width /= 6; // Move Style up. bool guiEnabled = GUI.enabled; if (m_SelectedElement == -1 || m_SelectedElement == 0) { GUI.enabled = false; } if (GUI.Button(rect, "Up")) { SwapStyleElements(m_SelectedElement, m_SelectedElement - 1); } GUI.enabled = guiEnabled; // Move Style down. rect.x += rect.width; if (m_SelectedElement == elementCount - 1) { GUI.enabled = false; } if (GUI.Button(rect, "Down")) { SwapStyleElements(m_SelectedElement, m_SelectedElement + 1); } GUI.enabled = guiEnabled; // Add Style rect.x += rect.width * 3; if (GUI.Button(rect, "+")) { int index = m_SelectedElement == -1 ? 0 : m_SelectedElement; if (index > elementCount) { index = elementCount; } // Copy selected element m_StyleListProp.InsertArrayElementAtIndex(index); // Select newly inserted element m_SelectedElement = index + 1; serializedObject.ApplyModifiedProperties(); m_StyleSheet.RefreshStyles(); } // Delete style rect.x += rect.width; if (m_SelectedElement == -1 || m_SelectedElement >= elementCount) { GUI.enabled = false; } if (GUI.Button(rect, "-")) { int index = m_SelectedElement == -1 ? 0 : m_SelectedElement; m_StyleListProp.DeleteArrayElementAtIndex(index); m_SelectedElement = -1; serializedObject.ApplyModifiedProperties(); m_StyleSheet.RefreshStyles(); return; } // Return if we can't display any items. if (itemsPerPage == 0) { return; } // DISPLAY PAGE CONTROLS int shiftMultiplier = currentEvent.shift ? 10 : 1; // Page + Shift goes 10 page forward Rect pagePos = EditorGUILayout.GetControlRect(false, 20); pagePos.width /= 3; // Previous Page if (m_Page > 0) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Previous")) { m_Page -= 1 * shiftMultiplier; } // PAGE COUNTER GUI.enabled = true; pagePos.x += pagePos.width; int totalPages = (int)(elementCount / (float)itemsPerPage + 0.999f); GUI.Label(pagePos, "Page " + (m_Page + 1) + " / " + totalPages, TMP_UIStyleManager.centeredLabel); // Next Page pagePos.x += pagePos.width; if (itemsPerPage * (m_Page + 1) < elementCount) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Next")) { m_Page += 1 * shiftMultiplier; } // Clamp page range m_Page = Mathf.Clamp(m_Page, 0, elementCount / itemsPerPage); if (serializedObject.ApplyModifiedProperties()) { TMPro_EventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true); if (m_IsStyleSheetDirty) { m_IsStyleSheetDirty = false; m_StyleSheet.RefreshStyles(); } } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_SelectedElement = -1; } }
public override void OnInspectorGUI() { // Check Warnings //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; serializedObject.Update(); GUILayout.Label("<b>TextMesh Pro! Font Asset</b>", TMP_UIStyleManager.Section_Label); // TextMeshPro Font Info Panel GUILayout.Label("Face Info", TMP_UIStyleManager.Section_Label); EditorGUI.indentLevel = 1; GUI.enabled = false; // Lock UI float labelWidth = EditorGUIUtility.labelWidth = 150f; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Name"), new GUIContent("Font Source")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("PointSize")); GUI.enabled = true; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Scale")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("LineHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Ascender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("CapHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Baseline")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Descender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Underline")); //EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("UnderlineThickness")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SuperscriptOffset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SubscriptOffset")); SerializedProperty subSize_prop = m_fontInfo_prop.FindPropertyRelative("SubSize"); EditorGUILayout.PropertyField(subSize_prop, new GUIContent("Super / Subscript Size")); subSize_prop.floatValue = Mathf.Clamp(subSize_prop.floatValue, 0.25f, 1f); GUI.enabled = false; //EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); //GUILayout.Label("Atlas Size"); EditorGUI.indentLevel = 1; GUILayout.Space(18); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasWidth"), new GUIContent("Width")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasHeight"), new GUIContent("Height")); GUI.enabled = true; EditorGUI.indentLevel = 0; GUILayout.Space(20); GUILayout.Label("Font Sub-Assets", TMP_UIStyleManager.Section_Label); GUI.enabled = false; EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(font_atlas_prop, new GUIContent("Font Atlas:")); EditorGUILayout.PropertyField(font_material_prop, new GUIContent("Font Material:")); GUI.enabled = true; string evt_cmd = Event.current.commandName; // Get Current Event CommandName to check for Undo Events // FONT SETTINGS EditorGUI.indentLevel = 0; if (GUILayout.Button("Font Weights\t" + (UI_PanelState.fontWeightPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fontWeightPanel = !UI_PanelState.fontWeightPanel; } if (UI_PanelState.fontWeightPanel) { EditorGUIUtility.labelWidth = 120; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Font Assets that will be used for the following font weights.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); GUILayout.Label("<b>Font Weight</b>", TMP_UIStyleManager.Label, GUILayout.Width(117)); GUILayout.Label("<b>Normal Style</b>", TMP_UIStyleManager.Label); GUILayout.Label("<b>Italic Style</b>", TMP_UIStyleManager.Label); EditorGUILayout.EndHorizontal(); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(1), new GUIContent("100 - Thin")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(2), new GUIContent("200 - Extra-Light")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(3), new GUIContent("300 - Light")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(4), new GUIContent("400 - Regular")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(5), new GUIContent("500 - Medium")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(6), new GUIContent("600 - Demi-Bold")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(7), new GUIContent("700 - Bold")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(8), new GUIContent("800 - Heavy")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(9), new GUIContent("900 - Black")); EditorGUILayout.EndVertical(); //EditorGUI.indentLevel = 1; EditorGUIUtility.labelWidth = 120f; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); GUILayout.Label("Settings used to simulate a typeface when no font asset is available.", TMP_UIStyleManager.Label); GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalStyle_prop, new GUIContent("Normal Weight")); font_normalStyle_prop.floatValue = Mathf.Clamp(font_normalStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightNormal", font_normalStyle_prop.floatValue); } } EditorGUILayout.PropertyField(font_boldStyle_prop, new GUIContent("Bold Weight"), GUILayout.MinWidth(100)); font_boldStyle_prop.floatValue = Mathf.Clamp(font_boldStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightBold", font_boldStyle_prop.floatValue); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalSpacing_prop, new GUIContent("Spacing Offset")); font_normalSpacing_prop.floatValue = Mathf.Clamp(font_normalSpacing_prop.floatValue, -100, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.PropertyField(font_boldSpacing_prop, new GUIContent("Bold Spacing")); font_boldSpacing_prop.floatValue = Mathf.Clamp(font_boldSpacing_prop.floatValue, 0, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Style: ")); font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60); EditorGUILayout.PropertyField(font_tabSize_prop, new GUIContent("Tab Multiple: ")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } GUILayout.Space(5); // FALLBACK FONT ASSETS EditorGUI.indentLevel = 0; if (GUILayout.Button("Fallback Font Assets\t" + (UI_PanelState.fallbackFontAssetPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fallbackFontAssetPanel = !UI_PanelState.fallbackFontAssetPanel; } if (UI_PanelState.fallbackFontAssetPanel) { EditorGUIUtility.labelWidth = 120; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Font Assets that will be searched and used as fallback when characters are missing from this font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); m_list.DoLayoutList(); EditorGUILayout.EndVertical(); } // GLYPH INFO TABLE EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; GUILayout.Space(5); EditorGUI.indentLevel = 0; if (GUILayout.Button("Glyph Info\t" + (UI_PanelState.glyphInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.glyphInfoPanel = !UI_PanelState.glyphInfoPanel; } if (UI_PanelState.glyphInfoPanel) { int arraySize = m_glyphInfoList_prop.arraySize; int itemsPerPage = 15; // Display Glyph Management Tools EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.ExpandWidth(true)); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Glyph Search", m_searchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { //GUIUtility.keyboardControl = 0; m_searchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim(); // Search Glyph Table for potential matches SearchGlyphTable(m_searchPattern, ref m_searchList); } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_searchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_searchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_searchPattern)) { arraySize = m_searchList.Count; } DisplayGlyphPageNavigation(arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); // Display Glyph Table Elements #region Glyph Table if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_GlyphPage; i < arraySize && i < itemsPerPage * (m_GlyphPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_searchPattern)) { elementIndex = m_searchList[i]; } SerializedProperty glyphInfo = m_glyphInfoList_prop.GetArrayElementAtIndex(elementIndex); EditorGUI.BeginDisabledGroup(i != m_selectedElement); { EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label); EditorGUILayout.PropertyField(glyphInfo); EditorGUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { m_selectedElement = i; m_AddGlyphWarning.isEnabled = false; m_unicodeHexLabel = k_placeholderUnicodeHex; GUIUtility.keyboardControl = 0; } // Draw Selection Highlight and Glyph Options if (m_selectedElement == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw Glyph management options Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float optionAreaWidth = controlRect.width * 0.6f; float btnWidth = optionAreaWidth / 3; Rect position = new Rect(controlRect.x + controlRect.width * .4f, controlRect.y, btnWidth, controlRect.height); // Copy Selected Glyph to Target Glyph ID GUI.enabled = !string.IsNullOrEmpty(m_dstGlyphID); if (GUI.Button(position, new GUIContent("Copy to"))) { GUIUtility.keyboardControl = 0; // Convert Hex Value to Decimal int dstGlyphID = TMP_TextUtilities.StringToInt(m_dstGlyphID); //Add new glyph at target Unicode hex id. if (!AddNewGlyph(elementIndex, dstGlyphID)) { m_AddGlyphWarning.isEnabled = true; m_AddGlyphWarning.expirationTime = EditorApplication.timeSinceStartup + 1; } m_dstGlyphID = string.Empty; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); } // Target Glyph ID GUI.enabled = true; position.x += btnWidth; GUI.SetNextControlName("GlyphID_Input"); m_dstGlyphID = EditorGUI.TextField(position, m_dstGlyphID); // Placeholder text EditorGUI.LabelField(position, new GUIContent(m_unicodeHexLabel, "The Unicode (Hex) ID of the duplicated Glyph"), TMP_UIStyleManager.Label); // Only filter the input when the destination glyph ID text field has focus. if (GUI.GetNameOfFocusedControl() == "GlyphID_Input") { m_unicodeHexLabel = string.Empty; //Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F')) { Event.current.character = '\0'; } } else { m_unicodeHexLabel = k_placeholderUnicodeHex; } // Remove Glyph position.x += btnWidth; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; RemoveGlyphFromList(elementIndex); m_selectedElement = -1; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); return; } if (m_AddGlyphWarning.isEnabled && EditorApplication.timeSinceStartup < m_AddGlyphWarning.expirationTime) { EditorGUILayout.HelpBox("The Destination Glyph ID already exists", MessageType.Warning); } } } } DisplayGlyphPageNavigation(arraySize, itemsPerPage); } #endregion // KERNING TABLE PANEL #region Kerning Table GUILayout.Space(5); if (GUILayout.Button("Kerning Table Info\t" + (UI_PanelState.kerningInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.kerningInfoPanel = !UI_PanelState.kerningInfoPanel; } if (UI_PanelState.kerningInfoPanel) { Rect pos; SerializedProperty kerningPairs_prop = m_kerningInfo_prop.FindPropertyRelative("kerningPairs"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Left Char", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label("Right Char", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label("Offset Value", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label(GUIContent.none, GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); GUILayout.BeginVertical(TMP_UIStyleManager.TMP_GUISkin.label); int arraySize = kerningPairs_prop.arraySize; int itemsPerPage = 25; if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_KerningPage; i < arraySize && i < itemsPerPage * (m_KerningPage + 1); i++) { SerializedProperty kerningPair_prop = kerningPairs_prop.GetArrayElementAtIndex(i); pos = EditorGUILayout.BeginHorizontal(); EditorGUI.PropertyField(new Rect(pos.x, pos.y, pos.width - 20f, pos.height), kerningPair_prop, GUIContent.none); // Button to Delete Kerning Pair if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { m_kerningTable.RemoveKerningPair(i); m_fontAsset.ReadFontDefinition(); // Reload Font Definition. serializedObject.Update(); // Get an updated version of the SerializedObject. isAssetDirty = true; break; } EditorGUILayout.EndHorizontal(); } } Rect pagePos = EditorGUILayout.GetControlRect(false, 20); pagePos.width /= 3; int shiftMultiplier = currentEvent.shift ? 10 : 1; // Previous Page if (m_KerningPage > 0) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Previous Page")) { m_KerningPage -= 1 * shiftMultiplier; } // Page Counter GUI.enabled = true; pagePos.x += pagePos.width; int totalPages = (int)(arraySize / (float)itemsPerPage + 0.999f); GUI.Label(pagePos, "Page " + (m_KerningPage + 1) + " / " + totalPages, GUI.skin.button); // Next Page pagePos.x += pagePos.width; if (itemsPerPage * (m_GlyphPage + 1) < arraySize) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Next Page")) { m_KerningPage += 1 * shiftMultiplier; } m_KerningPage = Mathf.Clamp(m_KerningPage, 0, arraySize / itemsPerPage); GUILayout.EndVertical(); GUILayout.Space(10); // Add New Kerning Pair Section GUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); pos = EditorGUILayout.BeginHorizontal(); // Draw Empty Kerning Pair EditorGUI.PropertyField(new Rect(pos.x, pos.y, pos.width - 20f, pos.height), m_kerningPair_prop); GUILayout.Label(GUIContent.none, GUILayout.Height(19)); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); if (GUILayout.Button("Add New Kerning Pair")) { int asci_left = m_kerningPair_prop.FindPropertyRelative("AscII_Left").intValue; int asci_right = m_kerningPair_prop.FindPropertyRelative("AscII_Right").intValue; float xOffset = m_kerningPair_prop.FindPropertyRelative("XadvanceOffset").floatValue; errorCode = m_kerningTable.AddKerningPair(asci_left, asci_right, xOffset); // Sort Kerning Pairs & Reload Font Asset if new kerning pair was added. if (errorCode != -1) { m_kerningTable.SortKerningPairs(); m_fontAsset.ReadFontDefinition(); // Reload Font Definition. serializedObject.Update(); // Get an updated version of the SerializedObject. isAssetDirty = true; } else { timeStamp = System.DateTime.Now.AddSeconds(5); } } if (errorCode == -1) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Kerning Pair already <color=#ffff00>exists!</color>", TMP_UIStyleManager.Label); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (System.DateTime.Now > timeStamp) { errorCode = 0; } } GUILayout.EndVertical(); } #endregion if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { //Debug.Log("Serialized properties have changed."); TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); isAssetDirty = false; EditorUtility.SetDirty(target); //TMPro_EditorUtility.RepaintAll(); // Consider SetDirty } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_selectedElement = -1; } }
private void Save_SDF_FontAsset(string filePath) { filePath = filePath.Substring(0, filePath.Length - 6); string dataPath = Application.dataPath; if (filePath.IndexOf(dataPath, StringComparison.InvariantCultureIgnoreCase) == -1) { Debug.LogError("You're saving the font asset in a directory outside of this project folder. This is not supported. Please select a directory under \"" + dataPath + "\""); return; } string path = filePath.Substring(dataPath.Length - 6); string directoryName = Path.GetDirectoryName(path); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); string str = directoryName + "/" + fileNameWithoutExtension; TMP_FontAsset tMP_FontAsset = AssetDatabase.LoadAssetAtPath(str + ".asset", typeof(TMP_FontAsset)) as TMP_FontAsset; if (tMP_FontAsset == null) { tMP_FontAsset = ScriptableObject.CreateInstance <WeaverCore.Assets.TMPro.TMP_FontAsset>(); AssetDatabase.CreateAsset(tMP_FontAsset, str + ".asset"); tMP_FontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF; int scaleFactor = (font_renderMode >= RenderModes.DistanceField16) ? 1 : font_scaledownFactor; FaceInfo faceInfo = GetFaceInfo(m_font_faceInfo, scaleFactor); tMP_FontAsset.AddFaceInfo(faceInfo); TMP_Glyph[] glyphInfo = GetGlyphInfo(m_font_glyphInfo, scaleFactor); tMP_FontAsset.AddGlyphInfo(glyphInfo); if (includeKerningPairs) { string assetPath = AssetDatabase.GetAssetPath(font_TTF); KerningTable kerningTable = GetKerningTable(assetPath, (int)faceInfo.PointSize); tMP_FontAsset.AddKerningInfo(kerningTable); } tMP_FontAsset.atlas = m_font_Atlas; m_font_Atlas.name = fileNameWithoutExtension + " Atlas"; AssetDatabase.AddObjectToAsset(m_font_Atlas, tMP_FontAsset); Shader shader = Shader.Find("TextMeshPro/Distance Field"); Material material = new Material(shader); material.name = fileNameWithoutExtension + " Material"; material.SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas); material.SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width); material.SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height); int num = font_padding + 1; material.SetFloat(ShaderUtilities.ID_GradientScale, num); material.SetFloat(ShaderUtilities.ID_WeightNormal, tMP_FontAsset.normalStyle); material.SetFloat(ShaderUtilities.ID_WeightBold, tMP_FontAsset.boldStyle); tMP_FontAsset.material = material; AssetDatabase.AddObjectToAsset(material, tMP_FontAsset); } else { Material[] array = TMP_EditorUtility.FindMaterialReferences(tMP_FontAsset); UnityEngine.Object.DestroyImmediate(tMP_FontAsset.atlas, true); tMP_FontAsset.fontAssetType = TMP_FontAsset.FontAssetTypes.SDF; int scaleFactor2 = (font_renderMode >= RenderModes.DistanceField16) ? 1 : font_scaledownFactor; FaceInfo faceInfo2 = GetFaceInfo(m_font_faceInfo, scaleFactor2); tMP_FontAsset.AddFaceInfo(faceInfo2); TMP_Glyph[] glyphInfo2 = GetGlyphInfo(m_font_glyphInfo, scaleFactor2); tMP_FontAsset.AddGlyphInfo(glyphInfo2); if (includeKerningPairs) { string assetPath2 = AssetDatabase.GetAssetPath(font_TTF); KerningTable kerningTable2 = GetKerningTable(assetPath2, (int)faceInfo2.PointSize); tMP_FontAsset.AddKerningInfo(kerningTable2); } tMP_FontAsset.atlas = m_font_Atlas; m_font_Atlas.name = fileNameWithoutExtension + " Atlas"; m_font_Atlas.hideFlags = HideFlags.None; tMP_FontAsset.material.hideFlags = HideFlags.None; AssetDatabase.AddObjectToAsset(m_font_Atlas, tMP_FontAsset); tMP_FontAsset.material.SetTexture(ShaderUtilities.ID_MainTex, tMP_FontAsset.atlas); for (int i = 0; i < array.Length; i++) { array[i].SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas); array[i].SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width); array[i].SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height); int num2 = font_padding + 1; array[i].SetFloat(ShaderUtilities.ID_GradientScale, num2); array[i].SetFloat(ShaderUtilities.ID_WeightNormal, tMP_FontAsset.normalStyle); array[i].SetFloat(ShaderUtilities.ID_WeightBold, tMP_FontAsset.boldStyle); } } AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tMP_FontAsset)); tMP_FontAsset.ReadFontDefinition(); AssetDatabase.Refresh(); m_font_Atlas = null; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, tMP_FontAsset); }
// Icons //public static GUIContent strikethroughIcon; public static void GetUIStyles() { if (TMP_GUISkin != null) { return; } // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMP_EditorUtility.GetAssetLocation(); if (EditorGUIUtility.isProSkin) { TMP_GUISkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin; alignLeft = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignLeft.psd", typeof(Texture2D)) as Texture2D; alignCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignCenter.psd", typeof(Texture2D)) as Texture2D; alignRight = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignRight.psd", typeof(Texture2D)) as Texture2D; alignJustified = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignJustified.psd", typeof(Texture2D)) as Texture2D; alignFlush = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignFlush.psd", typeof(Texture2D)) as Texture2D; alignGeoCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignCenterGeo.psd", typeof(Texture2D)) as Texture2D; alignTop = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignTop.psd", typeof(Texture2D)) as Texture2D; alignMiddle = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignMiddle.psd", typeof(Texture2D)) as Texture2D; alignBottom = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignBottom.psd", typeof(Texture2D)) as Texture2D; alignBaseline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignBaseLine.psd", typeof(Texture2D)) as Texture2D; alignMidline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignMidLine.psd", typeof(Texture2D)) as Texture2D; alignCapline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignCapLine.psd", typeof(Texture2D)) as Texture2D; progressTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/Progress Bar.psd", typeof(Texture2D)) as Texture2D; //selectionBox = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/SelectionBox.psd", typeof(Texture2D)) as Texture2D; //strikethroughIcon = new GUIContent(AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/icon_strikethrough.psd", typeof(Texture2D)) as Texture2D); selectionBox = EditorGUIUtility.Load("IN thumbnailshadow On@2x") as Texture2D; } else { TMP_GUISkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin; alignLeft = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignLeft_Light.psd", typeof(Texture2D)) as Texture2D; alignCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignCenter_Light.psd", typeof(Texture2D)) as Texture2D; alignRight = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignRight_Light.psd", typeof(Texture2D)) as Texture2D; alignJustified = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignJustified_Light.psd", typeof(Texture2D)) as Texture2D; alignFlush = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignFlush_Light.psd", typeof(Texture2D)) as Texture2D; alignGeoCenter = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignCenterGeo_Light.psd", typeof(Texture2D)) as Texture2D; alignTop = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignTop_Light.psd", typeof(Texture2D)) as Texture2D; alignMiddle = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignMiddle_Light.psd", typeof(Texture2D)) as Texture2D; alignBottom = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignBottom_Light.psd", typeof(Texture2D)) as Texture2D; alignBaseline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignBaseLine_Light.psd", typeof(Texture2D)) as Texture2D; alignMidline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignMidLine_Light.psd", typeof(Texture2D)) as Texture2D; alignCapline = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/btn_AlignCapLine_Light.psd", typeof(Texture2D)) as Texture2D; progressTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/Progress Bar (Light).psd", typeof(Texture2D)) as Texture2D; selectionBox = EditorGUIUtility.Load("IN thumbnailshadow On@2x") as Texture2D; } if (TMP_GUISkin != null) { Label = TMP_GUISkin.FindStyle("Label"); //ScrollView = TMP_GUISkin.FindStyle("ScrollView"); //VerticalScrollBar = TMP_GUISkin.FindStyle("VerticalScrollbar"); //HorizontalScrollBar = TMP_GUISkin.FindStyle("HorizontalScrollbar"); Section_Label = TMP_GUISkin.FindStyle("Section Label"); Group_Label = TMP_GUISkin.FindStyle("Group Label"); Group_Label_Left = TMP_GUISkin.FindStyle("Group Label - Left Half"); TextAreaBoxEditor = TMP_GUISkin.FindStyle("Text Area Box (Editor)"); TextAreaBoxWindow = TMP_GUISkin.FindStyle("Text Area Box (Window)"); TextureAreaBox = TMP_GUISkin.FindStyle("Texture Area Box"); SquareAreaBox85G = TMP_GUISkin.FindStyle("Square Area Box (85 Grey)"); alignContent_A = new GUIContent[] { new GUIContent(alignLeft, "Left"), new GUIContent(alignCenter, "Center"), new GUIContent(alignRight, "Right"), new GUIContent(alignJustified, "Justified"), new GUIContent(alignFlush, "Flush"), new GUIContent(alignGeoCenter, "Geometry Center") }; alignContent_B = new GUIContent[] { new GUIContent(alignTop, "Top"), new GUIContent(alignMiddle, "Middle"), new GUIContent(alignBottom, "Bottom"), new GUIContent(alignBaseline, "Baseline"), new GUIContent(alignMidline, "Midline"), new GUIContent(alignCapline, "Capline") }; } //m_isInitialized = true; }
public override void OnInspectorGUI() { if (toggleStyle == null) { toggleStyle = new GUIStyle(GUI.skin.label); toggleStyle.fontSize = 12; toggleStyle.normal.textColor = TMP_UIStyleManager.Section_Label.normal.textColor; toggleStyle.richText = true; } base.serializedObject.Update(); Rect controlRect = EditorGUILayout.GetControlRect(false, 25f); float labelWidth = EditorGUIUtility.labelWidth = 130f; float fieldWidth = EditorGUIUtility.fieldWidth; controlRect.y += 2f; GUI.Label(controlRect, "<b>TEXT INPUT BOX</b>" + (m_foldout.textInput ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label); if (GUI.Button(new Rect(controlRect.x, controlRect.y, controlRect.width - 150f, controlRect.height), GUIContent.none, GUI.skin.label)) { m_foldout.textInput = !m_foldout.textInput; } GUI.Label(new Rect(controlRect.width - 125f, controlRect.y + 4f, 125f, 24f), "<i>Enable RTL Editor</i>", toggleStyle); isRightToLeft_prop.boolValue = EditorGUI.Toggle(new Rect(controlRect.width - 10f, controlRect.y + 3f, 20f, 24f), GUIContent.none, isRightToLeft_prop.boolValue); if (m_foldout.textInput) { if (isLinkedTextComponent_prop.boolValue) { EditorGUILayout.HelpBox("The Text Input Box is disabled due to this text component being linked to another.", MessageType.Info); } else { EditorGUI.BeginChangeCheck(); text_prop.stringValue = EditorGUILayout.TextArea(text_prop.stringValue, TMP_UIStyleManager.TextAreaBoxEditor, GUILayout.Height(125f), GUILayout.ExpandWidth(true)); if (EditorGUI.EndChangeCheck() || (isRightToLeft_prop.boolValue && (m_RTLText == null || m_RTLText == string.Empty))) { inputSource_prop.enumValueIndex = 0; isInputPasingRequired_prop.boolValue = true; havePropertiesChanged = true; if (isRightToLeft_prop.boolValue) { m_RTLText = string.Empty; string stringValue = text_prop.stringValue; for (int i = 0; i < stringValue.Length; i++) { m_RTLText += stringValue[stringValue.Length - i - 1]; } } } if (isRightToLeft_prop.boolValue) { EditorGUI.BeginChangeCheck(); m_RTLText = EditorGUILayout.TextArea(m_RTLText, TMP_UIStyleManager.TextAreaBoxEditor, GUILayout.Height(125f), GUILayout.ExpandWidth(true)); if (EditorGUI.EndChangeCheck()) { string text = string.Empty; for (int j = 0; j < m_RTLText.Length; j++) { text += m_RTLText[m_RTLText.Length - j - 1]; } text_prop.stringValue = text; } } } } if (GUILayout.Button("<b>FONT SETTINGS</b>" + (m_foldout.fontSettings ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { m_foldout.fontSettings = !m_foldout.fontSettings; } if (m_isPresetListDirty) { m_materialPresetNames = GetMaterialPresets(); } if (m_foldout.fontSettings) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(fontAsset_prop); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; hasFontAssetChanged_prop.boolValue = true; m_isPresetListDirty = true; m_materialPresetSelectionIndex = 0; } if (m_materialPresetNames != null) { EditorGUI.BeginChangeCheck(); controlRect = EditorGUILayout.GetControlRect(false, 18f); float fixedHeight = EditorStyles.popup.fixedHeight; EditorStyles.popup.fixedHeight = controlRect.height; int fontSize = EditorStyles.popup.fontSize; EditorStyles.popup.fontSize = 11; m_materialPresetSelectionIndex = EditorGUI.Popup(controlRect, "Material Preset", m_materialPresetSelectionIndex, m_materialPresetNames); if (EditorGUI.EndChangeCheck()) { fontSharedMaterial_prop.objectReferenceValue = m_materialPresets[m_materialPresetSelectionIndex]; havePropertiesChanged = true; } if (m_materialPresetSelectionIndex < m_materialPresetNames.Length && m_targetMaterial != m_materialPresets[m_materialPresetSelectionIndex] && !havePropertiesChanged) { m_isPresetListDirty = true; } EditorStyles.popup.fixedHeight = fixedHeight; EditorStyles.popup.fontSize = fontSize; } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Font Style"); int intValue = fontStyle_prop.intValue; int num2 = GUILayout.Toggle((intValue & 1) == 1, "B", GUI.skin.button) ? 1 : 0; int num3 = GUILayout.Toggle((intValue & 2) == 2, "I", GUI.skin.button) ? 2 : 0; int num4 = GUILayout.Toggle((intValue & 4) == 4, "U", GUI.skin.button) ? 4 : 0; int num5 = GUILayout.Toggle((intValue & 0x40) == 64, "S", GUI.skin.button) ? 64 : 0; int num6 = GUILayout.Toggle((intValue & 8) == 8, "ab", GUI.skin.button) ? 8 : 0; int num7 = GUILayout.Toggle((intValue & 0x10) == 16, "AB", GUI.skin.button) ? 16 : 0; int num8 = GUILayout.Toggle((intValue & 0x20) == 32, "SC", GUI.skin.button) ? 32 : 0; EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { fontStyle_prop.intValue = num2 + num3 + num4 + num6 + num7 + num8 + num5; havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(fontColor_prop, new GUIContent("Color (Vertex)")); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(enableVertexGradient_prop, new GUIContent("Color Gradient"), GUILayout.MinWidth(140f), GUILayout.MaxWidth(200f)); EditorGUIUtility.labelWidth = 95f; EditorGUILayout.PropertyField(overrideHtmlColor_prop, new GUIContent("Override Tags")); EditorGUIUtility.labelWidth = labelWidth; EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } if (enableVertexGradient_prop.boolValue) { EditorGUILayout.PropertyField(fontColorGradientPreset_prop, new GUIContent("Gradient (Preset)")); if (fontColorGradientPreset_prop.objectReferenceValue == null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(fontColorGradient_prop.FindPropertyRelative("topLeft"), new GUIContent("Top Left")); EditorGUILayout.PropertyField(fontColorGradient_prop.FindPropertyRelative("topRight"), new GUIContent("Top Right")); EditorGUILayout.PropertyField(fontColorGradient_prop.FindPropertyRelative("bottomLeft"), new GUIContent("Bottom Left")); EditorGUILayout.PropertyField(fontColorGradient_prop.FindPropertyRelative("bottomRight"), new GUIContent("Bottom Right")); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } } else { SerializedObject serializedObject = new SerializedObject(fontColorGradientPreset_prop.objectReferenceValue); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(serializedObject.FindProperty("topLeft"), new GUIContent("Top Left")); EditorGUILayout.PropertyField(serializedObject.FindProperty("topRight"), new GUIContent("Top Right")); EditorGUILayout.PropertyField(serializedObject.FindProperty("bottomLeft"), new GUIContent("Bottom Left")); EditorGUILayout.PropertyField(serializedObject.FindProperty("bottomRight"), new GUIContent("Bottom Right")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); havePropertiesChanged = true; TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(fontColorGradientPreset_prop.objectReferenceValue as TMP_ColorGradient); } } } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(fontSize_prop, new GUIContent("Font Size"), GUILayout.MinWidth(168f), GUILayout.MaxWidth(200f)); EditorGUIUtility.fieldWidth = fieldWidth; if (EditorGUI.EndChangeCheck()) { fontSizeBase_prop.floatValue = fontSize_prop.floatValue; havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = 70f; EditorGUILayout.PropertyField(autoSizing_prop, new GUIContent("Auto Size")); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = labelWidth; if (EditorGUI.EndChangeCheck()) { if (!autoSizing_prop.boolValue) { fontSize_prop.floatValue = fontSizeBase_prop.floatValue; } havePropertiesChanged = true; } if (autoSizing_prop.boolValue) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Auto Size Options"); EditorGUIUtility.labelWidth = 24f; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(fontSizeMin_prop, new GUIContent("Min"), GUILayout.MinWidth(46f)); if (EditorGUI.EndChangeCheck()) { fontSizeMin_prop.floatValue = Mathf.Min(fontSizeMin_prop.floatValue, fontSizeMax_prop.floatValue); havePropertiesChanged = true; } EditorGUIUtility.labelWidth = 27f; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(fontSizeMax_prop, new GUIContent("Max"), GUILayout.MinWidth(49f)); if (EditorGUI.EndChangeCheck()) { fontSizeMax_prop.floatValue = Mathf.Max(fontSizeMin_prop.floatValue, fontSizeMax_prop.floatValue); havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = 36f; EditorGUILayout.PropertyField(charWidthMaxAdj_prop, new GUIContent("WD%"), GUILayout.MinWidth(58f)); EditorGUIUtility.labelWidth = 28f; EditorGUILayout.PropertyField(lineSpacingMax_prop, new GUIContent("Line"), GUILayout.MinWidth(50f)); EditorGUIUtility.labelWidth = labelWidth; EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { charWidthMaxAdj_prop.floatValue = Mathf.Clamp(charWidthMaxAdj_prop.floatValue, 0f, 50f); lineSpacingMax_prop.floatValue = Mathf.Min(0f, lineSpacingMax_prop.floatValue); havePropertiesChanged = true; } } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Spacing Options"); EditorGUIUtility.labelWidth = 35f; EditorGUILayout.PropertyField(characterSpacing_prop, new GUIContent("Char"), GUILayout.MinWidth(50f)); EditorGUILayout.PropertyField(wordSpacing_prop, new GUIContent("Word"), GUILayout.MinWidth(50f)); EditorGUILayout.PropertyField(lineSpacing_prop, new GUIContent("Line"), GUILayout.MinWidth(50f)); EditorGUILayout.PropertyField(paragraphSpacing_prop, new GUIContent(" Par."), GUILayout.MinWidth(50f)); EditorGUIUtility.labelWidth = labelWidth; EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); controlRect = EditorGUILayout.GetControlRect(false, 19f); GUIStyle gUIStyle = new GUIStyle(GUI.skin.button); gUIStyle.margin = new RectOffset(1, 1, 1, 1); gUIStyle.padding = new RectOffset(1, 1, 1, 0); selAlignGrid_A = TMP_EditorUtility.GetHorizontalAlignmentGridValue(textAlignment_prop.intValue); selAlignGrid_B = TMP_EditorUtility.GetVerticalAlignmentGridValue(textAlignment_prop.intValue); GUI.Label(new Rect(controlRect.x, controlRect.y + 2f, 100f, controlRect.height), "Alignment"); float num9 = EditorGUIUtility.labelWidth + 15f; selAlignGrid_A = GUI.SelectionGrid(new Rect(num9, controlRect.y, 138f, controlRect.height), selAlignGrid_A, TMP_UIStyleManager.alignContent_A, 6, gUIStyle); selAlignGrid_B = GUI.SelectionGrid(new Rect(num9 + 138f + 20f, controlRect.y, 138f, controlRect.height), selAlignGrid_B, TMP_UIStyleManager.alignContent_B, 6, gUIStyle); if (EditorGUI.EndChangeCheck()) { //int intValue2 = (1 << selAlignGrid_A) | (256 << selAlignGrid_B); int intValue2 = selAlignGrid_A + (selAlignGrid_B * 4); textAlignment_prop.intValue = intValue2; havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); //if ((textAlignment_prop.intValue & 8) == 8 || (textAlignment_prop.intValue & 0x10) == 16) if (selAlignGrid_A == 3) { DrawPropertySlider("Wrap Mix (W <-> C)", wordWrappingRatios_prop); } if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); controlRect = EditorGUILayout.GetControlRect(false); EditorGUI.PrefixLabel(new Rect(controlRect.x, controlRect.y, 130f, controlRect.height), new GUIContent("Wrapping & Overflow")); controlRect.width = (controlRect.width - 130f) / 2f; controlRect.x += 130f; int num10 = EditorGUI.Popup(controlRect, enableWordWrapping_prop.boolValue ? 1 : 0, new string[2] { "Disabled", "Enabled" }); if (EditorGUI.EndChangeCheck()) { enableWordWrapping_prop.boolValue = ((num10 == 1) ? true : false); havePropertiesChanged = true; isInputPasingRequired_prop.boolValue = true; } EditorGUI.BeginChangeCheck(); TMP_Text exists = linkedTextComponent_prop.objectReferenceValue as TMP_Text; if (textOverflowMode_prop.enumValueIndex == 6) { controlRect.x += controlRect.width + 5f; controlRect.width /= 3f; EditorGUI.PropertyField(controlRect, textOverflowMode_prop, GUIContent.none); controlRect.x += controlRect.width; controlRect.width = controlRect.width * 2f - 5f; EditorGUI.PropertyField(controlRect, linkedTextComponent_prop, GUIContent.none); if (GUI.changed) { TMP_Text tMP_Text = linkedTextComponent_prop.objectReferenceValue as TMP_Text; if ((bool)(UnityEngine.Object)(object) tMP_Text) { m_textComponent.linkedTextComponent = tMP_Text; } } } else if (textOverflowMode_prop.enumValueIndex == 5) { controlRect.x += controlRect.width + 5f; controlRect.width /= 2f; EditorGUI.PropertyField(controlRect, textOverflowMode_prop, GUIContent.none); controlRect.x += controlRect.width; controlRect.width -= 5f; EditorGUI.PropertyField(controlRect, pageToDisplay_prop, GUIContent.none); if ((bool)(UnityEngine.Object)(object) exists) { m_textComponent.linkedTextComponent = null; } } else { controlRect.x += controlRect.width + 5f; controlRect.width -= 5f; EditorGUI.PropertyField(controlRect, textOverflowMode_prop, GUIContent.none); if ((bool)(UnityEngine.Object)(object) exists) { m_textComponent.linkedTextComponent = null; } } if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; isInputPasingRequired_prop.boolValue = true; } EditorGUI.BeginChangeCheck(); controlRect = EditorGUILayout.GetControlRect(false); EditorGUI.PrefixLabel(new Rect(controlRect.x, controlRect.y, 130f, controlRect.height), new GUIContent("UV Mapping Options")); controlRect.width = (controlRect.width - 130f) / 2f; controlRect.x += 130f; EditorGUI.PropertyField(controlRect, horizontalMapping_prop, GUIContent.none); controlRect.x += controlRect.width + 5f; controlRect.width -= 5f; EditorGUI.PropertyField(controlRect, verticalMapping_prop, GUIContent.none); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } if (horizontalMapping_prop.enumValueIndex > 0) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(uvLineOffset_prop, new GUIContent("UV Line Offset"), GUILayout.MinWidth(70f)); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(enableKerning_prop, new GUIContent("Enable Kerning?")); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(enableExtraPadding_prop, new GUIContent("Extra Padding?")); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; checkPaddingRequired_prop.boolValue = true; } EditorGUILayout.EndHorizontal(); } if (GUILayout.Button("<b>EXTRA SETTINGS</b>" + (m_foldout.extraSettings ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { m_foldout.extraSettings = !m_foldout.extraSettings; } if (m_foldout.extraSettings) { EditorGUI.indentLevel = 0; EditorGUI.BeginChangeCheck(); DrawMaginProperty(margin_prop, "Margins"); if (EditorGUI.EndChangeCheck()) { m_textComponent.margin = margin_prop.vector4Value; havePropertiesChanged = true; } GUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Sorting Layer"); EditorGUI.BeginChangeCheck(); float labelWidth2 = EditorGUIUtility.labelWidth; float fieldWidth2 = EditorGUIUtility.fieldWidth; string[] sortingLayerNames = SortingLayerHelper.sortingLayerNames; string sortingLayerNameFromID = SortingLayerHelper.GetSortingLayerNameFromID(m_textComponent.sortingLayerID); int num11 = Array.IndexOf(sortingLayerNames, sortingLayerNameFromID); EditorGUIUtility.fieldWidth = 0f; int num12 = EditorGUILayout.Popup(string.Empty, num11, sortingLayerNames, GUILayout.MinWidth(80f)); if (num12 != num11) { m_textComponent.sortingLayerID = SortingLayerHelper.GetSortingLayerIDForIndex(num12); } EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 80f; int num13 = EditorGUILayout.IntField("Order", m_textComponent.sortingOrder); if (num13 != m_textComponent.sortingOrder) { m_textComponent.sortingOrder = num13; } EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = labelWidth2; EditorGUIUtility.fieldWidth = fieldWidth2; EditorGUILayout.PropertyField(geometrySortingOrder_prop, new GUIContent("Geometry Sorting")); EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = 150f; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(isOrthographic_prop, new GUIContent("Orthographic Mode?")); EditorGUILayout.PropertyField(isRichText_prop, new GUIContent("Enable Rich Text?")); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(enableEscapeCharacterParsing_prop, new GUIContent("Parse Escape Characters")); EditorGUILayout.PropertyField(useMaxVisibleDescender_prop, new GUIContent("Use Visible Descender")); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(spriteAsset_prop, new GUIContent("Sprite Asset", "The Sprite Asset used when NOT specifically referencing one using <sprite=\"Sprite Asset Name\"."), true); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; } EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(isVolumetricText_prop, new GUIContent("Enabled Volumetric Setup")); if (EditorGUI.EndChangeCheck()) { havePropertiesChanged = true; m_textComponent.textInfo.ResetVertexLayout(isVolumetricText_prop.boolValue); } EditorGUIUtility.labelWidth = 135f; GUILayout.Space(10f); } if (havePropertiesChanged) { havePropertiesChanged_prop.boolValue = true; havePropertiesChanged = false; } EditorGUILayout.Space(); base.serializedObject.ApplyModifiedProperties(); }
void DrawColor() { // FACE VERTEX COLOR EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_FontColorProp, k_BaseColorLabel); EditorGUILayout.PropertyField(m_EnableVertexGradientProp, k_ColorGradientLabel); if (EditorGUI.EndChangeCheck()) { m_HavePropertiesChanged = true; } EditorGUIUtility.fieldWidth = 0; if (m_EnableVertexGradientProp.boolValue) { EditorGUI.indentLevel += 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_FontColorGradientPresetProp, k_ColorPresetLabel); SerializedObject obj = null; SerializedProperty colorMode; SerializedProperty topLeft; SerializedProperty topRight; SerializedProperty bottomLeft; SerializedProperty bottomRight; if (m_FontColorGradientPresetProp.objectReferenceValue == null) { colorMode = m_ColorModeProp; topLeft = m_FontColorGradientProp.FindPropertyRelative("topLeft"); topRight = m_FontColorGradientProp.FindPropertyRelative("topRight"); bottomLeft = m_FontColorGradientProp.FindPropertyRelative("bottomLeft"); bottomRight = m_FontColorGradientProp.FindPropertyRelative("bottomRight"); } else { obj = new SerializedObject(m_FontColorGradientPresetProp.objectReferenceValue); colorMode = obj.FindProperty("colorMode"); topLeft = obj.FindProperty("topLeft"); topRight = obj.FindProperty("topRight"); bottomLeft = obj.FindProperty("bottomLeft"); bottomRight = obj.FindProperty("bottomRight"); } EditorGUILayout.PropertyField(colorMode, k_ColorModeLabel); var rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); EditorGUI.PrefixLabel(rect, k_CorenerColorsLabel); rect.x += EditorGUIUtility.labelWidth; rect.width = rect.width - EditorGUIUtility.labelWidth; switch ((ColorMode)colorMode.enumValueIndex) { case ColorMode.Single: TMP_EditorUtility.DrawColorProperty(rect, topLeft); topRight.colorValue = topLeft.colorValue; bottomLeft.colorValue = topLeft.colorValue; bottomRight.colorValue = topLeft.colorValue; break; case ColorMode.HorizontalGradient: rect.width /= 2f; TMP_EditorUtility.DrawColorProperty(rect, topLeft); rect.x += rect.width; TMP_EditorUtility.DrawColorProperty(rect, topRight); bottomLeft.colorValue = topLeft.colorValue; bottomRight.colorValue = topRight.colorValue; break; case ColorMode.VerticalGradient: TMP_EditorUtility.DrawColorProperty(rect, topLeft); rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); rect.x += EditorGUIUtility.labelWidth; TMP_EditorUtility.DrawColorProperty(rect, bottomLeft); topRight.colorValue = topLeft.colorValue; bottomRight.colorValue = bottomLeft.colorValue; break; case ColorMode.FourCornersGradient: rect.width /= 2f; TMP_EditorUtility.DrawColorProperty(rect, topLeft); rect.x += rect.width; TMP_EditorUtility.DrawColorProperty(rect, topRight); rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f; TMP_EditorUtility.DrawColorProperty(rect, bottomLeft); rect.x += rect.width; TMP_EditorUtility.DrawColorProperty(rect, bottomRight); break; } if (EditorGUI.EndChangeCheck()) { m_HavePropertiesChanged = true; if (obj != null) { obj.ApplyModifiedProperties(); TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(m_FontColorGradientPresetProp.objectReferenceValue as TMP_ColorGradient); } } EditorGUI.indentLevel -= 1; } EditorGUILayout.PropertyField(m_OverrideHtmlColorProp, k_OverrideTagsLabel); EditorGUILayout.Space(); }
void DrawFont() { // Update list of material presets if needed. if (m_IsPresetListDirty) { m_MaterialPresetNames = GetMaterialPresets(); } // FONT ASSET EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_FontAssetProp, k_FontAssetLabel); if (EditorGUI.EndChangeCheck()) { m_HavePropertiesChanged = true; m_HasFontAssetChangedProp.boolValue = true; m_IsPresetListDirty = true; m_MaterialPresetSelectionIndex = 0; } Rect rect; // MATERIAL PRESET if (m_MaterialPresetNames != null) { EditorGUI.BeginChangeCheck(); rect = EditorGUILayout.GetControlRect(false, 17); float oldHeight = EditorStyles.popup.fixedHeight; EditorStyles.popup.fixedHeight = rect.height; int oldSize = EditorStyles.popup.fontSize; EditorStyles.popup.fontSize = 11; m_MaterialPresetSelectionIndex = EditorGUI.Popup(rect, k_MaterialPresetLabel, m_MaterialPresetSelectionIndex, m_MaterialPresetNames); if (EditorGUI.EndChangeCheck()) { m_FontSharedMaterialProp.objectReferenceValue = m_MaterialPresets[m_MaterialPresetSelectionIndex]; m_HavePropertiesChanged = true; } //Make sure material preset selection index matches the selection if (m_MaterialPresetSelectionIndex < m_MaterialPresetNames.Length && m_TargetMaterial != m_MaterialPresets[m_MaterialPresetSelectionIndex] && !m_HavePropertiesChanged) { m_IsPresetListDirty = true; } EditorStyles.popup.fixedHeight = oldHeight; EditorStyles.popup.fontSize = oldSize; } // FONT STYLE EditorGUI.BeginChangeCheck(); int v1, v2, v3, v4, v5, v6, v7; if (EditorGUIUtility.wideMode) { rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f); EditorGUI.PrefixLabel(rect, k_FontStyleLabel); int styleValue = m_FontStyleProp.intValue; rect.x += EditorGUIUtility.labelWidth; rect.width -= EditorGUIUtility.labelWidth; rect.width = Mathf.Max(25f, rect.width / 7f); v1 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 1) == 1, k_BoldLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 1 : 0; // Bold rect.x += rect.width; v2 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 2) == 2, k_ItalicLabel, TMP_UIStyleManager.alignmentButtonMid) ? 2 : 0; // Italics rect.x += rect.width; v3 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 4) == 4, k_UnderlineLabel, TMP_UIStyleManager.alignmentButtonMid) ? 4 : 0; // Underline rect.x += rect.width; v7 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 64) == 64, k_StrikethroughLabel, TMP_UIStyleManager.alignmentButtonRight) ? 64 : 0; // Strikethrough rect.x += rect.width; int selected = 0; EditorGUI.BeginChangeCheck(); v4 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 8) == 8, k_LowercaseLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 8 : 0; // Lowercase if (EditorGUI.EndChangeCheck() && v4 > 0) { selected = v4; } rect.x += rect.width; EditorGUI.BeginChangeCheck(); v5 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 16) == 16, k_UppercaseLabel, TMP_UIStyleManager.alignmentButtonMid) ? 16 : 0; // Uppercase if (EditorGUI.EndChangeCheck() && v5 > 0) { selected = v5; } rect.x += rect.width; EditorGUI.BeginChangeCheck(); v6 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 32) == 32, k_SmallcapsLabel, TMP_UIStyleManager.alignmentButtonRight) ? 32 : 0; // Smallcaps if (EditorGUI.EndChangeCheck() && v6 > 0) { selected = v6; } if (selected > 0) { v4 = selected == 8 ? 8 : 0; v5 = selected == 16 ? 16 : 0; v6 = selected == 32 ? 32 : 0; } } else { rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f); EditorGUI.PrefixLabel(rect, k_FontStyleLabel); int styleValue = m_FontStyleProp.intValue; rect.x += EditorGUIUtility.labelWidth; rect.width -= EditorGUIUtility.labelWidth; rect.width = Mathf.Max(25f, rect.width / 4f); v1 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 1) == 1, k_BoldLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 1 : 0; // Bold rect.x += rect.width; v2 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 2) == 2, k_ItalicLabel, TMP_UIStyleManager.alignmentButtonMid) ? 2 : 0; // Italics rect.x += rect.width; v3 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 4) == 4, k_UnderlineLabel, TMP_UIStyleManager.alignmentButtonMid) ? 4 : 0; // Underline rect.x += rect.width; v7 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 64) == 64, k_StrikethroughLabel, TMP_UIStyleManager.alignmentButtonRight) ? 64 : 0; // Strikethrough rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 2f); rect.x += EditorGUIUtility.labelWidth; rect.width -= EditorGUIUtility.labelWidth; rect.width = Mathf.Max(25f, rect.width / 4f); int selected = 0; EditorGUI.BeginChangeCheck(); v4 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 8) == 8, k_LowercaseLabel, TMP_UIStyleManager.alignmentButtonLeft) ? 8 : 0; // Lowercase if (EditorGUI.EndChangeCheck() && v4 > 0) { selected = v4; } rect.x += rect.width; EditorGUI.BeginChangeCheck(); v5 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 16) == 16, k_UppercaseLabel, TMP_UIStyleManager.alignmentButtonMid) ? 16 : 0; // Uppercase if (EditorGUI.EndChangeCheck() && v5 > 0) { selected = v5; } rect.x += rect.width; EditorGUI.BeginChangeCheck(); v6 = TMP_EditorUtility.EditorToggle(rect, (styleValue & 32) == 32, k_SmallcapsLabel, TMP_UIStyleManager.alignmentButtonRight) ? 32 : 0; // Smallcaps if (EditorGUI.EndChangeCheck() && v6 > 0) { selected = v6; } if (selected > 0) { v4 = selected == 8 ? 8 : 0; v5 = selected == 16 ? 16 : 0; v6 = selected == 32 ? 32 : 0; } } if (EditorGUI.EndChangeCheck()) { m_FontStyleProp.intValue = v1 + v2 + v3 + v4 + v5 + v6 + v7; m_HavePropertiesChanged = true; } // FONT SIZE EditorGUI.BeginChangeCheck(); EditorGUI.BeginDisabledGroup(m_AutoSizingProp.boolValue); EditorGUILayout.PropertyField(m_FontSizeProp, k_FontSizeLabel, GUILayout.MaxWidth(EditorGUIUtility.labelWidth + 50f)); EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { m_FontSizeBaseProp.floatValue = m_FontSizeProp.floatValue; m_HavePropertiesChanged = true; } EditorGUI.indentLevel += 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_AutoSizingProp, k_AutoSizeLabel); if (EditorGUI.EndChangeCheck()) { if (m_AutoSizingProp.boolValue == false) { m_FontSizeProp.floatValue = m_FontSizeBaseProp.floatValue; } m_HavePropertiesChanged = true; } // Show auto sizing options if (m_AutoSizingProp.boolValue) { rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight); EditorGUI.PrefixLabel(rect, k_AutoSizeOptionsLabel); int previousIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 4f; rect.x += EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 24; EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(rect, m_FontSizeMinProp, k_MinLabel); if (EditorGUI.EndChangeCheck()) { m_FontSizeMinProp.floatValue = Mathf.Min(m_FontSizeMinProp.floatValue, m_FontSizeMaxProp.floatValue); m_HavePropertiesChanged = true; } rect.x += rect.width; EditorGUIUtility.labelWidth = 27; EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(rect, m_FontSizeMaxProp, k_MaxLabel); if (EditorGUI.EndChangeCheck()) { m_FontSizeMaxProp.floatValue = Mathf.Max(m_FontSizeMinProp.floatValue, m_FontSizeMaxProp.floatValue); m_HavePropertiesChanged = true; } rect.x += rect.width; EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = 36; EditorGUI.PropertyField(rect, m_CharWidthMaxAdjProp, k_WdLabel); rect.x += rect.width; EditorGUIUtility.labelWidth = 28; EditorGUI.PropertyField(rect, m_LineSpacingMaxProp, k_LineLabel); EditorGUIUtility.labelWidth = 0; if (EditorGUI.EndChangeCheck()) { m_CharWidthMaxAdjProp.floatValue = Mathf.Clamp(m_CharWidthMaxAdjProp.floatValue, 0, 50); m_LineSpacingMaxProp.floatValue = Mathf.Min(0, m_LineSpacingMaxProp.floatValue); m_HavePropertiesChanged = true; } EditorGUI.indentLevel = previousIndent; } EditorGUI.indentLevel -= 1; EditorGUILayout.Space(); }
public override void OnInspectorGUI() { Event currentEvent = Event.current; serializedObject.Update(); m_IsStyleSheetDirty = false; int arraySize = m_StyleListProp.arraySize; int itemsPerPage = (Screen.height - 100) / 110; if (arraySize > 0) { // Display each Style entry using the StyleDrawer PropertyDrawer. for (int i = itemsPerPage * m_Page; i < arraySize && i < itemsPerPage * (m_Page + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginVertical(EditorStyles.helpBox); SerializedProperty styleProperty = m_StyleListProp.GetArrayElementAtIndex(i); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(styleProperty); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { // } // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedElement == i) { m_SelectedElement = -1; } else { m_SelectedElement = i; GUIUtility.keyboardControl = 0; } } // Handle Selection Highlighting if (m_SelectedElement == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw options to MoveUp, MoveDown, Add or Remove Sprites Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); controlRect.width /= 6; // Move sprite up. bool guiEnabled = GUI.enabled; if (i == 0) { GUI.enabled = false; } if (GUI.Button(controlRect, "Up")) { SwapStyleElements(i, i - 1); } GUI.enabled = guiEnabled; // Move sprite down. controlRect.x += controlRect.width; if (i == arraySize - 1) { GUI.enabled = false; } if (GUI.Button(controlRect, "Down")) { SwapStyleElements(i, i + 1); } GUI.enabled = guiEnabled; /* * // Move sprite to new index * controlRect.x += controlRect.width * 2; * //if (i == arraySize - 1) { GUI.enabled = false; } * m_moveToIndex = EditorGUI.IntField(controlRect, m_moveToIndex); * controlRect.x -= controlRect.width; * if (GUI.Button(controlRect, "Goto")) * { * MoveGlyphToIndex(i, m_moveToIndex); * } * //controlRect.x += controlRect.width; * GUI.enabled = guiEnabled; */ // Add new Sprite controlRect.x += controlRect.width * 3; if (GUI.Button(controlRect, "+")) { // Copy selected element m_StyleListProp.InsertArrayElementAtIndex(m_SelectedElement); // Move copy of element to last index in the array. m_StyleListProp.MoveArrayElement(m_SelectedElement, arraySize); serializedObject.ApplyModifiedProperties(); m_StyleSheet.RefreshStyles(); } // Delete selected Sprite controlRect.x += controlRect.width; if (m_SelectedElement == -1) { GUI.enabled = false; } if (GUI.Button(controlRect, "-")) { m_StyleListProp.DeleteArrayElementAtIndex(m_SelectedElement); m_SelectedElement = -1; serializedObject.ApplyModifiedProperties(); m_StyleSheet.RefreshStyles(); return; } } } } int shiftMultiplier = currentEvent.shift ? 10 : 1; // Page + Shift goes 10 page forward // Return if we can't display any items. if (itemsPerPage == 0) { return; } Rect pagePos = EditorGUILayout.GetControlRect(false, 20); pagePos.width /= 3; // Previous Page if (m_Page > 0) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Previous")) { m_Page -= 1 * shiftMultiplier; } // PAGE COUNTER GUI.enabled = true; pagePos.x += pagePos.width; int totalPages = (int)(arraySize / (float)itemsPerPage + 0.999f); GUI.Label(pagePos, "Page " + (m_Page + 1) + " / " + totalPages, TMP_UIStyleManager.centeredLabel); // Next Page pagePos.x += pagePos.width; if (itemsPerPage * (m_Page + 1) < arraySize) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Next")) { m_Page += 1 * shiftMultiplier; } // Clamp page range m_Page = Mathf.Clamp(m_Page, 0, arraySize / itemsPerPage); if (serializedObject.ApplyModifiedProperties()) { TMPro_EventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true); if (m_IsStyleSheetDirty) { m_IsStyleSheetDirty = false; m_StyleSheet.RefreshStyles(); } } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_SelectedElement = -1; } }
public override void OnInspectorGUI() { Event current = Event.current; string commandName = current.commandName; base.serializedObject.Update(); EditorGUIUtility.labelWidth = 135f; GUILayout.Label("<b>TextMeshPro - Sprite Asset</b>", TMP_UIStyleManager.Section_Label); GUILayout.Label("Sprite Info", TMP_UIStyleManager.Section_Label); EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_spriteAtlas_prop, new GUIContent("Sprite Atlas")); if (EditorGUI.EndChangeCheck()) { Texture2D texture2D = m_spriteAtlas_prop.objectReferenceValue as Texture2D; if (texture2D != null) { Material material = m_material_prop.objectReferenceValue as Material; if (material != null) { material.mainTexture = texture2D; } } } GUI.enabled = true; EditorGUILayout.PropertyField(m_material_prop, new GUIContent("Default Material")); EditorGUI.indentLevel = 0; if (GUILayout.Button("Fallback Sprite Assets\t" + (UI_PanelState.fallbackSpriteAssetPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fallbackSpriteAssetPanel = !UI_PanelState.fallbackSpriteAssetPanel; } if (UI_PanelState.fallbackSpriteAssetPanel) { EditorGUIUtility.labelWidth = 120f; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Sprite Assets that will be searched and used as fallback when a given sprite is missing from this sprite asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); m_fallbackSpriteAssetList.DoLayoutList(); EditorGUILayout.EndVertical(); } GUI.enabled = true; GUILayout.Space(10f); EditorGUI.indentLevel = 0; if (GUILayout.Button("Sprite List\t\t" + (UI_PanelState.spriteInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.spriteInfoPanel = !UI_PanelState.spriteInfoPanel; } if (UI_PanelState.spriteInfoPanel) { int num = m_spriteInfoList_prop.arraySize; int num2 = 10; EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string text = EditorGUILayout.TextField("Sprite Search", m_searchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (!string.IsNullOrEmpty(text)) { m_searchPattern = text.ToLower(CultureInfo.InvariantCulture).Trim(); SearchGlyphTable(m_searchPattern, ref m_searchList); } m_isSearchDirty = false; } string str = string.IsNullOrEmpty(m_searchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, str)) { GUIUtility.keyboardControl = 0; m_searchPattern = string.Empty; } EditorGUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(m_searchPattern)) { num = m_searchList.Count; } DisplayGlyphPageNavigation(num, num2); EditorGUILayout.EndVertical(); if (num > 0) { for (int i = num2 * m_page; i < num && i < num2 * (m_page + 1); i++) { Rect rect = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int index = i; if (!string.IsNullOrEmpty(m_searchPattern)) { index = m_searchList[i]; } SerializedProperty arrayElementAtIndex = m_spriteInfoList_prop.GetArrayElementAtIndex(index); EditorGUI.BeginDisabledGroup(i != m_selectedElement); EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.Height(75f)); EditorGUILayout.PropertyField(arrayElementAtIndex); EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); Rect rect2 = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); Rect rect3 = new Rect(rect.x, rect.y, rect2.width, rect2.y - rect.y); if (DoSelectionCheck(rect3)) { m_selectedElement = i; GUIUtility.keyboardControl = 0; } if (m_selectedElement == i) { TMP_EditorUtility.DrawBox(rect3, 2f, new Color32(40, 192, byte.MaxValue, byte.MaxValue)); Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); controlRect.width /= 8f; bool enabled = GUI.enabled; if (i == 0) { GUI.enabled = false; } if (GUI.Button(controlRect, "Up")) { SwapSpriteElement(i, i - 1); } GUI.enabled = enabled; controlRect.x += controlRect.width; if (i == num - 1) { GUI.enabled = false; } if (GUI.Button(controlRect, "Down")) { SwapSpriteElement(i, i + 1); } GUI.enabled = enabled; controlRect.x += controlRect.width * 2f; m_moveToIndex = EditorGUI.IntField(controlRect, m_moveToIndex); controlRect.x -= controlRect.width; if (GUI.Button(controlRect, "Goto")) { MoveSpriteElement(i, m_moveToIndex); } GUI.enabled = enabled; controlRect.x += controlRect.width * 4f; if (GUI.Button(controlRect, "+")) { m_spriteInfoList_prop.arraySize++; int num3 = m_spriteInfoList_prop.arraySize - 1; SerializedProperty target = m_spriteInfoList_prop.GetArrayElementAtIndex(num3); CopySerializedProperty(m_spriteInfoList_prop.GetArrayElementAtIndex(index), ref target); target.FindPropertyRelative("id").intValue = num3; base.serializedObject.ApplyModifiedProperties(); m_isSearchDirty = true; } controlRect.x += controlRect.width; if (m_selectedElement == -1) { GUI.enabled = false; } if (GUI.Button(controlRect, "-")) { m_spriteInfoList_prop.DeleteArrayElementAtIndex(index); m_selectedElement = -1; base.serializedObject.ApplyModifiedProperties(); m_isSearchDirty = true; return; } } } } DisplayGlyphPageNavigation(num, num2); EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 20f; GUILayout.Space(5f); GUI.enabled = true; EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label); Rect controlRect2 = EditorGUILayout.GetControlRect(false, 40f); float num4 = (controlRect2.width - 75f) / 4f; EditorGUI.LabelField(controlRect2, "Global Offsets & Scale", EditorStyles.boldLabel); controlRect2.x += 70f; bool changed = GUI.changed; GUI.changed = false; m_xOffset = EditorGUI.FloatField(new Rect(controlRect2.x + 5f + num4 * 0f, controlRect2.y + 20f, num4 - 5f, 18f), new GUIContent("OX:"), m_xOffset); if (GUI.changed) { UpdateGlobalProperty("xOffset", m_xOffset); } m_yOffset = EditorGUI.FloatField(new Rect(controlRect2.x + 5f + num4 * 1f, controlRect2.y + 20f, num4 - 5f, 18f), new GUIContent("OY:"), m_yOffset); if (GUI.changed) { UpdateGlobalProperty("yOffset", m_yOffset); } m_xAdvance = EditorGUI.FloatField(new Rect(controlRect2.x + 5f + num4 * 2f, controlRect2.y + 20f, num4 - 5f, 18f), new GUIContent("ADV."), m_xAdvance); if (GUI.changed) { UpdateGlobalProperty("xAdvance", m_xAdvance); } m_scale = EditorGUI.FloatField(new Rect(controlRect2.x + 5f + num4 * 3f, controlRect2.y + 20f, num4 - 5f, 18f), new GUIContent("SF."), m_scale); if (GUI.changed) { UpdateGlobalProperty("scale", m_scale); } EditorGUILayout.EndVertical(); GUI.changed = changed; } if (base.serializedObject.ApplyModifiedProperties() || commandName == "UndoRedoPerformed" || isAssetDirty) { isAssetDirty = false; EditorUtility.SetDirty(base.target); } GUI.enabled = true; if (current.type == EventType.MouseDown && current.button == 0) { m_selectedElement = -1; } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_ColorMode, new GUIContent("Color Mode")); if (EditorGUI.EndChangeCheck()) { switch ((ColorMode)m_ColorMode.enumValueIndex) { case ColorMode.Single: m_TopRightColor.colorValue = m_TopLeftColor.colorValue; m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue; m_BottomRightColor.colorValue = m_TopLeftColor.colorValue; break; case ColorMode.HorizontalGradient: m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue; m_BottomRightColor.colorValue = m_TopRightColor.colorValue; break; case ColorMode.VerticalGradient: m_TopRightColor.colorValue = m_TopLeftColor.colorValue; m_BottomRightColor.colorValue = m_BottomLeftColor.colorValue; break; } } Rect rect; switch ((ColorMode)m_ColorMode.enumValueIndex) { case ColorMode.Single: EditorGUI.BeginChangeCheck(); rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); EditorGUI.PrefixLabel(rect, new GUIContent("Colors")); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f); TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor); if (EditorGUI.EndChangeCheck()) { m_TopRightColor.colorValue = m_TopLeftColor.colorValue; m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue; m_BottomRightColor.colorValue = m_TopLeftColor.colorValue; } break; case ColorMode.HorizontalGradient: rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); EditorGUI.PrefixLabel(rect, new GUIContent("Colors")); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f; EditorGUI.BeginChangeCheck(); TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor); if (EditorGUI.EndChangeCheck()) { m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue; } rect.x += rect.width; EditorGUI.BeginChangeCheck(); TMP_EditorUtility.DrawColorProperty(rect, m_TopRightColor); if (EditorGUI.EndChangeCheck()) { m_BottomRightColor.colorValue = m_TopRightColor.colorValue; } break; case ColorMode.VerticalGradient: rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); EditorGUI.PrefixLabel(rect, new GUIContent("Colors")); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f); rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2); EditorGUI.BeginChangeCheck(); TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor); if (EditorGUI.EndChangeCheck()) { m_TopRightColor.colorValue = m_TopLeftColor.colorValue; } rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f); rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2); EditorGUI.BeginChangeCheck(); TMP_EditorUtility.DrawColorProperty(rect, m_BottomLeftColor); if (EditorGUI.EndChangeCheck()) { m_BottomRightColor.colorValue = m_BottomLeftColor.colorValue; } break; case ColorMode.FourCornersGradient: rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); EditorGUI.PrefixLabel(rect, new GUIContent("Colors")); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f; rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2); TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor); rect.x += rect.width; TMP_EditorUtility.DrawColorProperty(rect, m_TopRightColor); rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2)); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f; rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2); TMP_EditorUtility.DrawColorProperty(rect, m_BottomLeftColor); rect.x += rect.width; TMP_EditorUtility.DrawColorProperty(rect, m_BottomRightColor); break; } if (serializedObject.ApplyModifiedProperties()) { TMPro_EventManager.ON_COLOR_GRAIDENT_PROPERTY_CHANGED(target as TMP_ColorGradient); } }
public override void OnInspectorGUI() { Event currentEvent = Event.current; serializedObject.Update(); int arraySize = m_StyleListProp.arraySize; int itemsPerPage = (Screen.height - 178) / 111; if (arraySize > 0) { // Display each Style entry using the StyleDrawer PropertyDrawer. for (int i = itemsPerPage * m_Page; i < arraySize && i < itemsPerPage * (m_Page + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginVertical(EditorStyles.helpBox); SerializedProperty spriteInfo = m_StyleListProp.GetArrayElementAtIndex(i); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(spriteInfo); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { // } // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedElement == i) { m_SelectedElement = -1; } else { m_SelectedElement = i; GUIUtility.keyboardControl = 0; } } // Handle Selection Highlighting if (m_SelectedElement == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); } } } int shiftMultiplier = currentEvent.shift ? 10 : 1; // Page + Shift goes 10 page forward GUILayout.Space(-3f); Rect pagePos = EditorGUILayout.GetControlRect(false, 20); pagePos.width /= 6; // Return if we can't display any items. if (itemsPerPage == 0) { return; } // Add new style. pagePos.x += pagePos.width * 4; if (GUI.Button(pagePos, "+")) { m_StyleListProp.arraySize += 1; serializedObject.ApplyModifiedProperties(); TMP_StyleSheet.RefreshStyles(); } // Delete selected style. pagePos.x += pagePos.width; if (m_SelectedElement == -1) { GUI.enabled = false; } if (GUI.Button(pagePos, "-")) { if (m_SelectedElement != -1) { m_StyleListProp.DeleteArrayElementAtIndex(m_SelectedElement); } m_SelectedElement = -1; serializedObject.ApplyModifiedProperties(); TMP_StyleSheet.RefreshStyles(); } GUILayout.Space(5f); pagePos = EditorGUILayout.GetControlRect(false, 20); pagePos.width /= 3; // Previous Page if (m_Page > 0) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Previous")) { m_Page -= 1 * shiftMultiplier; } // PAGE COUNTER GUI.enabled = true; pagePos.x += pagePos.width; int totalPages = (int)(arraySize / (float)itemsPerPage + 0.999f); GUI.Label(pagePos, "Page " + (m_Page + 1) + " / " + totalPages, TMP_UIStyleManager.centeredLabel); // Next Page pagePos.x += pagePos.width; if (itemsPerPage * (m_Page + 1) < arraySize) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Next")) { m_Page += 1 * shiftMultiplier; } // Clamp page range m_Page = Mathf.Clamp(m_Page, 0, arraySize / itemsPerPage); if (serializedObject.ApplyModifiedProperties()) { TMPro_EventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true); } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_SelectedElement = -1; } }
public override void OnInspectorGUI() { //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; string evt_cmd = currentEvent.commandName; // Get Current Event CommandName to check for Undo Events serializedObject.Update(); EditorGUIUtility.labelWidth = 135; // HEADER GUILayout.Label("<b>TextMeshPro - Sprite Asset</b>", TMP_UIStyleManager.Section_Label); // TEXTMESHPRO SPRITE INFO PANEL GUILayout.Label("Sprite Info", TMP_UIStyleManager.Section_Label); EditorGUI.indentLevel = 1; //GUI.enabled = false; // Lock UI EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_spriteAtlas_prop, new GUIContent("Sprite Atlas")); if (EditorGUI.EndChangeCheck()) { // Assign the new sprite atlas texture to the current material Texture2D tex = m_spriteAtlas_prop.objectReferenceValue as Texture2D; if (tex != null) { Material mat = m_material_prop.objectReferenceValue as Material; if (mat != null) { mat.mainTexture = tex; } } } GUI.enabled = true; EditorGUILayout.PropertyField(m_material_prop, new GUIContent("Default Material")); // FALLBACK SPRITE ASSETS EditorGUI.indentLevel = 0; if (GUILayout.Button("Fallback Sprite Assets\t" + (UI_PanelState.fallbackSpriteAssetPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fallbackSpriteAssetPanel = !UI_PanelState.fallbackSpriteAssetPanel; } if (UI_PanelState.fallbackSpriteAssetPanel) { EditorGUIUtility.labelWidth = 120; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Sprite Assets that will be searched and used as fallback when a given sprite is missing from this sprite asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); m_fallbackSpriteAssetList.DoLayoutList(); EditorGUILayout.EndVertical(); } // SPRITE LIST GUI.enabled = true; // Unlock UI GUILayout.Space(10); EditorGUI.indentLevel = 0; if (GUILayout.Button("Sprite List\t\t" + (UI_PanelState.spriteInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.spriteInfoPanel = !UI_PanelState.spriteInfoPanel; } if (UI_PanelState.spriteInfoPanel) { int arraySize = m_spriteInfoList_prop.arraySize; int itemsPerPage = 10; // (Screen.height - 292) / 80; // Display Glyph Management Tools EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.ExpandWidth(true)); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Sprite Search", m_searchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { //GUIUtility.keyboardControl = 0; m_searchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim(); // Search Glyph Table for potential matches SearchGlyphTable(m_searchPattern, ref m_searchList); } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_searchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_searchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_searchPattern)) { arraySize = m_searchList.Count; } // Display Page Navigation DisplayGlyphPageNavigation(arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); if (arraySize > 0) { // Display each SpriteInfo entry using the SpriteInfo property drawer. for (int i = itemsPerPage * m_page; i < arraySize && i < itemsPerPage * (m_page + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_searchPattern)) { elementIndex = m_searchList[i]; } SerializedProperty spriteInfo = m_spriteInfoList_prop.GetArrayElementAtIndex(elementIndex); EditorGUI.BeginDisabledGroup(i != m_selectedElement); { EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.Height(75)); { EditorGUILayout.PropertyField(spriteInfo); } EditorGUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { m_selectedElement = i; GUIUtility.keyboardControl = 0; } // Draw & Handle Section Area if (m_selectedElement == i) { // Draw selection highlight TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw options to MoveUp, MoveDown, Add or Remove Sprites Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); controlRect.width /= 8; // Move sprite up. bool guiEnabled = GUI.enabled; if (i == 0) { GUI.enabled = false; } if (GUI.Button(controlRect, "Up")) { SwapSpriteElement(i, i - 1); } GUI.enabled = guiEnabled; // Move sprite down. controlRect.x += controlRect.width; if (i == arraySize - 1) { GUI.enabled = false; } if (GUI.Button(controlRect, "Down")) { SwapSpriteElement(i, i + 1); } GUI.enabled = guiEnabled; // Move sprite to new index controlRect.x += controlRect.width * 2; //if (i == arraySize - 1) { GUI.enabled = false; } m_moveToIndex = EditorGUI.IntField(controlRect, m_moveToIndex); controlRect.x -= controlRect.width; if (GUI.Button(controlRect, "Goto")) { MoveSpriteElement(i, m_moveToIndex); } //controlRect.x += controlRect.width; GUI.enabled = guiEnabled; // Add new Sprite controlRect.x += controlRect.width * 4; if (GUI.Button(controlRect, "+")) { m_spriteInfoList_prop.arraySize += 1; int index = m_spriteInfoList_prop.arraySize - 1; SerializedProperty spriteInfo_prop = m_spriteInfoList_prop.GetArrayElementAtIndex(index); // Copy properties of the selected element CopySerializedProperty(m_spriteInfoList_prop.GetArrayElementAtIndex(elementIndex), ref spriteInfo_prop); spriteInfo_prop.FindPropertyRelative("id").intValue = index; serializedObject.ApplyModifiedProperties(); m_isSearchDirty = true; } // Delete selected Sprite controlRect.x += controlRect.width; if (m_selectedElement == -1) { GUI.enabled = false; } if (GUI.Button(controlRect, "-")) { m_spriteInfoList_prop.DeleteArrayElementAtIndex(elementIndex); m_selectedElement = -1; serializedObject.ApplyModifiedProperties(); m_isSearchDirty = true; return; } } } } DisplayGlyphPageNavigation(arraySize, itemsPerPage); EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 20f; GUILayout.Space(5f); // GLOBAL TOOLS #region Global Tools GUI.enabled = true; EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label); Rect rect = EditorGUILayout.GetControlRect(false, 40); float width = (rect.width - 75f) / 4; EditorGUI.LabelField(rect, "Global Offsets & Scale", EditorStyles.boldLabel); rect.x += 70; bool old_ChangedState = GUI.changed; GUI.changed = false; m_xOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 0, rect.y + 20, width - 5f, 18), new GUIContent("OX:"), m_xOffset); if (GUI.changed) { UpdateGlobalProperty("xOffset", m_xOffset); } m_yOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 1, rect.y + 20, width - 5f, 18), new GUIContent("OY:"), m_yOffset); if (GUI.changed) { UpdateGlobalProperty("yOffset", m_yOffset); } m_xAdvance = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 2, rect.y + 20, width - 5f, 18), new GUIContent("ADV."), m_xAdvance); if (GUI.changed) { UpdateGlobalProperty("xAdvance", m_xAdvance); } m_scale = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 3, rect.y + 20, width - 5f, 18), new GUIContent("SF."), m_scale); if (GUI.changed) { UpdateGlobalProperty("scale", m_scale); } EditorGUILayout.EndVertical(); #endregion GUI.changed = old_ChangedState; } if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { isAssetDirty = false; EditorUtility.SetDirty(target); //TMPro_EditorUtility.RepaintAll(); // Consider SetDirty } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_selectedElement = -1; } }
public static void GetUIStyles() { if (!(TMP_GUISkin != null)) { string assetLocation = TMP_EditorUtility.GetAssetLocation(); if (EditorGUIUtility.isProSkin) { TMP_GUISkin = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin); alignLeft = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignLeft.psd", typeof(Texture2D)) as Texture2D); alignCenter = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignCenter.psd", typeof(Texture2D)) as Texture2D); alignRight = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignRight.psd", typeof(Texture2D)) as Texture2D); alignJustified = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignJustified.psd", typeof(Texture2D)) as Texture2D); alignFlush = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignFlush.psd", typeof(Texture2D)) as Texture2D); alignGeoCenter = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignCenterGeo.psd", typeof(Texture2D)) as Texture2D); alignTop = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignTop.psd", typeof(Texture2D)) as Texture2D); alignMiddle = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignMiddle.psd", typeof(Texture2D)) as Texture2D); alignBottom = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignBottom.psd", typeof(Texture2D)) as Texture2D); alignBaseline = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignBaseLine.psd", typeof(Texture2D)) as Texture2D); alignMidline = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignMidLine.psd", typeof(Texture2D)) as Texture2D); alignCapline = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignCapLine.psd", typeof(Texture2D)) as Texture2D); progressTexture = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/Progress Bar.psd", typeof(Texture2D)) as Texture2D); selectionBox = (EditorGUIUtility.Load("IN thumbnailshadow On@2x") as Texture2D); } else { TMP_GUISkin = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin); alignLeft = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignLeft_Light.psd", typeof(Texture2D)) as Texture2D); alignCenter = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignCenter_Light.psd", typeof(Texture2D)) as Texture2D); alignRight = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignRight_Light.psd", typeof(Texture2D)) as Texture2D); alignJustified = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignJustified_Light.psd", typeof(Texture2D)) as Texture2D); alignFlush = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignFlush_Light.psd", typeof(Texture2D)) as Texture2D); alignGeoCenter = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignCenterGeo_Light.psd", typeof(Texture2D)) as Texture2D); alignTop = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignTop_Light.psd", typeof(Texture2D)) as Texture2D); alignMiddle = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignMiddle_Light.psd", typeof(Texture2D)) as Texture2D); alignBottom = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignBottom_Light.psd", typeof(Texture2D)) as Texture2D); alignBaseline = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignBaseLine_Light.psd", typeof(Texture2D)) as Texture2D); alignMidline = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignMidLine_Light.psd", typeof(Texture2D)) as Texture2D); alignCapline = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/btn_AlignCapLine_Light.psd", typeof(Texture2D)) as Texture2D); progressTexture = (AssetDatabase.LoadAssetAtPath(assetLocation + "/GUISkins/Textures/Progress Bar (Light).psd", typeof(Texture2D)) as Texture2D); selectionBox = (EditorGUIUtility.Load("IN thumbnailshadow On@2x") as Texture2D); } if (TMP_GUISkin != null) { Label = TMP_GUISkin.FindStyle("Label"); Section_Label = TMP_GUISkin.FindStyle("Section Label"); Group_Label = TMP_GUISkin.FindStyle("Group Label"); Group_Label_Left = TMP_GUISkin.FindStyle("Group Label - Left Half"); TextAreaBoxEditor = TMP_GUISkin.FindStyle("Text Area Box (Editor)"); TextAreaBoxWindow = TMP_GUISkin.FindStyle("Text Area Box (Window)"); TextureAreaBox = TMP_GUISkin.FindStyle("Texture Area Box"); SquareAreaBox85G = TMP_GUISkin.FindStyle("Square Area Box (85 Grey)"); alignContent_A = new GUIContent[4] { new GUIContent(alignLeft, "Left"), new GUIContent(alignCenter, "Center"), new GUIContent(alignRight, "Right"), new GUIContent(alignJustified, "Justified") //new GUIContent(alignFlush, "Flush"), //new GUIContent(alignGeoCenter, "Geometry Center") }; alignContent_B = new GUIContent[6] { new GUIContent(alignTop, "Top"), new GUIContent(alignMiddle, "Middle"), new GUIContent(alignBottom, "Bottom"), new GUIContent(alignBaseline, "Baseline"), new GUIContent(alignMidline, "Midline"), new GUIContent(alignCapline, "Capline") }; } } }
public override void OnInspectorGUI() { //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; string evt_cmd = currentEvent.commandName; // Get Current Event CommandName to check for Undo Events serializedObject.Update(); // TEXTMESHPRO SPRITE INFO PANEL #region Display Sprite Asset Face Info Rect rect = EditorGUILayout.GetControlRect(false, 24); GUI.Label(rect, new GUIContent("<b>Face Info</b> - v" + m_SpriteAsset.version), TMP_UIStyleManager.sectionHeader); rect.x += rect.width - 132f; rect.y += 2; rect.width = 130f; rect.height = 18f; if (GUI.Button(rect, new GUIContent("Update Sprite Asset"))) { TMP_SpriteAssetMenu.UpdateSpriteAsset(m_SpriteAsset); } EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(m_PointSizeProperty); EditorGUILayout.PropertyField(m_ScaleProperty); //EditorGUILayout.PropertyField(m_LineHeightProperty); EditorGUILayout.PropertyField(m_AscentLineProperty); EditorGUILayout.PropertyField(m_BaselineProperty); EditorGUILayout.PropertyField(m_DescentLineProperty); EditorGUILayout.Space(); #endregion // ATLAS TEXTURE & MATERIAL #region Display Atlas Texture and Material rect = EditorGUILayout.GetControlRect(false, 24); if (GUI.Button(rect, new GUIContent("<b>Atlas & Material</b>"), TMP_UIStyleManager.sectionHeader)) { UI_PanelState.spriteAtlasInfoPanel = !UI_PanelState.spriteAtlasInfoPanel; } GUI.Label(rect, (UI_PanelState.spriteAtlasInfoPanel ? "" : s_UiStateLabel[1]), TMP_UIStyleManager.rightLabel); if (UI_PanelState.spriteAtlasInfoPanel) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_spriteAtlas_prop, new GUIContent("Sprite Atlas")); if (EditorGUI.EndChangeCheck()) { // Assign the new sprite atlas texture to the current material Texture2D tex = m_spriteAtlas_prop.objectReferenceValue as Texture2D; if (tex != null) { Material mat = m_material_prop.objectReferenceValue as Material; if (mat != null) { mat.mainTexture = tex; } } } EditorGUILayout.PropertyField(m_material_prop, new GUIContent("Default Material")); EditorGUILayout.Space(); } #endregion // FALLBACK SPRITE ASSETS #region Display Sprite Fallbacks rect = EditorGUILayout.GetControlRect(false, 24); EditorGUI.indentLevel = 0; if (GUI.Button(rect, new GUIContent("<b>Fallback Sprite Assets</b>", "Select the Sprite Assets that will be searched and used as fallback when a given sprite is missing from this sprite asset."), TMP_UIStyleManager.sectionHeader)) { UI_PanelState.fallbackSpriteAssetPanel = !UI_PanelState.fallbackSpriteAssetPanel; } GUI.Label(rect, (UI_PanelState.fallbackSpriteAssetPanel ? "" : s_UiStateLabel[1]), TMP_UIStyleManager.rightLabel); if (UI_PanelState.fallbackSpriteAssetPanel) { m_fallbackSpriteAssetList.DoLayoutList(); EditorGUILayout.Space(); } #endregion // SPRITE CHARACTER TABLE #region Display Sprite Character Table EditorGUI.indentLevel = 0; rect = EditorGUILayout.GetControlRect(false, 24); if (GUI.Button(rect, new GUIContent("<b>Sprite Character Table</b>", "List of sprite characters contained in this sprite asset."), TMP_UIStyleManager.sectionHeader)) { UI_PanelState.spriteCharacterTablePanel = !UI_PanelState.spriteCharacterTablePanel; } GUI.Label(rect, (UI_PanelState.spriteCharacterTablePanel ? "" : s_UiStateLabel[1]), TMP_UIStyleManager.rightLabel); if (UI_PanelState.spriteCharacterTablePanel) { int arraySize = m_SpriteCharacterTableProperty.arraySize; int itemsPerPage = 10; // Display Glyph Management Tools EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandWidth(true)); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Sprite Search", m_CharacterSearchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_IsCharacterSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { //GUIUtility.keyboardControl = 0; m_CharacterSearchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim(); // Search Glyph Table for potential matches SearchCharacterTable(m_CharacterSearchPattern, ref m_CharacterSearchList); } else { m_CharacterSearchPattern = null; } m_IsCharacterSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_CharacterSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_CharacterSearchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_CharacterSearchPattern)) { arraySize = m_CharacterSearchList.Count; } // Display Page Navigation DisplayPageNavigation(ref m_CurrentCharacterPage, arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); if (arraySize > 0) { // Display each SpriteInfo entry using the SpriteInfo property drawer. for (int i = itemsPerPage * m_CurrentCharacterPage; i < arraySize && i < itemsPerPage * (m_CurrentCharacterPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_CharacterSearchPattern)) { elementIndex = m_CharacterSearchList[i]; } SerializedProperty spriteCharacterProperty = m_SpriteCharacterTableProperty.GetArrayElementAtIndex(elementIndex); EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUI.BeginDisabledGroup(i != m_selectedElement); { EditorGUILayout.PropertyField(spriteCharacterProperty); } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndVertical(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_selectedElement == i) { m_selectedElement = -1; } else { m_selectedElement = i; GUIUtility.keyboardControl = 0; } } // Draw & Handle Section Area if (m_selectedElement == i) { // Draw selection highlight TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw options to MoveUp, MoveDown, Add or Remove Sprites Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); controlRect.width /= 8; // Move sprite up. bool guiEnabled = GUI.enabled; if (i == 0) { GUI.enabled = false; } if (GUI.Button(controlRect, "Up")) { SwapCharacterElements(i, i - 1); } GUI.enabled = guiEnabled; // Move sprite down. controlRect.x += controlRect.width; if (i == arraySize - 1) { GUI.enabled = false; } if (GUI.Button(controlRect, "Down")) { SwapCharacterElements(i, i + 1); } GUI.enabled = guiEnabled; // Move sprite to new index controlRect.x += controlRect.width * 2; //if (i == arraySize - 1) { GUI.enabled = false; } m_moveToIndex = EditorGUI.IntField(controlRect, m_moveToIndex); controlRect.x -= controlRect.width; if (GUI.Button(controlRect, "Goto")) { MoveCharacterToIndex(i, m_moveToIndex); } //controlRect.x += controlRect.width; GUI.enabled = guiEnabled; // Add new Sprite controlRect.x += controlRect.width * 4; if (GUI.Button(controlRect, "+")) { m_SpriteCharacterTableProperty.arraySize += 1; int index = m_SpriteCharacterTableProperty.arraySize - 1; SerializedProperty spriteInfo_prop = m_SpriteCharacterTableProperty.GetArrayElementAtIndex(index); // Copy properties of the selected element CopyCharacterSerializedProperty(m_SpriteCharacterTableProperty.GetArrayElementAtIndex(elementIndex), ref spriteInfo_prop); //spriteInfo_prop.FindPropertyRelative("m_Index").intValue = index; serializedObject.ApplyModifiedProperties(); m_IsCharacterSearchDirty = true; } // Delete selected Sprite controlRect.x += controlRect.width; if (m_selectedElement == -1) { GUI.enabled = false; } if (GUI.Button(controlRect, "-")) { m_SpriteCharacterTableProperty.DeleteArrayElementAtIndex(elementIndex); m_selectedElement = -1; serializedObject.ApplyModifiedProperties(); m_IsCharacterSearchDirty = true; return; } } } } DisplayPageNavigation(ref m_CurrentCharacterPage, arraySize, itemsPerPage); EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 20f; GUILayout.Space(5f); // GLOBAL TOOLS #region Global Tools /* * GUI.enabled = true; * EditorGUILayout.BeginVertical(EditorStyles.helpBox); * rect = EditorGUILayout.GetControlRect(false, 40); * * float width = (rect.width - 75f) / 4; * EditorGUI.LabelField(rect, "Global Offsets & Scale", EditorStyles.boldLabel); * * * rect.x += 70; * bool old_ChangedState = GUI.changed; * * GUI.changed = false; * m_xOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 0, rect.y + 20, width - 5f, 18), new GUIContent("OX:"), m_xOffset); * if (GUI.changed) UpdateGlobalProperty("m_HorizontalBearingX", m_xOffset); * * m_yOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 1, rect.y + 20, width - 5f, 18), new GUIContent("OY:"), m_yOffset); * if (GUI.changed) UpdateGlobalProperty("m_HorizontalBearingY", m_yOffset); * * m_xAdvance = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 2, rect.y + 20, width - 5f, 18), new GUIContent("ADV."), m_xAdvance); * if (GUI.changed) UpdateGlobalProperty("m_HorizontalAdvance", m_xAdvance); * * m_scale = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 3, rect.y + 20, width - 5f, 18), new GUIContent("SF."), m_scale); * if (GUI.changed) UpdateGlobalProperty("m_Scale", m_scale); * * EditorGUILayout.EndVertical(); * * GUI.changed = old_ChangedState; */ #endregion } #endregion // SPRITE GLYPH TABLE #region Display Sprite Glyph Table EditorGUI.indentLevel = 0; rect = EditorGUILayout.GetControlRect(false, 24); if (GUI.Button(rect, new GUIContent("<b>Sprite Glyph Table</b>", "A list of the SpriteGlyphs contained in this sprite asset."), TMP_UIStyleManager.sectionHeader)) { UI_PanelState.spriteGlyphTablePanel = !UI_PanelState.spriteGlyphTablePanel; } GUI.Label(rect, (UI_PanelState.spriteGlyphTablePanel ? "" : s_UiStateLabel[1]), TMP_UIStyleManager.rightLabel); if (UI_PanelState.spriteGlyphTablePanel) { int arraySize = m_SpriteGlyphTableProperty.arraySize; int itemsPerPage = 10; // Display Glyph Management Tools EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandWidth(true)); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Sprite Search", m_GlyphSearchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_IsGlyphSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { //GUIUtility.keyboardControl = 0; m_GlyphSearchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim(); // Search Glyph Table for potential matches SearchCharacterTable(m_GlyphSearchPattern, ref m_GlyphSearchList); } else { m_GlyphSearchPattern = null; } m_IsGlyphSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_GlyphSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_GlyphSearchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_GlyphSearchPattern)) { arraySize = m_GlyphSearchList.Count; } // Display Page Navigation DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); if (arraySize > 0) { // Display each SpriteInfo entry using the SpriteInfo property drawer. for (int i = itemsPerPage * m_CurrentGlyphPage; i < arraySize && i < itemsPerPage * (m_CurrentGlyphPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_GlyphSearchPattern)) { elementIndex = m_GlyphSearchList[i]; } SerializedProperty spriteGlyphProperty = m_SpriteGlyphTableProperty.GetArrayElementAtIndex(elementIndex); EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUI.BeginDisabledGroup(i != m_selectedElement); { EditorGUILayout.PropertyField(spriteGlyphProperty); } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndVertical(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_selectedElement == i) { m_selectedElement = -1; } else { m_selectedElement = i; GUIUtility.keyboardControl = 0; } } // Draw & Handle Section Area if (m_selectedElement == i) { // Draw selection highlight TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw options to MoveUp, MoveDown, Add or Remove Sprites Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); controlRect.width /= 8; // Move sprite up. bool guiEnabled = GUI.enabled; if (i == 0) { GUI.enabled = false; } if (GUI.Button(controlRect, "Up")) { SwapGlyphElements(i, i - 1); } GUI.enabled = guiEnabled; // Move sprite down. controlRect.x += controlRect.width; if (i == arraySize - 1) { GUI.enabled = false; } if (GUI.Button(controlRect, "Down")) { SwapGlyphElements(i, i + 1); } GUI.enabled = guiEnabled; // Move sprite to new index controlRect.x += controlRect.width * 2; //if (i == arraySize - 1) { GUI.enabled = false; } m_moveToIndex = EditorGUI.IntField(controlRect, m_moveToIndex); controlRect.x -= controlRect.width; if (GUI.Button(controlRect, "Goto")) { MoveGlyphToIndex(i, m_moveToIndex); } //controlRect.x += controlRect.width; GUI.enabled = guiEnabled; // Add new Sprite controlRect.x += controlRect.width * 4; if (GUI.Button(controlRect, "+")) { m_SpriteGlyphTableProperty.arraySize += 1; int index = m_SpriteGlyphTableProperty.arraySize - 1; SerializedProperty newSpriteGlyphProperty = m_SpriteGlyphTableProperty.GetArrayElementAtIndex(index); // Copy properties of the selected element CopyGlyphSerializedProperty(m_SpriteGlyphTableProperty.GetArrayElementAtIndex(elementIndex), ref newSpriteGlyphProperty); newSpriteGlyphProperty.FindPropertyRelative("m_Index").intValue = index; serializedObject.ApplyModifiedProperties(); m_IsGlyphSearchDirty = true; //m_SpriteAsset.UpdateLookupTables(); } // Delete selected Sprite controlRect.x += controlRect.width; if (m_selectedElement == -1) { GUI.enabled = false; } if (GUI.Button(controlRect, "-")) { SerializedProperty selectedSpriteGlyphProperty = m_SpriteGlyphTableProperty.GetArrayElementAtIndex(elementIndex); int selectedGlyphIndex = selectedSpriteGlyphProperty.FindPropertyRelative("m_Index").intValue; m_SpriteGlyphTableProperty.DeleteArrayElementAtIndex(elementIndex); // Remove all Sprite Characters referencing this glyph. for (int j = 0; j < m_SpriteCharacterTableProperty.arraySize; j++) { int glyphIndex = m_SpriteCharacterTableProperty.GetArrayElementAtIndex(j).FindPropertyRelative("m_GlyphIndex").intValue; if (glyphIndex == selectedGlyphIndex) { // Remove character m_SpriteCharacterTableProperty.DeleteArrayElementAtIndex(j); } } m_selectedElement = -1; serializedObject.ApplyModifiedProperties(); m_IsGlyphSearchDirty = true; //m_SpriteAsset.UpdateLookupTables(); return; } } } } DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage); EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 20f; GUILayout.Space(5f); // GLOBAL TOOLS #region Global Tools GUI.enabled = true; EditorGUILayout.BeginVertical(EditorStyles.helpBox); rect = EditorGUILayout.GetControlRect(false, 40); float width = (rect.width - 75f) / 4; EditorGUI.LabelField(rect, "Global Offsets & Scale", EditorStyles.boldLabel); rect.x += 70; bool old_ChangedState = GUI.changed; GUI.changed = false; m_xOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 0, rect.y + 20, width - 5f, 18), new GUIContent("OX:"), m_xOffset); if (GUI.changed) { UpdateGlobalProperty("m_HorizontalBearingX", m_xOffset); } m_yOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 1, rect.y + 20, width - 5f, 18), new GUIContent("OY:"), m_yOffset); if (GUI.changed) { UpdateGlobalProperty("m_HorizontalBearingY", m_yOffset); } m_xAdvance = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 2, rect.y + 20, width - 5f, 18), new GUIContent("ADV."), m_xAdvance); if (GUI.changed) { UpdateGlobalProperty("m_HorizontalAdvance", m_xAdvance); } m_scale = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 3, rect.y + 20, width - 5f, 18), new GUIContent("SF."), m_scale); if (GUI.changed) { UpdateGlobalProperty("m_Scale", m_scale); } EditorGUILayout.EndVertical(); #endregion GUI.changed = old_ChangedState; } #endregion if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { if (m_SpriteAsset.m_IsSpriteAssetLookupTablesDirty || evt_cmd == k_UndoRedo) { m_SpriteAsset.UpdateLookupTables(); } TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, m_SpriteAsset); isAssetDirty = false; EditorUtility.SetDirty(target); } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_selectedElement = -1; } }
private void DrawControls() { GUILayout.BeginVertical(); GUILayout.Label("<b>TextMeshPro - Font Asset Creator</b>", TMP_UIStyleManager.Section_Label, GUILayout.Width(300f)); GUILayout.Label("Font Settings", TMP_UIStyleManager.Section_Label, GUILayout.Width(300f)); GUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox, GUILayout.Width(300f)); EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 160f; EditorGUI.BeginChangeCheck(); font_TTF = (EditorGUILayout.ObjectField("Font Source", font_TTF, typeof(Font), false, GUILayout.Width(290f)) as Font); if (EditorGUI.EndChangeCheck()) { } if (FontSizingOption_Selection == 0) { FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(290f)); } else { EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 40f; GUILayout.BeginHorizontal(GUILayout.Width(290f)); FontSizingOption_Selection = EditorGUILayout.Popup("Font Size", FontSizingOption_Selection, FontSizingOptions, GUILayout.Width(225f)); font_size = EditorGUILayout.IntField(font_size); GUILayout.EndHorizontal(); } EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 160f; font_padding = EditorGUILayout.IntField("Font Padding", font_padding, GUILayout.Width(290f)); font_padding = (int)Mathf.Clamp(font_padding, 0f, 64f); m_fontPackingSelection = (FontPackingModes)(object)EditorGUILayout.EnumPopup("Packing Method", m_fontPackingSelection, GUILayout.Width(225f)); GUILayout.BeginHorizontal(GUILayout.Width(290f)); GUI.changed = false; EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 40f; GUILayout.Label("Atlas Resolution:", GUILayout.Width(116f)); font_atlas_width = EditorGUILayout.IntPopup(font_atlas_width, FontResolutionLabels, FontAtlasResolutions); font_atlas_height = EditorGUILayout.IntPopup(font_atlas_height, FontResolutionLabels, FontAtlasResolutions); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); bool flag = false; font_CharacterSet_Selection = EditorGUILayout.Popup("Character Set", font_CharacterSet_Selection, FontCharacterSets, GUILayout.Width(290f)); if (EditorGUI.EndChangeCheck()) { characterSequence = ""; flag = true; } switch (font_CharacterSet_Selection) { case 0: characterSequence = "32 - 126, 160, 8203, 8230, 9633"; break; case 1: characterSequence = "32 - 126, 160 - 255, 8192 - 8303, 8364, 8482, 9633"; break; case 2: characterSequence = "32 - 64, 91 - 126, 160"; break; case 3: characterSequence = "32 - 96, 123 - 126, 160"; break; case 4: characterSequence = "32 - 64, 91 - 96, 123 - 126, 160"; break; case 5: { EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox); GUILayout.Label("Enter a sequence of decimal values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); m_fontAssetSelection = (EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290f)) as TMP_FontAsset); if ((EditorGUI.EndChangeCheck() || flag) && m_fontAssetSelection != null) { characterSequence = TMP_EditorUtility.GetDecimalCharacterSequence(TMP_FontAsset.GetCharactersArray(m_fontAssetSelection)); } EditorGUIUtility.labelWidth = 120f; char character = Event.current.character; if ((character < '0' || character > '9') && (character < ',' || character > '-')) { Event.current.character = '\0'; } GUILayout.Label("Character Sequence (Decimal)", TMP_UIStyleManager.Section_Label); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120f), GUILayout.MaxWidth(290f)); EditorGUILayout.EndVertical(); break; } case 6: { EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox); GUILayout.Label("Enter a sequence of Unicode (hex) values to define the characters to be included in the font asset or retrieve one from another font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); m_fontAssetSelection = (EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290f)) as TMP_FontAsset); if ((EditorGUI.EndChangeCheck() || flag) && m_fontAssetSelection != null) { characterSequence = TMP_EditorUtility.GetUnicodeCharacterSequence(TMP_FontAsset.GetCharactersArray(m_fontAssetSelection)); } EditorGUIUtility.labelWidth = 120f; char character = Event.current.character; if ((character < '0' || character > '9') && (character < 'a' || character > 'f') && (character < 'A' || character > 'F') && (character < ',' || character > '-')) { Event.current.character = '\0'; } GUILayout.Label("Character Sequence (Hex)", TMP_UIStyleManager.Section_Label); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120f), GUILayout.MaxWidth(290f)); EditorGUILayout.EndVertical(); break; } case 7: EditorGUILayout.BeginVertical(TMP_UIStyleManager.TextureAreaBox); GUILayout.Label("Type the characters to be included in the font asset or retrieve them from another font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); m_fontAssetSelection = (EditorGUILayout.ObjectField("Select Font Asset", m_fontAssetSelection, typeof(TMP_FontAsset), false, GUILayout.Width(290f)) as TMP_FontAsset); if ((EditorGUI.EndChangeCheck() || flag) && m_fontAssetSelection != null) { characterSequence = TMP_FontAsset.GetCharacters(m_fontAssetSelection); } EditorGUIUtility.labelWidth = 120f; EditorGUI.indentLevel = 0; GUILayout.Label("Custom Character List", TMP_UIStyleManager.Section_Label); characterSequence = EditorGUILayout.TextArea(characterSequence, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Height(120f), GUILayout.MaxWidth(290f)); EditorGUILayout.EndVertical(); break; case 8: characterList = (EditorGUILayout.ObjectField("Character File", characterList, typeof(TextAsset), false, GUILayout.Width(290f)) as TextAsset); if (characterList != null) { characterSequence = characterList.text; } break; } EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 40f; GUILayout.BeginHorizontal(GUILayout.Width(290f)); font_style = (FaceStyles)(object)EditorGUILayout.EnumPopup("Font Style:", font_style, GUILayout.Width(225f)); font_style_mod = EditorGUILayout.IntField((int)font_style_mod); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); font_renderMode = (RenderModes)(object)EditorGUILayout.EnumPopup("Font Render Mode:", font_renderMode, GUILayout.Width(290f)); if (EditorGUI.EndChangeCheck()) { } includeKerningPairs = EditorGUILayout.Toggle("Get Kerning Pairs?", includeKerningPairs, GUILayout.MaxWidth(290f)); EditorGUIUtility.labelWidth = 120f; EditorGUIUtility.fieldWidth = 160f; GUILayout.Space(20f); GUI.enabled = ((!(font_TTF == null) && !isProcessing) ? true : false); if (GUILayout.Button("Generate Font Atlas", GUILayout.Width(290f)) && characterSequence.Length != 0 && GUI.enabled && font_TTF != null) { int error_Code = TMPro_FontPlugin.Initialize_FontEngine(); if (error_Code != 0) { if (error_Code == 99) { error_Code = 0; } else { Debug.Log("Error Code: " + error_Code + " occurred while Initializing the FreeType Library."); } } string assetPath = AssetDatabase.GetAssetPath(font_TTF); if (error_Code == 0) { error_Code = TMPro_FontPlugin.Load_TrueType_Font(assetPath); if (error_Code != 0) { if (error_Code == 99) { error_Code = 0; } else { Debug.Log("Error Code: " + error_Code + " occurred while Loading the font."); } } } if (error_Code == 0) { if (FontSizingOption_Selection == 0) { font_size = 72; } error_Code = TMPro_FontPlugin.FT_Size_Font(font_size); if (error_Code != 0) { Debug.Log("Error Code: " + error_Code + " occurred while Sizing the font."); } } if (error_Code == 0) { int[] character_Set = null; if (font_CharacterSet_Selection == 7 || font_CharacterSet_Selection == 8) { List <int> list = new List <int>(); int i; for (i = 0; i < characterSequence.Length; i++) { if (list.FindIndex((int item) => item == characterSequence[i]) == -1) { list.Add(characterSequence[i]); } } character_Set = list.ToArray(); } else if (font_CharacterSet_Selection == 6) { character_Set = ParseHexNumberSequence(characterSequence); } else { character_Set = ParseNumberSequence(characterSequence); } m_character_Count = character_Set.Length; m_texture_buffer = new byte[font_atlas_width * font_atlas_height]; m_font_faceInfo = default(FT_FaceInfo); m_font_glyphInfo = new FT_GlyphInfo[m_character_Count]; int padding = font_padding; bool autoSizing = (FontSizingOption_Selection == 0) ? true : false; float strokeSize = font_style_mod; if (font_renderMode == RenderModes.DistanceField16) { strokeSize = font_style_mod * 16f; } if (font_renderMode == RenderModes.DistanceField32) { strokeSize = font_style_mod * 32f; } isProcessing = true; ThreadPool.QueueUserWorkItem(delegate { isRenderingDone = false; error_Code = TMPro_FontPlugin.Render_Characters(m_texture_buffer, font_atlas_width, font_atlas_height, padding, character_Set, m_character_Count, font_style, strokeSize, autoSizing, font_renderMode, (int)m_fontPackingSelection, ref m_font_faceInfo, m_font_glyphInfo); isRenderingDone = true; }); previewSelection = PreviewSelectionTypes.PreviewFont; } } GUILayout.Space(1f); progressRect = GUILayoutUtility.GetRect(288f, 20f, TMP_UIStyleManager.TextAreaBoxWindow, GUILayout.Width(288f), GUILayout.Height(20f)); GUI.BeginGroup(progressRect); GUI.DrawTextureWithTexCoords(new Rect(2f, 0f, 288f, 20f), TMP_UIStyleManager.progressTexture, new Rect(1f - m_renderingProgress, 0f, 1f, 1f)); GUI.EndGroup(); GUISkin skin = GUI.skin; GUI.skin = TMP_UIStyleManager.TMP_GUISkin; GUILayout.Space(5f); GUILayout.BeginVertical(TMP_UIStyleManager.TextAreaBoxWindow); output_ScrollPosition = EditorGUILayout.BeginScrollView(output_ScrollPosition, GUILayout.Height(145f)); EditorGUILayout.LabelField(output_feedback, TMP_UIStyleManager.Label); EditorGUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.skin = skin; GUILayout.Space(10f); GUI.enabled = ((m_font_Atlas != null) ? true : false); if (GUILayout.Button("Save TextMeshPro Font Asset", GUILayout.Width(290f)) && GUI.enabled) { string empty = string.Empty; if (font_renderMode < RenderModes.DistanceField16) { empty = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name, "asset"); if (empty.Length == 0) { return; } Save_Normal_FontAsset(empty); } else if (font_renderMode >= RenderModes.DistanceField16) { empty = EditorUtility.SaveFilePanel("Save TextMesh Pro! Font Asset File", new FileInfo(AssetDatabase.GetAssetPath(font_TTF)).DirectoryName, font_TTF.name + " SDF", "asset"); if (empty.Length == 0) { return; } Save_SDF_FontAsset(empty); } } GUI.enabled = true; GUILayout.Space(5f); GUILayout.EndVertical(); GUILayout.Space(25f); Rect controlRect = EditorGUILayout.GetControlRect(false, 5f); if (Event.current.type == EventType.Repaint) { m_UI_Panel_Size = controlRect; } GUILayout.EndVertical(); }
public override void OnInspectorGUI() { Event current = Event.current; base.serializedObject.Update(); GUILayout.Label("<b>TextMesh Pro! Font Asset</b>", TMP_UIStyleManager.Section_Label); GUILayout.Label("Face Info", TMP_UIStyleManager.Section_Label); EditorGUI.indentLevel = 1; GUI.enabled = false; float labelWidth = EditorGUIUtility.labelWidth = 150f; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Name"), new GUIContent("Font Source")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("PointSize")); GUI.enabled = true; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Scale")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("LineHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Ascender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("CapHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Baseline")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Descender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Underline"), new GUIContent("Underline Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("strikethrough"), new GUIContent("Strikethrough Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SuperscriptOffset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SubscriptOffset")); SerializedProperty serializedProperty = m_fontInfo_prop.FindPropertyRelative("SubSize"); EditorGUILayout.PropertyField(serializedProperty, new GUIContent("Super / Subscript Size")); serializedProperty.floatValue = Mathf.Clamp(serializedProperty.floatValue, 0.25f, 1f); GUI.enabled = false; EditorGUI.indentLevel = 1; GUILayout.Space(18f); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasWidth"), new GUIContent("Width")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasHeight"), new GUIContent("Height")); GUI.enabled = true; EditorGUI.indentLevel = 0; GUILayout.Space(20f); GUILayout.Label("Font Sub-Assets", TMP_UIStyleManager.Section_Label); GUI.enabled = false; EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(font_atlas_prop, new GUIContent("Font Atlas:")); EditorGUILayout.PropertyField(font_material_prop, new GUIContent("Font Material:")); GUI.enabled = true; string commandName = Event.current.commandName; EditorGUI.indentLevel = 0; if (GUILayout.Button("Font Weights\t" + (UI_PanelState.fontWeightPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fontWeightPanel = !UI_PanelState.fontWeightPanel; } if (UI_PanelState.fontWeightPanel) { EditorGUIUtility.labelWidth = 120f; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Font Assets that will be used for the following font weights.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); GUILayout.Label("<b>Font Weight</b>", TMP_UIStyleManager.Label, GUILayout.Width(117f)); GUILayout.Label("<b>Normal Style</b>", TMP_UIStyleManager.Label); GUILayout.Label("<b>Italic Style</b>", TMP_UIStyleManager.Label); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(4), new GUIContent("400 - Regular")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(7), new GUIContent("700 - Bold")); EditorGUILayout.EndVertical(); EditorGUIUtility.labelWidth = 120f; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); GUILayout.Label("Settings used to simulate a typeface when no font asset is available.", TMP_UIStyleManager.Label); GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalStyle_prop, new GUIContent("Normal Weight")); font_normalStyle_prop.floatValue = Mathf.Clamp(font_normalStyle_prop.floatValue, -3f, 3f); if (GUI.changed || commandName == "UndoRedoPerformed") { GUI.changed = false; for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightNormal", font_normalStyle_prop.floatValue); } } EditorGUILayout.PropertyField(font_boldStyle_prop, new GUIContent("Bold Weight"), GUILayout.MinWidth(100f)); font_boldStyle_prop.floatValue = Mathf.Clamp(font_boldStyle_prop.floatValue, -3f, 3f); if (GUI.changed || commandName == "UndoRedoPerformed") { GUI.changed = false; for (int j = 0; j < m_materialPresets.Length; j++) { m_materialPresets[j].SetFloat("_WeightBold", font_boldStyle_prop.floatValue); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalSpacing_prop, new GUIContent("Spacing Offset")); font_normalSpacing_prop.floatValue = Mathf.Clamp(font_normalSpacing_prop.floatValue, -100f, 100f); if (GUI.changed || commandName == "UndoRedoPerformed") { GUI.changed = false; } EditorGUILayout.PropertyField(font_boldSpacing_prop, new GUIContent("Bold Spacing")); font_boldSpacing_prop.floatValue = Mathf.Clamp(font_boldSpacing_prop.floatValue, 0f, 100f); if (GUI.changed || commandName == "UndoRedoPerformed") { GUI.changed = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Style: ")); font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60); EditorGUILayout.PropertyField(font_tabSize_prop, new GUIContent("Tab Multiple: ")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } GUILayout.Space(5f); EditorGUI.indentLevel = 0; if (GUILayout.Button("Fallback Font Assets\t" + (UI_PanelState.fallbackFontAssetPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fallbackFontAssetPanel = !UI_PanelState.fallbackFontAssetPanel; } if (UI_PanelState.fallbackFontAssetPanel) { EditorGUIUtility.labelWidth = 120f; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Font Assets that will be searched and used as fallback when characters are missing from this font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); m_list.DoLayoutList(); EditorGUILayout.EndVertical(); } EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; GUILayout.Space(5f); EditorGUI.indentLevel = 0; if (GUILayout.Button("Glyph Info\t" + (UI_PanelState.glyphInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.glyphInfoPanel = !UI_PanelState.glyphInfoPanel; } if (UI_PanelState.glyphInfoPanel) { int num2 = m_glyphInfoList_prop.arraySize; int num3 = 15; EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.ExpandWidth(true)); EditorGUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string text = EditorGUILayout.TextField("Glyph Search", m_searchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (!string.IsNullOrEmpty(text)) { m_searchPattern = text; SearchGlyphTable(m_searchPattern, ref m_searchList); } m_isSearchDirty = false; } string str = string.IsNullOrEmpty(m_searchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, str)) { GUIUtility.keyboardControl = 0; m_searchPattern = string.Empty; } EditorGUILayout.EndHorizontal(); if (!string.IsNullOrEmpty(m_searchPattern)) { num2 = m_searchList.Count; } DisplayGlyphPageNavigation(num2, num3); EditorGUILayout.EndVertical(); if (num2 > 0) { for (int k = num3 * m_GlyphPage; k < num2 && k < num3 * (m_GlyphPage + 1); k++) { Rect rect = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int num4 = k; if (!string.IsNullOrEmpty(m_searchPattern)) { num4 = m_searchList[k]; } SerializedProperty arrayElementAtIndex = m_glyphInfoList_prop.GetArrayElementAtIndex(num4); EditorGUI.BeginDisabledGroup(k != m_selectedElement); EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label); EditorGUILayout.PropertyField(arrayElementAtIndex); EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); Rect rect2 = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); Rect rect3 = new Rect(rect.x, rect.y, rect2.width, rect2.y - rect.y); if (DoSelectionCheck(rect3)) { m_selectedElement = k; m_AddGlyphWarning.isEnabled = false; m_unicodeHexLabel = "<i>Unicode Hex ID</i>"; GUIUtility.keyboardControl = 0; } if (m_selectedElement != k) { continue; } TMP_EditorUtility.DrawBox(rect3, 2f, new Color32(40, 192, byte.MaxValue, byte.MaxValue)); Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float num5 = controlRect.width * 0.6f; float num6 = num5 / 3f; Rect position = new Rect(controlRect.x + controlRect.width * 0.4f, controlRect.y, num6, controlRect.height); GUI.enabled = !string.IsNullOrEmpty(m_dstGlyphID); if (GUI.Button(position, new GUIContent("Copy to"))) { GUIUtility.keyboardControl = 0; int dstGlyphID = TMP_TextUtilities.StringToInt(m_dstGlyphID); if (!AddNewGlyph(num4, dstGlyphID)) { m_AddGlyphWarning.isEnabled = true; m_AddGlyphWarning.expirationTime = EditorApplication.timeSinceStartup + 1.0; } m_dstGlyphID = string.Empty; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); } GUI.enabled = true; position.x += num6; GUI.SetNextControlName("GlyphID_Input"); m_dstGlyphID = EditorGUI.TextField(position, m_dstGlyphID); EditorGUI.LabelField(position, new GUIContent(m_unicodeHexLabel, "The Unicode (Hex) ID of the duplicated Glyph"), TMP_UIStyleManager.Label); if (GUI.GetNameOfFocusedControl() == "GlyphID_Input") { m_unicodeHexLabel = string.Empty; char character = Event.current.character; if ((character < '0' || character > '9') && (character < 'a' || character > 'f') && (character < 'A' || character > 'F')) { Event.current.character = '\0'; } } else { m_unicodeHexLabel = "<i>Unicode Hex ID</i>"; } position.x += num6; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; RemoveGlyphFromList(num4); m_selectedElement = -1; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); return; } if (m_AddGlyphWarning.isEnabled && EditorApplication.timeSinceStartup < m_AddGlyphWarning.expirationTime) { EditorGUILayout.HelpBox("The Destination Glyph ID already exists", MessageType.Warning); } } } DisplayGlyphPageNavigation(num2, num3); } GUILayout.Space(5f); if (GUILayout.Button("Kerning Table Info\t" + (UI_PanelState.kerningInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.kerningInfoPanel = !UI_PanelState.kerningInfoPanel; } if (UI_PanelState.kerningInfoPanel) { SerializedProperty serializedProperty2 = m_kerningInfo_prop.FindPropertyRelative("kerningPairs"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Left Char", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label("Right Char", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label("Offset Value", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label(GUIContent.none, GUILayout.Width(20f)); EditorGUILayout.EndHorizontal(); GUILayout.BeginVertical(TMP_UIStyleManager.TMP_GUISkin.label); int arraySize = serializedProperty2.arraySize; int num7 = 25; Rect rect4; if (arraySize > 0) { for (int l = num7 * m_KerningPage; l < arraySize && l < num7 * (m_KerningPage + 1); l++) { SerializedProperty arrayElementAtIndex2 = serializedProperty2.GetArrayElementAtIndex(l); rect4 = EditorGUILayout.BeginHorizontal(); EditorGUI.PropertyField(new Rect(rect4.x, rect4.y, rect4.width - 20f, rect4.height), arrayElementAtIndex2, GUIContent.none); if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { m_kerningTable.RemoveKerningPair(l); m_fontAsset.ReadFontDefinition(); base.serializedObject.Update(); isAssetDirty = true; break; } EditorGUILayout.EndHorizontal(); } } Rect controlRect2 = EditorGUILayout.GetControlRect(false, 20f); controlRect2.width /= 3f; int num8 = (!current.shift) ? 1 : 10; if (m_KerningPage > 0) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(controlRect2, "Previous Page")) { m_KerningPage -= num8; } GUI.enabled = true; controlRect2.x += controlRect2.width; int num9 = (int)((float)arraySize / (float)num7 + 0.999f); GUI.Label(controlRect2, "Page " + (m_KerningPage + 1) + " / " + num9, GUI.skin.button); controlRect2.x += controlRect2.width; if (num7 * (m_GlyphPage + 1) < arraySize) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(controlRect2, "Next Page")) { m_KerningPage += num8; } m_KerningPage = Mathf.Clamp(m_KerningPage, 0, arraySize / num7); GUILayout.EndVertical(); GUILayout.Space(10f); GUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); rect4 = EditorGUILayout.BeginHorizontal(); EditorGUI.PropertyField(new Rect(rect4.x, rect4.y, rect4.width - 20f, rect4.height), m_kerningPair_prop); GUILayout.Label(GUIContent.none, GUILayout.Height(19f)); EditorGUILayout.EndHorizontal(); GUILayout.Space(5f); if (GUILayout.Button("Add New Kerning Pair")) { int intValue = m_kerningPair_prop.FindPropertyRelative("AscII_Left").intValue; int intValue2 = m_kerningPair_prop.FindPropertyRelative("AscII_Right").intValue; float floatValue = m_kerningPair_prop.FindPropertyRelative("XadvanceOffset").floatValue; errorCode = m_kerningTable.AddKerningPair(intValue, intValue2, floatValue); if (errorCode != -1) { m_kerningTable.SortKerningPairs(); m_fontAsset.ReadFontDefinition(); base.serializedObject.Update(); isAssetDirty = true; } else { timeStamp = DateTime.Now.AddSeconds(5.0); } } if (errorCode == -1) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Kerning Pair already <color=#ffff00>exists!</color>", TMP_UIStyleManager.Label); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (DateTime.Now > timeStamp) { errorCode = 0; } } GUILayout.EndVertical(); } if (base.serializedObject.ApplyModifiedProperties() || commandName == "UndoRedoPerformed" || isAssetDirty) { TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); isAssetDirty = false; EditorUtility.SetDirty(base.target); } GUI.enabled = true; if (current.type == EventType.MouseDown && current.button == 0) { m_selectedElement = -1; } }
public override void OnInspectorGUI() { // Check Warnings //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; serializedObject.Update(); // TextMeshPro Font Info Panel Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, "Face Info", EditorStyles.boldLabel); rect.x += rect.width - 130f; rect.width = 130f; if (GUI.Button(rect, "Update Atlas Texture")) { TMPro_FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(target as TMP_FontAsset); } EditorGUI.indentLevel = 1; GUI.enabled = false; // Lock UI float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Name"), new GUIContent("Font Source")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("PointSize")); GUI.enabled = true; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Scale")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("LineHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Ascender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("CapHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Baseline")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Descender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Underline"), new GUIContent("Underline Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("strikethrough"), new GUIContent("Strikethrough Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SuperscriptOffset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SubscriptOffset")); SerializedProperty subSize_prop = m_fontInfo_prop.FindPropertyRelative("SubSize"); EditorGUILayout.PropertyField(subSize_prop, new GUIContent("Super / Subscript Size")); subSize_prop.floatValue = Mathf.Clamp(subSize_prop.floatValue, 0.25f, 1f); GUI.enabled = false; //EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); //GUILayout.label("Atlas Size"); EditorGUI.indentLevel = 1; EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasWidth"), new GUIContent("Width")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasHeight"), new GUIContent("Height")); GUI.enabled = true; EditorGUILayout.Space(); EditorGUI.indentLevel = 0; UI_PanelState.fontSubAssetsPanel = EditorGUILayout.Foldout(UI_PanelState.fontSubAssetsPanel, new GUIContent("Font Sub-Assets"), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.fontSubAssetsPanel) { GUI.enabled = false; EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(font_atlas_prop, new GUIContent("Font Atlas")); EditorGUILayout.PropertyField(font_material_prop, new GUIContent("Font Material")); GUI.enabled = true; EditorGUILayout.Space(); } string evt_cmd = Event.current.commandName; // Get Current Event CommandName to check for Undo Events // FONT SETTINGS EditorGUI.indentLevel = 0; UI_PanelState.fontWeightPanel = EditorGUILayout.Foldout(UI_PanelState.fontWeightPanel, new GUIContent("Font Weights", "The Font Assets that will be used for different font weights and the settings used to simulate a typeface when no asset is available."), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.fontWeightPanel) { EditorGUIUtility.labelWidth *= 0.75f; EditorGUIUtility.fieldWidth *= 0.25f; EditorGUILayout.BeginVertical(); EditorGUI.indentLevel = 1; rect = EditorGUILayout.GetControlRect(true); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f; GUI.Label(rect, "Normal Style", EditorStyles.boldLabel); rect.x += rect.width; GUI.Label(rect, "Italic Style", EditorStyles.boldLabel); EditorGUI.indentLevel = 1; //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(1), new GUIContent("100 - Thin")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(2), new GUIContent("200 - Extra-Light")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(3), new GUIContent("300 - Light")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(4), new GUIContent("400 - Regular")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(5), new GUIContent("500 - Medium")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(6), new GUIContent("600 - Demi-Bold")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(7), new GUIContent("700 - Bold")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(8), new GUIContent("800 - Heavy")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(9), new GUIContent("900 - Black")); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalStyle_prop, new GUIContent("Normal Weight")); font_normalStyle_prop.floatValue = Mathf.Clamp(font_normalStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightNormal", font_normalStyle_prop.floatValue); } } EditorGUILayout.PropertyField(font_boldStyle_prop, new GUIContent("Bold Weight")); font_boldStyle_prop.floatValue = Mathf.Clamp(font_boldStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightBold", font_boldStyle_prop.floatValue); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalSpacing_prop, new GUIContent("Spacing Offset")); font_normalSpacing_prop.floatValue = Mathf.Clamp(font_normalSpacing_prop.floatValue, -100, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.PropertyField(font_boldSpacing_prop, new GUIContent("Bold Spacing")); font_boldSpacing_prop.floatValue = Mathf.Clamp(font_boldSpacing_prop.floatValue, 0, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Style")); font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60); EditorGUILayout.PropertyField(font_tabSize_prop, new GUIContent("Tab Multiple")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } EditorGUIUtility.labelWidth = 0; EditorGUIUtility.fieldWidth = 0; // FALLBACK FONT ASSETS EditorGUI.indentLevel = 0; UI_PanelState.fallbackFontAssetPanel = EditorGUILayout.Foldout(UI_PanelState.fallbackFontAssetPanel, new GUIContent("Fallback Font Assets", "Select the Font Assets that will be searched and used as fallback when characters are missing from this font asset."), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.fallbackFontAssetPanel) { EditorGUIUtility.labelWidth = 120; EditorGUI.indentLevel = 0; m_list.DoLayoutList(); EditorGUILayout.Space(); } // GLYPH INFO TABLE #region Glyph Table EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; EditorGUI.indentLevel = 0; UI_PanelState.glyphInfoPanel = EditorGUILayout.Foldout(UI_PanelState.glyphInfoPanel, new GUIContent("Glyph Table"), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.glyphInfoPanel) { int arraySize = m_glyphInfoList_prop.arraySize; int itemsPerPage = 15; // Display Glyph Management Tools EditorGUILayout.BeginVertical(EditorStyles.helpBox); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 130f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Glyph Search", m_GlyphSearchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { m_GlyphSearchPattern = searchPattern; // Search Glyph Table for potential matches SearchGlyphTable(m_GlyphSearchPattern, ref m_GlyphSearchList); } else { m_GlyphSearchPattern = null; } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_GlyphSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_GlyphSearchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_GlyphSearchPattern)) { arraySize = m_GlyphSearchList.Count; } DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); // Display Glyph Table Elements if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_CurrentGlyphPage; i < arraySize && i < itemsPerPage * (m_CurrentGlyphPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_GlyphSearchPattern)) { elementIndex = m_GlyphSearchList[i]; } SerializedProperty glyphInfo = m_glyphInfoList_prop.GetArrayElementAtIndex(elementIndex); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.BeginDisabledGroup(i != m_SelectedGlyphRecord); { EditorGUILayout.PropertyField(glyphInfo); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedGlyphRecord == i) { m_SelectedGlyphRecord = -1; } else { m_SelectedGlyphRecord = i; m_AddGlyphWarning.isEnabled = false; m_unicodeHexLabel = k_placeholderUnicodeHex; GUIUtility.keyboardControl = 0; } } // Draw Selection Highlight and Glyph Options if (m_SelectedGlyphRecord == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw Glyph management options Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float optionAreaWidth = controlRect.width * 0.6f; float btnWidth = optionAreaWidth / 3; Rect position = new Rect(controlRect.x + controlRect.width * .4f, controlRect.y, btnWidth, controlRect.height); // Copy Selected Glyph to Target Glyph ID GUI.enabled = !string.IsNullOrEmpty(m_dstGlyphID); if (GUI.Button(position, new GUIContent("Copy to"))) { GUIUtility.keyboardControl = 0; // Convert Hex Value to Decimal int dstGlyphID = TMP_TextUtilities.StringToInt(m_dstGlyphID); //Add new glyph at target Unicode hex id. if (!AddNewGlyph(elementIndex, dstGlyphID)) { m_AddGlyphWarning.isEnabled = true; m_AddGlyphWarning.expirationTime = EditorApplication.timeSinceStartup + 1; } m_dstGlyphID = string.Empty; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); } // Target Glyph ID GUI.enabled = true; position.x += btnWidth; GUI.SetNextControlName("GlyphID_Input"); m_dstGlyphID = EditorGUI.TextField(position, m_dstGlyphID); // Placeholder text EditorGUI.LabelField(position, new GUIContent(m_unicodeHexLabel, "The Unicode (Hex) ID of the duplicated Glyph"), TMP_UIStyleManager.label); // Only filter the input when the destination glyph ID text field has focus. if (GUI.GetNameOfFocusedControl() == "GlyphID_Input") { m_unicodeHexLabel = string.Empty; //Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F')) { Event.current.character = '\0'; } } else { m_unicodeHexLabel = k_placeholderUnicodeHex; } // Remove Glyph position.x += btnWidth; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; RemoveGlyphFromList(elementIndex); isAssetDirty = true; m_SelectedGlyphRecord = -1; m_isSearchDirty = true; break; } if (m_AddGlyphWarning.isEnabled && EditorApplication.timeSinceStartup < m_AddGlyphWarning.expirationTime) { EditorGUILayout.HelpBox("The Destination Glyph ID already exists", MessageType.Warning); } } } } DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage); EditorGUILayout.Space(); } #endregion // KERNING TABLE PANEL #region Kerning Table EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; EditorGUI.indentLevel = 0; UI_PanelState.kerningInfoPanel = EditorGUILayout.Foldout(UI_PanelState.kerningInfoPanel, new GUIContent("Glyph Adjustment Table"), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.kerningInfoPanel) { int arraySize = m_kerningPairs_prop.arraySize; int itemsPerPage = 20; // Display Kerning Pair Management Tools EditorGUILayout.BeginVertical(EditorStyles.helpBox); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 150f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Adjustment Pair Search", m_KerningTableSearchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { m_KerningTableSearchPattern = searchPattern; // Search Glyph Table for potential matches SearchKerningTable(m_KerningTableSearchPattern, ref m_KerningTableSearchList); } else { m_KerningTableSearchPattern = null; } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_KerningTableSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_KerningTableSearchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_KerningTableSearchPattern)) { arraySize = m_KerningTableSearchList.Count; } DisplayPageNavigation(ref m_CurrentKerningPage, arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); //Rect pos; //pos = EditorGUILayout.GetControlRect(false, 20); //pos.x += 5; //EditorGUI.LabelField(pos, "First Glyph", TMP_UIStyleManager.TMP_GUISkin.label); //pos.x += 100; //EditorGUI.LabelField(pos, "Adjustment Values", TMP_UIStyleManager.TMP_GUISkin.label); //pos.x = pos.width / 2 + 5; //EditorGUI.LabelField(pos, "Second Glyph", TMP_UIStyleManager.TMP_GUISkin.label); //pos.x += 100; //EditorGUI.LabelField(pos, "Adjustment Values", TMP_UIStyleManager.TMP_GUISkin.label); if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_CurrentKerningPage; i < arraySize && i < itemsPerPage * (m_CurrentKerningPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_KerningTableSearchPattern)) { elementIndex = m_KerningTableSearchList[i]; } SerializedProperty kerningInfo = m_kerningPairs_prop.GetArrayElementAtIndex(elementIndex); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.BeginDisabledGroup(i != m_SelectedAdjustmentRecord); { EditorGUILayout.PropertyField(kerningInfo, new GUIContent("Selectable")); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedAdjustmentRecord == i) { m_SelectedAdjustmentRecord = -1; } else { m_SelectedAdjustmentRecord = i; GUIUtility.keyboardControl = 0; } } // Draw Selection Highlight and Kerning Pair Options if (m_SelectedAdjustmentRecord == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw Glyph management options Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float optionAreaWidth = controlRect.width; float btnWidth = optionAreaWidth / 4; Rect position = new Rect(controlRect.x + controlRect.width - btnWidth, controlRect.y, btnWidth, controlRect.height); // Remove Kerning pair GUI.enabled = true; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; m_kerningTable.RemoveKerningPair(i); m_fontAsset.ReadFontDefinition(); isAssetDirty = true; m_SelectedAdjustmentRecord = -1; m_isSearchDirty = true; break; } } } } DisplayPageNavigation(ref m_CurrentKerningPage, arraySize, itemsPerPage); GUILayout.Space(5); // Add new kerning pair EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUILayout.PropertyField(m_kerningPair_prop); } EditorGUILayout.EndVertical(); if (GUILayout.Button("Add New Kerning Pair")) { int firstGlyph = m_kerningPair_prop.FindPropertyRelative("m_FirstGlyph").intValue; int secondGlyph = m_kerningPair_prop.FindPropertyRelative("m_SecondGlyph").intValue; GlyphValueRecord firstGlyphAdjustments = GetGlyphAdjustments(m_kerningPair_prop.FindPropertyRelative("m_FirstGlyphAdjustments")); GlyphValueRecord secondGlyphAdjustments = GetGlyphAdjustments(m_kerningPair_prop.FindPropertyRelative("m_SecondGlyphAdjustments")); errorCode = m_kerningTable.AddGlyphPairAdjustmentRecord((uint)firstGlyph, firstGlyphAdjustments, (uint)secondGlyph, secondGlyphAdjustments); // Sort Kerning Pairs & Reload Font Asset if new kerning pair was added. if (errorCode != -1) { m_kerningTable.SortKerningPairs(); m_fontAsset.ReadFontDefinition(); serializedObject.ApplyModifiedProperties(); isAssetDirty = true; m_isSearchDirty = true; } else { timeStamp = System.DateTime.Now.AddSeconds(5); } // Clear Add Kerning Pair Panel // TODO } if (errorCode == -1) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Kerning Pair already <color=#ffff00>exists!</color>", TMP_UIStyleManager.label); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (System.DateTime.Now > timeStamp) { errorCode = 0; } } } #endregion if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); isAssetDirty = false; EditorUtility.SetDirty(target); } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_SelectedAdjustmentRecord = -1; } }