TMP_StyleAssetMenu.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 + "/TMP StyleSheet.asset");
  30. //// Create new Style Sheet Asset.
  31. TMP_StyleSheet styleSheet = ScriptableObject.CreateInstance<TMP_StyleSheet>();
  32. AssetDatabase.CreateAsset(styleSheet, filePathWithName);
  33. EditorUtility.SetDirty(styleSheet);
  34. AssetDatabase.SaveAssets();
  35. }
  36. }
  37. }