internal static void CreateTextMeshProObjectPerform() { string filePath; if (Selection.assetGUIDs.Length == 0) { // No asset selected. filePath = "Assets"; } else { // Get the path of the selected folder or asset. filePath = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]); // Get the file extension of the selected asset as it might need to be removed. string fileExtension = Path.GetExtension(filePath); if (fileExtension != "") { filePath = Path.GetDirectoryName(filePath); } } string filePathWithName = AssetDatabase.GenerateUniqueAssetPath(filePath + "/Text StyleSheet.asset"); // Create new Style Sheet Asset. TextStyleSheet styleSheet = ScriptableObject.CreateInstance <TextStyleSheet>(); // Create Normal default style TextStyle style = new TextStyle("Normal", string.Empty, string.Empty); styleSheet.styles.Add(style); AssetDatabase.CreateAsset(styleSheet, filePathWithName); EditorUtility.SetDirty(styleSheet); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); EditorGUIUtility.PingObject(styleSheet); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { SerializedProperty nameProperty = property.FindPropertyRelative("m_Name"); SerializedProperty hashCodeProperty = property.FindPropertyRelative("m_HashCode"); SerializedProperty openingDefinitionProperty = property.FindPropertyRelative("m_OpeningDefinition"); SerializedProperty closingDefinitionProperty = property.FindPropertyRelative("m_ClosingDefinition"); SerializedProperty openingDefinitionArray = property.FindPropertyRelative("m_OpeningTagArray"); SerializedProperty closingDefinitionArray = property.FindPropertyRelative("m_ClosingTagArray"); EditorGUIUtility.labelWidth = 86; position.height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; float labelHeight = position.height + 2f; EditorGUI.BeginChangeCheck(); Rect rect0 = new Rect(position.x, position.y, (position.width) / 2 + 5, position.height); EditorGUI.PropertyField(rect0, nameProperty); if (EditorGUI.EndChangeCheck()) { // Recompute HashCode if name has changed. hashCodeProperty.intValue = TextUtilities.GetHashCodeCaseInSensitive(nameProperty.stringValue); property.serializedObject.ApplyModifiedProperties(); // Dictionary needs to be updated since HashCode has changed. TextStyleSheet styleSheet = property.serializedObject.targetObject as TextStyleSheet; styleSheet.RefreshStyles(); } // HashCode Rect rect1 = new Rect(rect0.x + rect0.width + 5, position.y, 65, position.height); GUI.Label(rect1, "HashCode"); GUI.enabled = false; rect1.x += 65; rect1.width = position.width / 2 - 75; EditorGUI.PropertyField(rect1, hashCodeProperty, GUIContent.none); GUI.enabled = true; // Text Tags EditorGUI.BeginChangeCheck(); // Opening Tags position.y += labelHeight; GUI.Label(position, "Opening Tags"); Rect textRect1 = new Rect(110, position.y, position.width - 86, 35); openingDefinitionProperty.stringValue = EditorGUI.TextArea(textRect1, openingDefinitionProperty.stringValue); if (EditorGUI.EndChangeCheck()) { // If any properties have changed, we need to update the Opening and Closing Arrays. int size = openingDefinitionProperty.stringValue.Length; // Adjust array size to match new string length. if (openingDefinitionArray.arraySize != size) { openingDefinitionArray.arraySize = size; } for (int i = 0; i < size; i++) { SerializedProperty element = openingDefinitionArray.GetArrayElementAtIndex(i); element.intValue = openingDefinitionProperty.stringValue[i]; } } EditorGUI.BeginChangeCheck(); // Closing Tags position.y += 38; GUI.Label(position, "Closing Tags"); Rect textRect2 = new Rect(110, position.y, position.width - 86, 35); closingDefinitionProperty.stringValue = EditorGUI.TextArea(textRect2, closingDefinitionProperty.stringValue); if (EditorGUI.EndChangeCheck()) { // If any properties have changed, we need to update the Opening and Closing Arrays. int size = closingDefinitionProperty.stringValue.Length; // Adjust array size to match new string length. if (closingDefinitionArray.arraySize != size) { closingDefinitionArray.arraySize = size; } for (int i = 0; i < size; i++) { SerializedProperty element = closingDefinitionArray.GetArrayElementAtIndex(i); element.intValue = closingDefinitionProperty.stringValue[i]; } } }
public override void OnInspectorGUI() { serializedObject.Update(); string evt_cmd = Event.current.commandName; float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; // TextMeshPro Font Info Panel EditorGUI.indentLevel = 0; // FONT ASSET EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.defaultFontAssetLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(m_PropFontAsset, Styles.defaultFontAssetLabel); EditorGUILayout.PropertyField(m_PropDefaultFontAssetPath, Styles.defaultFontAssetPathLabel); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // FONT ASSET FALLBACK(s) EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.fallbackFontAssetsLabel, EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); m_FontAssetFallbackList.DoLayoutList(); if (EditorGUI.EndChangeCheck()) { TextResourceManager.RebuildFontAssetCache(); } GUILayout.Label(Styles.fallbackMaterialSettingsLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(m_PropMatchMaterialPreset, Styles.matchMaterialPresetLabel); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // MISSING GLYPHS EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.dynamicFontSystemSettingsLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; //EditorGUILayout.PropertyField(m_GetFontFeaturesAtRuntime, Styles.getFontFeaturesAtRuntime); EditorGUILayout.PropertyField(m_PropMissingGlyphCharacter, Styles.missingGlyphLabel); EditorGUILayout.PropertyField(m_PropClearDynamicDataOnBuild, Styles.clearDynamicDataOnBuildLabel); EditorGUILayout.PropertyField(m_PropDisplayWarnings, Styles.disableWarningsLabel); //EditorGUILayout.PropertyField(m_DynamicAtlasTextureManager, Styles.dynamicAtlasTextureManager); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // TEXT OBJECT DEFAULT PROPERTIES /* * EditorGUILayout.BeginVertical(EditorStyles.helpBox); * GUILayout.Label(Styles.containerDefaultSettingsLabel, EditorStyles.boldLabel); * EditorGUI.indentLevel = 1; * * EditorGUILayout.PropertyField(m_PropDefaultTextMeshProTextContainerSize, Styles.textMeshProLabel); * EditorGUILayout.PropertyField(m_PropDefaultTextMeshProUITextContainerSize, Styles.textMeshProUiLabel); * EditorGUILayout.PropertyField(m_PropEnableRaycastTarget, Styles.enableRaycastTarget); * EditorGUILayout.PropertyField(m_PropAutoSizeTextContainer, Styles.autoSizeContainerLabel); * EditorGUI.indentLevel = 0; * * EditorGUILayout.Space(); * * GUILayout.Label(Styles.textComponentDefaultSettingsLabel, EditorStyles.boldLabel); * EditorGUI.indentLevel = 1; * EditorGUILayout.PropertyField(m_PropDefaultFontSize, Styles.defaultFontSize); * * EditorGUILayout.BeginHorizontal(); * { * EditorGUILayout.PrefixLabel(Styles.autoSizeRatioLabel); * EditorGUIUtility.labelWidth = 32; * EditorGUIUtility.fieldWidth = 10; * * EditorGUI.indentLevel = 0; * EditorGUILayout.PropertyField(m_PropDefaultAutoSizeMinRatio, Styles.minLabel); * EditorGUILayout.PropertyField(m_PropDefaultAutoSizeMaxRatio, Styles.maxLabel); * EditorGUI.indentLevel = 1; * } * EditorGUILayout.EndHorizontal(); * * EditorGUIUtility.labelWidth = labelWidth; * EditorGUIUtility.fieldWidth = fieldWidth; * * EditorGUILayout.PropertyField(m_PropWordWrapping, Styles.wordWrappingLabel); * EditorGUILayout.PropertyField(m_PropKerning, Styles.kerningLabel); * * EditorGUILayout.PropertyField(m_PropExtraPadding, Styles.extraPaddingLabel); * EditorGUILayout.PropertyField(m_PropTintAllSprites, Styles.tintAllSpritesLabel); * * EditorGUILayout.PropertyField(m_PropParseEscapeCharacters, Styles.parseEscapeCharactersLabel); * * EditorGUI.indentLevel = 0; * * EditorGUILayout.Space(); * EditorGUILayout.EndVertical(); */ // SPRITE ASSET EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.defaultSpriteAssetLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(m_PropSpriteAsset, Styles.defaultSpriteAssetLabel); EditorGUILayout.PropertyField(m_PropMissingSpriteCharacterUnicode, Styles.missingSpriteCharacterUnicodeLabel); //EditorGUILayout.PropertyField(m_PropEnableEmojiSupport, Styles.enableEmojiSupportLabel); //EditorGUILayout.PropertyField(m_PropSpriteRelativeScaling, Styles.spriteRelativeScale); EditorGUILayout.PropertyField(m_PropSpriteAssetPath, Styles.spriteAssetsPathLabel); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // SPRITE ASSET FALLBACK(s) EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.fallbackSpriteAssetsLabel, EditorStyles.boldLabel); m_SpriteAssetFallbackList.DoLayoutList(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // STYLE SHEET EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.defaultStyleSheetLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_PropStyleSheet, Styles.defaultStyleSheetLabel); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); TextStyleSheet styleSheet = m_PropStyleSheet.objectReferenceValue as TextStyleSheet; if (styleSheet != null) { styleSheet.RefreshStyles(); } } EditorGUILayout.PropertyField(m_PropStyleSheetsResourcePath, Styles.styleSheetResourcePathLabel); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // COLOR GRADIENT PRESETS EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.colorGradientPresetsLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(m_PropColorGradientPresetsPath, Styles.colorGradientsPathLabel); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); // LINE BREAKING RULE EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label(Styles.lineBreakingLabel, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(m_PropUnicodeLineBreakingRules); //EditorGUILayout.Space(); //GUILayout.Label(Styles.koreanSpecificRules, EditorStyles.boldLabel); //EditorGUILayout.PropertyField(m_PropUseModernHangulLineBreakingRules, new GUIContent("Use Modern Line Breaking", "Determines if traditional or modern line breaking rules will be used to control line breaking. Traditional line breaking rules use the Leading and Following Character rules whereas Modern uses spaces for line breaking.")); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo) { EditorUtility.SetDirty(target); TextEventManager.ON_TMP_SETTINGS_CHANGED(); } }
void OnEnable() { m_StyleSheet = target as TextStyleSheet; m_StyleListProp = serializedObject.FindProperty("m_StyleList"); }