MPEditorContents.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace MPUIKIT.Editor {
  5. [InitializeOnLoad]
  6. internal static class MPEditorContents {
  7. private static string _mpuiKitImagesDirectory = string.Empty;
  8. private static GUIContent _flipHorizontalNormal, _flipHorizontalActive;
  9. private static GUIContent _flipVerticalNormal, _flipVerticalActive;
  10. private static GUIContent _rotateLeftNormal, _rotateLeftActive;
  11. private static GUIContent _rotateRightNormal, _rotateRightActive;
  12. private static Texture2D _logo, _background, _title;
  13. public static GUIContent FlipHorizontalNormal {
  14. get {
  15. if (_flipHorizontalNormal != null) return _flipHorizontalNormal;
  16. _flipHorizontalNormal = new GUIContent(LoadImage("flip_h", false));
  17. return _flipHorizontalNormal;
  18. }
  19. }
  20. public static GUIContent FlipHorizontalActive {
  21. get {
  22. if (_flipHorizontalActive != null) return _flipHorizontalActive;
  23. _flipHorizontalActive = new GUIContent(LoadImage("flip_h", true));
  24. return _flipHorizontalActive;
  25. }
  26. }
  27. public static GUIContent FlipVerticalNormal {
  28. get {
  29. if (_flipVerticalNormal != null) return _flipVerticalNormal;
  30. _flipVerticalNormal = new GUIContent(LoadImage("flip_v", false));
  31. return _flipVerticalNormal;
  32. }
  33. }
  34. public static GUIContent FlipVerticalActive {
  35. get {
  36. if (_flipVerticalActive != null) return _flipVerticalActive;
  37. _flipVerticalActive = new GUIContent(LoadImage("flip_v", true));
  38. return _flipVerticalActive;
  39. }
  40. }
  41. public static GUIContent RotateLeftNormal {
  42. get {
  43. if (_rotateLeftNormal != null) return _rotateLeftNormal;
  44. _rotateLeftNormal = new GUIContent(LoadImage("rotate_left", false));
  45. return _rotateLeftNormal;
  46. }
  47. }
  48. public static GUIContent RotateLeftActive {
  49. get {
  50. if (_rotateLeftActive != null) return _rotateLeftActive;
  51. _rotateLeftActive = new GUIContent(LoadImage("rotate_left", true));
  52. return _rotateLeftActive;
  53. }
  54. }
  55. public static GUIContent RotateRightNormal {
  56. get {
  57. if (_rotateRightNormal != null) return _rotateRightNormal;
  58. _rotateRightNormal = new GUIContent(LoadImage("rotate_right", false));
  59. return _rotateRightNormal;
  60. }
  61. }
  62. public static GUIContent RotateRightActive {
  63. get {
  64. if (_rotateRightActive != null) return _rotateRightActive;
  65. _rotateRightActive = new GUIContent(LoadImage("rotate_right", true));
  66. return _rotateRightActive;
  67. }
  68. }
  69. public static Texture Logo {
  70. get {
  71. if (_logo != null) return _logo;
  72. _logo = LoadImage("logo", false, true);
  73. return _logo;
  74. }
  75. }
  76. public static Texture Background {
  77. get {
  78. if (_background != null) return _background;
  79. _background = LoadImage("background", false, true);
  80. return _background;
  81. }
  82. }
  83. public static Texture Title {
  84. get {
  85. if (_title != null) return _title;
  86. _title = LoadImage("title", false, true);
  87. return _title;
  88. }
  89. }
  90. static MPEditorContents() {
  91. FindMpuiKitIconsDirectory();
  92. }
  93. private static void FindMpuiKitIconsDirectory()
  94. {
  95. string rootDir = MPEditorUtility.FindMPUIKitRootDirectory();
  96. _mpuiKitImagesDirectory = string.IsNullOrEmpty(rootDir) ? string.Empty : Path.Combine(rootDir, "Editor", "Images");
  97. }
  98. private static Texture2D LoadImage(string name, bool activeState, bool ignoreState = false) {
  99. int colorLevel = 0;
  100. if (!ignoreState) {
  101. if (activeState) colorLevel = 3;
  102. else colorLevel = EditorGUIUtility.isProSkin ? 2 : 1;
  103. }
  104. if (_mpuiKitImagesDirectory == string.Empty) FindMpuiKitIconsDirectory();
  105. string assetPath = $"{_mpuiKitImagesDirectory}{Path.DirectorySeparatorChar}{name}{(ignoreState ? string.Empty : $"_{colorLevel}")}.png";
  106. return AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;
  107. }
  108. }
  109. }