Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Ink / Editor / Tools / File Icons / InkBrowserIcons.cs
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. /*
  5. * This script allows you to set custom icons for folders in project browser.
  6. * Recommended icon sizes - small: 16x16 px, large: 64x64 px;
  7. */
  8. namespace Ink.UnityIntegration {
  9. [InitializeOnLoad]
  10. public class InkBrowserIcons {
  11. private static bool isRetina {
  12. get {
  13. float unityVersion = float.Parse(Application.unityVersion.Substring (0, 3));
  14. return Application.platform == RuntimePlatform.OSXEditor && unityVersion >= 5.4f;
  15. }
  16. }
  17. private const float largeIconSize = 64f;
  18. private static Texture2D _inkFileIcon;
  19. public static Texture2D inkFileIcon {
  20. get {
  21. if(_inkFileIcon == null) {
  22. if(isRetina) {
  23. _inkFileIcon = Resources.Load<Texture2D>("InkFileIcon-retina");
  24. } else {
  25. _inkFileIcon = Resources.Load<Texture2D>("InkFileIcon");
  26. }
  27. }
  28. return _inkFileIcon;
  29. }
  30. }
  31. private static Texture2D _inkFileIconLarge;
  32. public static Texture2D inkFileIconLarge {
  33. get {
  34. if(_inkFileIconLarge == null) {
  35. _inkFileIconLarge = Resources.Load<Texture2D>("InkFileIcon-large");
  36. }
  37. return _inkFileIconLarge;
  38. }
  39. }
  40. private static Texture2D _errorIcon;
  41. public static Texture2D errorIcon {
  42. get {
  43. if(_errorIcon == null) {
  44. _errorIcon = Resources.Load<Texture2D>("InkErrorIcon");
  45. }
  46. return _errorIcon;
  47. }
  48. }
  49. private static Texture2D _warningIcon;
  50. public static Texture2D warningIcon {
  51. get {
  52. if(_warningIcon == null) {
  53. _warningIcon = Resources.Load<Texture2D>("InkWarningIcon");
  54. }
  55. return _warningIcon;
  56. }
  57. }
  58. private static Texture2D _todoIcon;
  59. public static Texture2D todoIcon {
  60. get {
  61. if(_todoIcon == null) {
  62. _todoIcon = Resources.Load<Texture2D>("InkTodoIcon");
  63. }
  64. return _todoIcon;
  65. }
  66. }
  67. private static Texture2D _manualIcon;
  68. public static Texture2D manualIcon {
  69. get {
  70. if(_manualIcon == null) {
  71. _manualIcon = Resources.Load<Texture2D>("InkCompileManualIcon");
  72. }
  73. return _manualIcon;
  74. }
  75. }
  76. private static Texture2D _childIcon;
  77. public static Texture2D childIcon {
  78. get {
  79. if(_childIcon == null) {
  80. _childIcon = Resources.Load<Texture2D>("InkChildIcon");
  81. }
  82. return _childIcon;
  83. }
  84. }
  85. private static Texture2D _childIconLarge;
  86. public static Texture2D childIconLarge {
  87. get {
  88. if(_childIconLarge == null) {
  89. _childIconLarge = Resources.Load<Texture2D>("InkChildIcon-Large");
  90. }
  91. return _childIconLarge;
  92. }
  93. }
  94. private static Texture2D _unknownFileIcon;
  95. public static Texture2D unknownFileIcon {
  96. get {
  97. if(_unknownFileIcon == null) {
  98. _unknownFileIcon = Resources.Load<Texture2D>("InkUnknownFileIcon");
  99. }
  100. return _unknownFileIcon;
  101. }
  102. }
  103. static InkBrowserIcons() {
  104. EditorApplication.projectWindowItemOnGUI += OnDrawProjectWindowItem;
  105. }
  106. static void OnDrawProjectWindowItem(string guid, Rect rect) {
  107. string path = AssetDatabase.GUIDToAssetPath(guid);
  108. if (InkEditorUtils.IsInkFile(path)) {
  109. DefaultAsset asset = AssetDatabase.LoadAssetAtPath<DefaultAsset>(path);
  110. DrawInkFile(InkLibrary.GetInkFileWithFile(asset), rect);
  111. }
  112. }
  113. static void DrawInkFile (InkFile inkFile, Rect rect) {
  114. bool isSmall = rect.width > rect.height;
  115. if (isSmall) {
  116. rect.width = rect.height;
  117. } else {
  118. rect.height = rect.width;
  119. }
  120. if (rect.width >= largeIconSize) {
  121. DrawLarge(inkFile, rect);
  122. } else {
  123. DrawSmall(inkFile, rect);
  124. }
  125. }
  126. static void DrawLarge (InkFile inkFile, Rect rect) {
  127. var offset = (rect.width - largeIconSize) * 0.5f;
  128. rect = new Rect(rect.x + offset, rect.y + offset, largeIconSize, largeIconSize);
  129. if(inkFileIconLarge != null)
  130. GUI.DrawTexture(rect, inkFileIconLarge);
  131. Rect miniRect = new Rect(rect.center, rect.size * 0.5f);
  132. if(inkFile == null) {
  133. if(unknownFileIcon != null) {
  134. GUI.DrawTexture(miniRect, unknownFileIcon);
  135. }
  136. } else {
  137. if(inkFile.hasErrors && errorIcon != null) {
  138. GUI.DrawTexture(miniRect, errorIcon);
  139. } else if(inkFile.hasWarnings && warningIcon != null) {
  140. GUI.DrawTexture(miniRect, warningIcon);
  141. } else if(inkFile.hasTodos && todoIcon != null) {
  142. GUI.DrawTexture(miniRect, todoIcon);
  143. }
  144. if(inkFile.isIncludeFile && childIcon != null) {
  145. GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width * 0.5f, rect.height * 0.5f), childIconLarge);
  146. }
  147. }
  148. }
  149. static void DrawSmall (InkFile inkFile, Rect rect) {
  150. if(inkFileIcon != null)
  151. GUI.DrawTexture(rect, inkFileIcon);
  152. if(inkFile == null) {
  153. if(unknownFileIcon != null) {
  154. GUI.DrawTexture(new Rect(rect.x, rect.y, unknownFileIcon.width, unknownFileIcon.height), unknownFileIcon);
  155. }
  156. } else {
  157. if (inkFile.isMaster) {
  158. if (!InkSettings.instance.ShouldCompileInkFileAutomatically(inkFile)) {
  159. GUI.DrawTexture(new Rect(rect.x, rect.y + rect.size.y * 0.5f, rect.size.x * 0.5f, rect.size.y * 0.5f), manualIcon);
  160. }
  161. Rect miniRect = new Rect(rect.center, rect.size * 0.5f);
  162. if(inkFile.hasErrors && errorIcon != null) {
  163. GUI.DrawTexture(miniRect, errorIcon);
  164. } else if(inkFile.hasWarnings && warningIcon != null) {
  165. GUI.DrawTexture(miniRect, warningIcon);
  166. } else if(inkFile.hasTodos && todoIcon != null) {
  167. GUI.DrawTexture(miniRect, todoIcon);
  168. }
  169. }
  170. if(inkFile.isIncludeFile && childIcon != null) {
  171. GUI.DrawTexture(new Rect(rect.x, rect.y, childIcon.width, childIcon.height), childIcon);
  172. }
  173. }
  174. }
  175. }
  176. }