void OnEnable() { // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); // Get all serialized properties prop_isEnabled = serializedObject.FindProperty("m_isEnabled"); prop_propertiesChanged = serializedObject.FindProperty("propertiesChanged"); // Get the appropriate skin based on Dark or Light Unity Skin. if (EditorGUIUtility.isProSkin) { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin; } else { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin; } if (mySkin != null) { fieldLabel = mySkin.FindStyle("Section Label"); //textAreaBox = mySkin.FindStyle("Text Area Box (Editor)"); } }
public void OnEnable() { m_editorWindow = this; UpdateEditorWindowSize(768, 768); // Get the UI Skin and Styles for the various Editors TMP_UIStyleManager.GetUIStyles(); // Locate the plugin files & move them to root of project if that hasn't already been done. #if !UNITY_5 // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); string projectPath = Path.GetFullPath("Assets/.."); if (System.IO.File.Exists(projectPath + "/TMPro_Plugin.dll") == false) { FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dll", projectPath + "/TMPro_Plugin.dll"); // Copy the .dll FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dylib", projectPath + "/TMPro_Plugin.dylib"); // Copy Mac .dylib FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/vcomp120.dll", projectPath + "/vcomp120.dll"); // Copy OpemMP .dll } else // Check if we are using the latest versions { if (System.IO.File.GetLastWriteTime(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dylib") > System.IO.File.GetLastWriteTime(projectPath + "/TMPro_Plugin.dylib")) { FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dylib", projectPath + "/TMPro_Plugin.dylib"); } if (System.IO.File.GetLastWriteTime(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dll") > System.IO.File.GetLastWriteTime(projectPath + "/TMPro_Plugin.dll")) { FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dll", projectPath + "/TMPro_Plugin.dll"); } if (System.IO.File.GetLastWriteTime(tmproAssetFolderPath + "/Plugins/vcomp120.dll") > System.IO.File.GetLastWriteTime(projectPath + "/vcomp120.dll")) { FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/vcomp120.dll", projectPath + "/vcomp120.dll"); } } #endif // Add Event Listener related to Distance Field Atlas Creation. TMPro_EventManager.COMPUTE_DT_EVENT += ON_COMPUTE_DT_EVENT; // Debug Link to received message from Native Code //TMPro_FontPlugin.LinkDebugLog(); // Link with C++ Plugin to get Debug output }
public void OnEnable() { m_editorWindow = this; UpdateEditorWindowSize(768, 768); // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); if (EditorGUIUtility.isProSkin) { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin; progressTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/Progress Bar.psd", typeof(Texture2D)) as Texture2D; } else { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin; progressTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/Progress Bar (Light).psd", typeof(Texture2D)) as Texture2D; } if (mySkin != null) { SectionLabel = mySkin.FindStyle("Section Label"); textureAreaBox = mySkin.FindStyle("Texture Area Box"); textAreaBox = mySkin.FindStyle("Text Area Box (Window)"); } // Locate the plugin files & move them to root of project if that hasn't already been done. string projectPath = Path.GetFullPath("Assets/.."); if (System.IO.File.Exists(projectPath + "/TMPro_Plugin.dll") == false) { FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dll", projectPath + "/TMPro_Plugin.dll"); // Copy the .dll FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/TMPro_Plugin.dylib", projectPath + "/TMPro_Plugin.dylib"); // Copy Mac .dylib FileUtil.ReplaceFile(tmproAssetFolderPath + "/Plugins/vcomp120.dll", projectPath + "/vcomp120.dll"); // Copy OpemMP .dll } // Add Event Listener related to Distance Field Atlas Creation. TMPro_EventManager.COMPUTE_DT_EVENT += ON_COMPUTE_DT_EVENT; // Debug Link to received message from Native Code //TMPro_FontPlugin.LinkDebugLog(); // Link with C++ Plugin to get Debug output }
void OnEnable() { // Serialized Properties anchorPosition_prop = serializedObject.FindProperty("m_anchorPosition"); pivot_prop = serializedObject.FindProperty("m_pivot"); rectangle_prop = serializedObject.FindProperty("m_rect"); margins_prop = serializedObject.FindProperty("m_margins"); m_textContainer = (TextContainer)target; m_transform = Selection.activeGameObject.transform; // GUI SKINS // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); // GUI Skin if (EditorGUIUtility.isProSkin) { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin; } else { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin; } if (mySkin != null) { SectionLabel = mySkin.FindStyle("Section Label"); //GroupLabel = mySkin.FindStyle("Group Label"); //SquareAreaBox85G = mySkin.FindStyle("Square Area Box (85 Grey)"); } /* * if (m_visualHelper == null) * { * m_visualHelper = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; * m_visualHelper.localScale = new Vector3(0.25f, 0.25f, 0.25f); * } */ }
public void OnEnable() { font_atlas_prop = serializedObject.FindProperty("atlas"); font_material_prop = serializedObject.FindProperty("material"); font_normalStyle_prop = serializedObject.FindProperty("NormalStyle"); font_boldStyle_prop = serializedObject.FindProperty("BoldStyle"); font_italicStyle_prop = serializedObject.FindProperty("ItalicStyle"); 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_isGlyphInfoListExpanded_prop = serializedObject.FindProperty("isGlyphInfoListExpanded"); //m_isKerningTableExpanded_prop = serializedObject.FindProperty("isKerningTableExpanded"); m_fontAsset = target as TextMeshProFont; m_kerningTable = m_fontAsset.kerningInfo; // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); // GUI Skin if (EditorGUIUtility.isProSkin) { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin; } else { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin; } if (mySkin != null) { SectionLabel = mySkin.FindStyle("Section Label"); GroupLabel = mySkin.FindStyle("Group Label"); SquareAreaBox85G = mySkin.FindStyle("Square Area Box (85 Grey)"); } }
public override void OnInspectorGUI() { //Debug.Log("OnInspectorGUI Called."); serializedObject.Update(); GUILayout.Label("<b>TextMesh Pro! Font Asset</b>", SectionLabel); // TextMeshPro Font Info Panel GUILayout.Label("Face Info", SectionLabel); EditorGUI.indentLevel = 1; GUI.enabled = false; // Lock UI EditorGUIUtility.labelWidth = 135; //EditorGUIUtility.fieldWidth = 80; 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("LineHeight")); GUI.enabled = false; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Baseline")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Ascender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Descender")); GUI.enabled = true; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Underline")); //EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("UnderlineThickness")); 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("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", SectionLabel); 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; // Font SETTINGS GUILayout.Space(10); GUILayout.Label("Face Style", SectionLabel); string evt_cmd = Event.current.commandName; // Get Current Event CommandName to check for Undo Events 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; Material mat = font_material_prop.objectReferenceValue as Material; mat.SetFloat("_WeightNormal", font_normalStyle_prop.floatValue); } //Rect rect = EditorGUILayout.GetControlRect(); 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; Material mat = font_material_prop.objectReferenceValue as Material; mat.SetFloat("_WeightBold", font_boldStyle_prop.floatValue); } EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Style: ")); font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60); GUILayout.Space(10); EditorGUI.indentLevel = 0; if (GUILayout.Button("Glyph Info \t\t\t" + (UI_PanelState.glyphInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), SectionLabel)) { UI_PanelState.glyphInfoPanel = !UI_PanelState.glyphInfoPanel; } if (UI_PanelState.glyphInfoPanel) { if (m_glyphInfoList_prop.arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = 0; i < m_glyphInfoList_prop.arraySize; i++) { SerializedProperty glyphInfo = m_glyphInfoList_prop.GetArrayElementAtIndex(i); EditorGUILayout.BeginVertical(GroupLabel); EditorGUILayout.PropertyField(glyphInfo); EditorGUILayout.EndVertical(); } } } // KERNING TABLE PANEL if (GUILayout.Button("Kerning Table Info\t\t\t" + (UI_PanelState.kerningInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), SectionLabel)) { UI_PanelState.kerningInfoPanel = !UI_PanelState.kerningInfoPanel; } if (UI_PanelState.kerningInfoPanel) { Rect pos; SerializedProperty kerningPairs_prop = m_kerningInfo_prop.FindPropertyRelative("kerningPairs"); int pairCount = kerningPairs_prop.arraySize; EditorGUILayout.BeginHorizontal(); GUILayout.Label("Left Char", mySkin.label); GUILayout.Label("Right Char", mySkin.label); GUILayout.Label("Offset Value", mySkin.label); GUILayout.Label(GUIContent.none, GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); GUILayout.BeginVertical(mySkin.label); for (int i = 0; i < pairCount; 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(); } GUILayout.EndVertical(); GUILayout.Space(10); // Add New Kerning Pair Section GUILayout.BeginVertical(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 kerpair 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>", mySkin.label); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (System.DateTime.Now > timeStamp) { errorCode = 0; } } GUILayout.EndVertical(); } 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; TMPro_EditorUtility.RepaintAll(); // Consider SetDirty } }
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 = TMPro_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; 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; progressTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/Progress Bar.psd", typeof(Texture2D)) 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; 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; progressTexture = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/Textures/Progress Bar (Light).psd", typeof(Texture2D)) 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[] { new GUIContent(alignLeft, "Left"), new GUIContent(alignCenter, "Center"), new GUIContent(alignRight, "Right"), new GUIContent(alignJustified, "Justified") }; alignContent_B = new GUIContent[] { new GUIContent(alignTop, "Top"), new GUIContent(alignMiddle, "Middle"), new GUIContent(alignBottom, "Bottom"), new GUIContent(alignBaseline, "Baseline"), new GUIContent(alignMidline, "Midline") }; } //m_isInitialized = true; }
public void OnEnable() { //Debug.Log("New Instance of TMPRO UGUI Editor with ID " + this.GetInstanceID()); // Initialize the Event Listener for Undo Events. Undo.undoRedoPerformed += OnUndoRedo; //Undo.postprocessModifications += OnUndoRedoEvent; text_prop = serializedObject.FindProperty("m_text"); fontAsset_prop = serializedObject.FindProperty("m_fontAsset"); fontSharedMaterial_prop = serializedObject.FindProperty("m_sharedMaterial"); //fontBaseMaterial_prop = serializedObject.FindProperty("m_baseMaterial"); isNewBaseMaterial_prop = serializedObject.FindProperty("m_isNewBaseMaterial"); fontStyle_prop = serializedObject.FindProperty("m_fontStyle"); fontSize_prop = serializedObject.FindProperty("m_fontSize"); fontSizeBase_prop = serializedObject.FindProperty("m_fontSizeBase"); autoSizing_prop = serializedObject.FindProperty("m_enableAutoSizing"); fontSizeMin_prop = serializedObject.FindProperty("m_fontSizeMin"); fontSizeMax_prop = serializedObject.FindProperty("m_fontSizeMax"); charSpacingMax_prop = serializedObject.FindProperty("m_charSpacingMax"); lineSpacingMax_prop = serializedObject.FindProperty("m_lineSpacingMax"); // Colors & Gradient fontColor_prop = serializedObject.FindProperty("m_fontColor"); enableVertexGradient_prop = serializedObject.FindProperty("m_enableVertexGradient"); fontColorGradient_prop = serializedObject.FindProperty("m_fontColorGradient"); overrideHtmlColor_prop = serializedObject.FindProperty("m_overrideHtmlColors"); characterSpacing_prop = serializedObject.FindProperty("m_characterSpacing"); lineSpacing_prop = serializedObject.FindProperty("m_lineSpacing"); paragraphSpacing_prop = serializedObject.FindProperty("m_paragraphSpacing"); textAlignment_prop = serializedObject.FindProperty("m_textAlignment"); enableWordWrapping_prop = serializedObject.FindProperty("m_enableWordWrapping"); wordWrappingRatios_prop = serializedObject.FindProperty("m_wordWrappingRatios"); textOverflowMode_prop = serializedObject.FindProperty("m_overflowMode"); horizontalMapping_prop = serializedObject.FindProperty("m_horizontalMapping"); verticalMapping_prop = serializedObject.FindProperty("m_verticalMapping"); uvOffset_prop = serializedObject.FindProperty("m_uvOffset"); uvLineOffset_prop = serializedObject.FindProperty("m_uvLineOffset"); enableKerning_prop = serializedObject.FindProperty("m_enableKerning"); //isOrthographic_prop = serializedObject.FindProperty("m_isOrthographic"); havePropertiesChanged_prop = serializedObject.FindProperty("havePropertiesChanged"); inputSource_prop = serializedObject.FindProperty("m_inputSource"); isInputPasingRequired_prop = serializedObject.FindProperty("isInputParsingRequired"); //isAffectingWordWrapping_prop = serializedObject.FindProperty("isAffectingWordWrapping"); enableExtraPadding_prop = serializedObject.FindProperty("m_enableExtraPadding"); isRichText_prop = serializedObject.FindProperty("m_isRichText"); checkPaddingRequired_prop = serializedObject.FindProperty("checkPaddingRequired"); margin_prop = serializedObject.FindProperty("m_margin"); //isMaskUpdateRequired_prop = serializedObject.FindProperty("isMaskUpdateRequired"); //mask_prop = serializedObject.FindProperty("m_mask"); maskOffset_prop = serializedObject.FindProperty("m_maskOffset"); //maskOffsetMode_prop = serializedObject.FindProperty("m_maskOffsetMode"); //maskSoftness_prop = serializedObject.FindProperty("m_maskSoftness"); //vertexOffset_prop = serializedObject.FindProperty("m_vertexOffset"); //sortingLayerID_prop = serializedObject.FindProperty("m_sortingLayerID"); //sortingOrder_prop = serializedObject.FindProperty("m_sortingOrder"); hasFontAssetChanged_prop = serializedObject.FindProperty("hasFontAssetChanged"); // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); if (EditorGUIUtility.isProSkin) { mySkin = 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; 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; } else { mySkin = 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; 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; } if (mySkin != null) { Section_Label = mySkin.FindStyle("Section Label"); //Group_Label = mySkin.FindStyle("Group Label"); textAreaBox = mySkin.FindStyle("Text Area Box (Editor)"); alignContent_A = new GUIContent[] { new GUIContent(alignLeft, "Left"), new GUIContent(alignCenter, "Center"), new GUIContent(alignRight, "Right"), new GUIContent(alignJustified, "Justified") }; alignContent_B = new GUIContent[] { new GUIContent(alignTop, "Top"), new GUIContent(alignMiddle, "Middle"), new GUIContent(alignBottom, "Bottom") }; } m_textMeshProScript = (TextMeshProUGUI)target; m_rectTransform = Selection.activeGameObject.GetComponent <RectTransform>(); m_uiRenderer = Selection.activeGameObject.GetComponent <CanvasRenderer>(); // Add a Material Component if one does not exists /* * m_materialComponent = Selection.activeGameObject.GetComponent<MaterialComponent> (); * if (m_materialComponent == null) * { * m_materialComponent = Selection.activeGameObject.AddComponent<MaterialComponent> (); * } */ // Create new Material Editor if one does not exists if (m_uiRenderer != null && m_uiRenderer.GetMaterial() != null) { m_materialEditor = Editor.CreateEditor(m_uiRenderer.GetMaterial()); m_targetMaterial = m_uiRenderer.GetMaterial(); //Debug.Log("Currently Assigned Material is " + m_targetMaterial + ". Font Material is " + m_textMeshProScript.fontSharedMaterial); } //m_updateManager = Camera.main.gameObject.GetComponent<TMPro_UpdateManager>(); }
void Save_SDF_FontAsset(string filePath) { filePath = filePath.Substring(0, filePath.Length - 6); // Trim file extension from filePath. string dataPath = Application.dataPath; if (filePath.IndexOf(dataPath) == -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 relativeAssetPath = filePath.Substring(dataPath.Length - 6); string tex_DirName = Path.GetDirectoryName(relativeAssetPath); string tex_FileName = Path.GetFileNameWithoutExtension(relativeAssetPath); string tex_Path_NoExt = tex_DirName + "/" + tex_FileName; // Check if TextMeshPro font asset already exists. If not, create a new one. Otherwise update the existing one. TextMeshProFont font_asset = AssetDatabase.LoadAssetAtPath(tex_Path_NoExt + ".asset", typeof(TextMeshProFont)) as TextMeshProFont; if (font_asset == null) { //Debug.Log("Creating TextMeshPro font asset!"); font_asset = ScriptableObject.CreateInstance <TextMeshProFont>(); // Create new TextMeshPro Font Asset. AssetDatabase.CreateAsset(font_asset, tex_Path_NoExt + ".asset"); if (m_destination_Atlas != null) { m_font_Atlas = m_destination_Atlas; } // If using the C# SDF creation mode, we need the scaledown factor. int scaleDownFactor = font_renderMode >= RenderModes.DistanceField16 ? 1 : font_scaledownFactor; // Add FaceInfo to Font Asset FaceInfo face = GetFaceInfo(m_font_faceInfo, scaleDownFactor); font_asset.AddFaceInfo(face); // Add GlyphInfo[] to Font Asset GlyphInfo[] glyphs = GetGlyphInfo(m_font_glyphInfo, scaleDownFactor); font_asset.AddGlyphInfo(glyphs); // Get and Add Kerning Pairs to Font Asset if (includeKerningPairs) { string fontFilePath = AssetDatabase.GetAssetPath(font_TTF); KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize); font_asset.AddKerningInfo(kerningTable); } // Add Line Breaking Rules //LineBreakingTable lineBreakingTable = new LineBreakingTable(); // // Add Font Atlas as Sub-Asset font_asset.atlas = m_font_Atlas; m_font_Atlas.name = tex_FileName + " Atlas"; m_font_Atlas.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset); // Create new Material and Add it as Sub-Asset Shader default_Shader = Shader.Find("TMPro/Distance Field"); Material tmp_material = new Material(default_Shader); //tmp_material.shaderKeywords = new string[] { "BEVEL_OFF", "GLOW_OFF", "UNDERLAY_OFF" }; tmp_material.name = tex_FileName + " Material"; tmp_material.SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas); tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width); tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height); tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, font_asset.NormalStyle); tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, font_asset.BoldStyle); int spread = font_renderMode >= RenderModes.DistanceField16 ? font_padding + 1 : font_spread; tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, spread); // Spread = Padding for Brute Force SDF. font_asset.material = tmp_material; tmp_material.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(tmp_material, font_asset); } else { // Find all Materials referencing this font atlas. Material[] material_references = TMPro_EditorUtility.FindMaterialReferences(font_asset.material); // Destroy Assets that will be replaced. DestroyImmediate(font_asset.atlas, true); int scaleDownFactor = font_renderMode >= RenderModes.DistanceField16 ? 1 : font_scaledownFactor; // Add FaceInfo to Font Asset FaceInfo face = GetFaceInfo(m_font_faceInfo, scaleDownFactor); font_asset.AddFaceInfo(face); // Add GlyphInfo[] to Font Asset GlyphInfo[] glyphs = GetGlyphInfo(m_font_glyphInfo, scaleDownFactor); font_asset.AddGlyphInfo(glyphs); // Get and Add Kerning Pairs to Font Asset if (includeKerningPairs) { string fontFilePath = AssetDatabase.GetAssetPath(font_TTF); KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize); font_asset.AddKerningInfo(kerningTable); } // Add Font Atlas as Sub-Asset font_asset.atlas = m_font_Atlas; m_font_Atlas.name = tex_FileName + " Atlas"; m_font_Atlas.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset); // Update the Texture reference on the Material for (int i = 0; i < material_references.Length; i++) { material_references[i].SetTexture(ShaderUtilities.ID_MainTex, font_asset.atlas); material_references[i].SetFloat(ShaderUtilities.ID_TextureWidth, m_font_Atlas.width); material_references[i].SetFloat(ShaderUtilities.ID_TextureHeight, m_font_Atlas.height); material_references[i].SetFloat(ShaderUtilities.ID_WeightNormal, font_asset.NormalStyle); material_references[i].SetFloat(ShaderUtilities.ID_WeightBold, font_asset.BoldStyle); int spread = font_renderMode >= RenderModes.DistanceField16 ? font_padding + 1 : font_spread; material_references[i].SetFloat(ShaderUtilities.ID_GradientScale, spread); // Spread = Padding for Brute Force SDF. } } // Saving File for Debug //var pngData = destination_Atlas.EncodeToPNG(); //File.WriteAllBytes("Assets/Textures/Debug Distance Field.png", pngData); //font_asset.fontCreationSettings = SaveFontCreationSettings(); AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(font_asset)); // Re-import font asset to get the new updated version. font_asset.ReadFontDefinition(); AssetDatabase.Refresh(); // NEED TO GENERATE AN EVENT TO FORCE A REDRAW OF ANY TEXTMESHPRO INSTANCES THAT MIGHT BE USING THIS FONT ASSET TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, font_asset); }
void Save_Normal_FontAsset(string filePath) { filePath = filePath.Substring(0, filePath.Length - 6); // Trim file extension from filePath. string dataPath = Application.dataPath; if (filePath.IndexOf(dataPath) == -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 relativeAssetPath = filePath.Substring(dataPath.Length - 6); string tex_DirName = Path.GetDirectoryName(relativeAssetPath); string tex_FileName = Path.GetFileNameWithoutExtension(relativeAssetPath); string tex_Path_NoExt = tex_DirName + "/" + tex_FileName; // Check if TextMeshPro font asset already exists. If not, create a new one. Otherwise update the existing one. TextMeshProFont font_asset = AssetDatabase.LoadAssetAtPath(tex_Path_NoExt + ".asset", typeof(TextMeshProFont)) as TextMeshProFont; if (font_asset == null) { //Debug.Log("Creating TextMeshPro font asset!"); font_asset = ScriptableObject.CreateInstance <TextMeshProFont>(); // Create new TextMeshPro Font Asset. AssetDatabase.CreateAsset(font_asset, tex_Path_NoExt + ".asset"); // Add FaceInfo to Font Asset FaceInfo face = GetFaceInfo(m_font_faceInfo, 1); font_asset.AddFaceInfo(face); // Add GlyphInfo[] to Font Asset GlyphInfo[] glyphs = GetGlyphInfo(m_font_glyphInfo, 1); font_asset.AddGlyphInfo(glyphs); // Get and Add Kerning Pairs to Font Asset if (includeKerningPairs) { string fontFilePath = AssetDatabase.GetAssetPath(font_TTF); KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize); font_asset.AddKerningInfo(kerningTable); } // Add Font Atlas as Sub-Asset font_asset.atlas = m_font_Atlas; m_font_Atlas.name = tex_FileName + " Atlas"; m_font_Atlas.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset); // Create new Material and Add it as Sub-Asset Shader default_Shader = Shader.Find("TMPro/Bitmap"); Material tmp_material = new Material(default_Shader); tmp_material.name = tex_FileName + " Material"; tmp_material.SetTexture(ShaderUtilities.ID_MainTex, m_font_Atlas); font_asset.material = tmp_material; tmp_material.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(tmp_material, font_asset); } else { // Find all Materials referencing this font atlas. Material[] material_references = TMPro_EditorUtility.FindMaterialReferences(font_asset.material); // Destroy Assets that will be replaced. DestroyImmediate(font_asset.atlas, true); // Add FaceInfo to Font Asset FaceInfo face = GetFaceInfo(m_font_faceInfo, 1); font_asset.AddFaceInfo(face); // Add GlyphInfo[] to Font Asset GlyphInfo[] glyphs = GetGlyphInfo(m_font_glyphInfo, 1); font_asset.AddGlyphInfo(glyphs); // Get and Add Kerning Pairs to Font Asset if (includeKerningPairs) { string fontFilePath = AssetDatabase.GetAssetPath(font_TTF); KerningTable kerningTable = GetKerningTable(fontFilePath, (int)face.PointSize); font_asset.AddKerningInfo(kerningTable); } // Add Font Atlas as Sub-Asset font_asset.atlas = m_font_Atlas; m_font_Atlas.name = tex_FileName + " Atlas"; m_font_Atlas.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(m_font_Atlas, font_asset); // Update the Texture reference on the Material for (int i = 0; i < material_references.Length; i++) { material_references[i].SetTexture(ShaderUtilities.ID_MainTex, font_asset.atlas); } } AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(font_asset)); // Re-import font asset to get the new updated version. //EditorUtility.SetDirty(font_asset); font_asset.ReadFontDefinition(); AssetDatabase.Refresh(); // NEED TO GENERATE AN EVENT TO FORCE A REDRAW OF ANY TEXTMESHPRO INSTANCES THAT MIGHT BE USING THIS FONT ASSET TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, font_asset); }
public void OnEnable() { // Initialize the Event Listener for Undo Events. Undo.undoRedoPerformed += OnUndoRedo; //Undo.postprocessModifications += OnUndoRedoEvent; text_prop = serializedObject.FindProperty("m_text"); fontAsset_prop = serializedObject.FindProperty("m_fontAsset"); fontSize_prop = serializedObject.FindProperty("m_fontSize"); fontColor_prop = serializedObject.FindProperty("m_fontColor"); characterSpacing_prop = serializedObject.FindProperty("m_characterSpacing"); lineLength_prop = serializedObject.FindProperty("m_lineLength"); //textRectangle_prop = serializedObject.FindProperty("m_textRectangle"); lineSpacing_prop = serializedObject.FindProperty("m_lineSpacing"); lineJustification_prop = serializedObject.FindProperty("m_lineJustification"); anchorPosition_prop = serializedObject.FindProperty("m_anchor"); horizontalMapping_prop = serializedObject.FindProperty("m_horizontalMapping"); verticalMapping_prop = serializedObject.FindProperty("m_verticalMapping"); enableKerning_prop = serializedObject.FindProperty("m_enableKerning"); overrideHtmlColor_prop = serializedObject.FindProperty("m_overrideHtmlColors"); enableWordWrapping_prop = serializedObject.FindProperty("m_enableWordWrapping"); wordWrappingRatios_prop = serializedObject.FindProperty("m_wordWrappingRatios"); isOrthographic_prop = serializedObject.FindProperty("m_isOrthographic"); havePropertiesChanged_prop = serializedObject.FindProperty("havePropertiesChanged"); inputSource_prop = serializedObject.FindProperty("m_inputSource"); isInputPasingRequired_prop = serializedObject.FindProperty("isInputParsingRequired"); isAffectingWordWrapping_prop = serializedObject.FindProperty("isAffectingWordWrapping"); enableExtraPadding_prop = serializedObject.FindProperty("m_enableExtraPadding"); isRichText_prop = serializedObject.FindProperty("m_isRichText"); checkPaddingRequired_prop = serializedObject.FindProperty("checkPaddingRequired"); //isMaskUpdateRequired_prop = serializedObject.FindProperty("isMaskUpdateRequired"); //mask_prop = serializedObject.FindProperty("m_mask"); //maskOffset_prop= serializedObject.FindProperty("m_maskOffset"); //maskOffsetMode_prop = serializedObject.FindProperty("m_maskOffsetMode"); //maskSoftness_prop = serializedObject.FindProperty("m_maskSoftness"); //vertexOffset_prop = serializedObject.FindProperty("m_vertexOffset"); sortingLayerID_prop = serializedObject.FindProperty("m_sortingLayerID"); sortingOrder_prop = serializedObject.FindProperty("m_sortingOrder"); hasFontAssetChanged_prop = serializedObject.FindProperty("hasFontAssetChanged"); // Find to location of the TextMesh Pro Asset Folder (as users may have moved it) string tmproAssetFolderPath = TMPro_EditorUtility.GetAssetLocation(); if (EditorGUIUtility.isProSkin) { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_DarkSkin.guiskin", typeof(GUISkin)) as GUISkin; } else { mySkin = AssetDatabase.LoadAssetAtPath(tmproAssetFolderPath + "/GUISkins/TMPro_LightSkin.guiskin", typeof(GUISkin)) as GUISkin; } if (mySkin != null) { Section_Label = mySkin.FindStyle("Section Label"); //Group_Label = mySkin.FindStyle("Group Label"); textAreaBox = mySkin.FindStyle("Text Area Box (Editor)"); } m_textMeshProScript = (TextMeshPro)target; m_transform = Selection.activeGameObject.transform; m_renderer = Selection.activeGameObject.renderer; //m_updateManager = Camera.main.gameObject.GetComponent<TMPro_UpdateManager>(); }