TMP_StyleAssetMenu.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. using System.Collections;
  5. namespace TMPro.EditorUtilities
  6. {
  7. public static class TMP_StyleAssetMenu
  8. {
  9. [MenuItem("Assets/Create/TextMeshPro/Style Sheet", false, 120)]
  10. public static void CreateTextMeshProObjectPerform()
  11. {
  12. string filePath;
  13. if (Selection.assetGUIDs.Length == 0)
  14. {
  15. // No asset selected.
  16. filePath = "Assets";
  17. }
  18. else
  19. {
  20. // Get the path of the selected folder or asset.
  21. filePath = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
  22. // Get the file extension of the selected asset as it might need to be removed.
  23. string fileExtension = Path.GetExtension(filePath);
  24. if (fileExtension != "")
  25. {
  26. filePath = Path.GetDirectoryName(filePath);
  27. }
  28. }
  29. string filePathWithName = AssetDatabase.GenerateUniqueAssetPath(filePath + "/Text StyleSheet.asset");
  30. //// Create new Style Sheet Asset.
  31. TMP_StyleSheet styleSheet = ScriptableObject.CreateInstance<TMP_StyleSheet>();
  32. // Create Normal default style
  33. TMP_Style style = new TMP_Style("Normal", string.Empty, string.Empty);
  34. styleSheet.styles.Add(style);
  35. AssetDatabase.CreateAsset(styleSheet, filePathWithName);
  36. EditorUtility.SetDirty(styleSheet);
  37. AssetDatabase.SaveAssets();
  38. EditorUtility.FocusProjectWindow();
  39. EditorGUIUtility.PingObject(styleSheet);
  40. }
  41. }
  42. }