AnimancerIcons.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Animancer.Editor
  6. {
  7. /// <summary>[Editor-Only] Icon textures used throughout Animancer.</summary>
  8. /// https://kybernetik.com.au/animancer/api/Animancer.Editor/AnimancerIcons
  9. public static class AnimancerIcons
  10. {
  11. /************************************************************************************************************************/
  12. /// <summary>A standard icon for information.</summary>
  13. public static readonly Texture Info = Load("console.infoicon");
  14. /// <summary>A standard icon for warnings.</summary>
  15. public static readonly Texture Warning = Load("console.warnicon");
  16. /// <summary>A standard icon for errors.</summary>
  17. public static readonly Texture Error = Load("console.erroricon");
  18. /************************************************************************************************************************/
  19. private static Texture _ScriptableObject;
  20. /// <summary>The icon for <see cref="UnityEngine.ScriptableObject"/>.</summary>
  21. public static Texture ScriptableObject
  22. {
  23. get
  24. {
  25. if (_ScriptableObject == null)
  26. {
  27. _ScriptableObject = Load("d_ScriptableObject Icon");
  28. if (_ScriptableObject == null)
  29. _ScriptableObject = AssetPreview.GetMiniTypeThumbnail(typeof(StringAsset));
  30. }
  31. return _ScriptableObject;
  32. }
  33. }
  34. /************************************************************************************************************************/
  35. /// <summary>Loads an icon texture.</summary>
  36. public static Texture Load(string name, FilterMode filterMode = FilterMode.Bilinear)
  37. {
  38. var icon = EditorGUIUtility.Load(name) as Texture;
  39. if (icon != null)
  40. icon.filterMode = filterMode;
  41. return icon;
  42. }
  43. /// <summary>Loads an icon `texture` if it was <c>null</c>.</summary>
  44. public static Texture Load(ref Texture texture, string name, FilterMode filterMode = FilterMode.Bilinear)
  45. => texture != null
  46. ? texture
  47. : texture = Load(name, filterMode);
  48. /************************************************************************************************************************/
  49. private static GUIContent
  50. _PlayIcon,
  51. _PauseIcon,
  52. _StepBackwardIcon,
  53. _StepForwardIcon,
  54. _AddIcon,
  55. _ClearIcon,
  56. _CopyIcon;
  57. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for a play button.</summary>
  58. public static GUIContent PlayIcon
  59. => IconContent(ref _PlayIcon, "PlayButton");
  60. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for a pause button.</summary>
  61. public static GUIContent PauseIcon
  62. => IconContent(ref _PauseIcon, "PauseButton");
  63. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for a step backward button.</summary>
  64. public static GUIContent StepBackwardIcon
  65. => IconContent(ref _StepBackwardIcon, "Animation.PrevKey");
  66. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for a step forward button.</summary>
  67. public static GUIContent StepForwardIcon
  68. => IconContent(ref _StepForwardIcon, "Animation.NextKey");
  69. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for an add button.</summary>
  70. public static GUIContent AddIcon(string tooltip = "Add")
  71. => IconContent(ref _AddIcon, "Toolbar Plus", tooltip);
  72. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for a clear button.</summary>
  73. public static GUIContent ClearIcon(string tooltip = "Clear")
  74. => IconContent(ref _ClearIcon, "Grid.EraserTool", tooltip);
  75. /// <summary><see cref="IconContent(ref GUIContent, string, string)"/> for a copy button.</summary>
  76. public static GUIContent CopyIcon(string tooltip = "Copy to clipboard")
  77. => IconContent(ref _CopyIcon, "UnityEditor.ConsoleWindow", tooltip);
  78. /************************************************************************************************************************/
  79. /// <summary>Calls <see cref="EditorGUIUtility.IconContent(string)"/> if the `content` was null.</summary>
  80. public static GUIContent IconContent(ref GUIContent content, string name, string tooltip = "")
  81. {
  82. content ??= EditorGUIUtility.IconContent(name);
  83. content.tooltip = tooltip;
  84. return content;
  85. }
  86. /************************************************************************************************************************/
  87. }
  88. }
  89. #endif