Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TMP_StyleAssetMenu.cs 1.5KB

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