EditorTextures.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using UnityEngine;
  2. namespace SingularityGroup.HotReload.Editor {
  3. /// <summary>
  4. /// Create a new texture only once. Safe access to generated textures.
  5. /// </summary>
  6. /// <remarks>
  7. /// If </remarks>
  8. internal static class EditorTextures {
  9. private static Texture2D black;
  10. private static Texture2D white;
  11. private static Texture2D lightGray225;
  12. private static Texture2D lightGray235;
  13. private static Texture2D darkGray17;
  14. private static Texture2D darkGray30;
  15. // Texture2D.blackTexture doesn't render properly in Editor GUI.
  16. public static Texture2D Black {
  17. get {
  18. if (!black) {
  19. black = new Texture2D(2, 2, TextureFormat.RGBA32, false);
  20. var pixels = black.GetPixels32();
  21. for (var i = 0; i < pixels.Length; i++) {
  22. pixels[i] = new Color32(0, 0, 0, byte.MaxValue);
  23. }
  24. black.SetPixels32(pixels);
  25. black.Apply();
  26. }
  27. return black;
  28. }
  29. }
  30. // Texture2D.whiteTexture might not render properly in Editor GUI.
  31. public static Texture2D White {
  32. get {
  33. if (!white) {
  34. white = new Texture2D(2, 2, TextureFormat.RGBA32, false);
  35. var pixels = white.GetPixels32();
  36. for (var i = 0; i < pixels.Length; i++) {
  37. pixels[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
  38. }
  39. white.SetPixels32(pixels);
  40. white.Apply();
  41. }
  42. return white;
  43. }
  44. }
  45. public static Texture2D DarkGray17 {
  46. get {
  47. if (!darkGray17) {
  48. darkGray17 = new Texture2D(2, 2, TextureFormat.RGBA32, false);
  49. var pixels = darkGray17.GetPixels32();
  50. for (var i = 0; i < pixels.Length; i++) {
  51. pixels[i] = new Color32(17, 17, 17, byte.MaxValue);
  52. }
  53. darkGray17.SetPixels32(pixels);
  54. darkGray17.Apply();
  55. }
  56. return darkGray17;
  57. }
  58. }
  59. public static Texture2D DarkGray40 {
  60. get {
  61. if (!darkGray30) {
  62. darkGray30 = new Texture2D(2, 2, TextureFormat.RGBA32, false);
  63. var pixels = darkGray30.GetPixels32();
  64. for (var i = 0; i < pixels.Length; i++) {
  65. pixels[i] = new Color32(40, 40, 40, byte.MaxValue);
  66. }
  67. darkGray30.SetPixels32(pixels);
  68. darkGray30.Apply();
  69. }
  70. return darkGray30;
  71. }
  72. }
  73. public static Texture2D LightGray238 {
  74. get {
  75. if (!lightGray235) {
  76. lightGray235 = new Texture2D(2, 2, TextureFormat.RGBA32, false);
  77. var pixels = lightGray235.GetPixels32();
  78. for (var i = 0; i < pixels.Length; i++) {
  79. pixels[i] = new Color32(238, 238, 238, byte.MaxValue);
  80. }
  81. lightGray235.SetPixels32(pixels);
  82. lightGray235.Apply();
  83. }
  84. return lightGray235;
  85. }
  86. }
  87. public static Texture2D LightGray225 {
  88. get {
  89. if (!lightGray225) {
  90. lightGray225 = new Texture2D(2, 2, TextureFormat.RGBA32, false);
  91. var pixels = lightGray225.GetPixels32();
  92. for (var i = 0; i < pixels.Length; i++) {
  93. pixels[i] = new Color32(225, 225, 225, byte.MaxValue);
  94. }
  95. lightGray225.SetPixels32(pixels);
  96. lightGray225.Apply();
  97. }
  98. return lightGray225;
  99. }
  100. }
  101. }
  102. }