4 using System.Collections.Generic;
7 #if ENABLE_WINMD_SUPPORT && !UNITY_EDITOR 19 private static float textureSize = 50f;
22 [Header(
"Navigation icons")]
33 [Header(
"Common action icons")]
44 [Header(
"Common notification icons")]
48 [Header(
"Common object icons")]
56 [Header(
"Common gesture icons")]
69 private bool initialized;
70 private List<string> iconKeys;
71 private Dictionary<string, Texture2D> iconLookup;
73 public override bool GetIcon(
string iconName, MeshRenderer targetRenderer, MeshFilter targetMesh,
bool useDefaultIfNotFound)
77 Texture2D icon = null;
78 if (useDefaultIfNotFound)
83 if (!
string.IsNullOrEmpty(iconName))
86 if (!iconLookup.TryGetValue(iconName, out icon))
87 if (useDefaultIfNotFound)
91 if (useDefaultIfNotFound)
96 targetMesh.sharedMesh = IconMesh;
97 targetMesh.transform.localScale = Vector3.one;
98 targetRenderer.sharedMaterial.mainTexture = icon;
109 return new List<string>(iconKeys);
112 private void Initialize()
114 if (iconLookup != null)
117 iconLookup =
new Dictionary<string, Texture2D>();
118 iconKeys =
new List<string>();
121 #if ENABLE_WINMD_SUPPORT && !UNITY_EDITOR 122 var fields = GetType().GetTypeInfo().DeclaredFields;
124 var fields = this.GetType().GetFields();
126 foreach (var field
in fields)
128 if (field.FieldType == typeof(Texture2D) && !field.Name.StartsWith(
"_"))
130 iconLookup.Add(field.Name, (Texture2D)field.GetValue(
this));
131 iconKeys.Add(field.Name);
136 foreach (Texture2D icon
in CustomIcons)
138 if (iconLookup.ContainsKey(icon.name))
140 iconLookup[icon.name] = icon;
144 iconLookup.Add(icon.name, icon);
145 iconKeys.Add(icon.name);
151 public override string DrawIconSelectField(
string iconName)
153 int selectedIconIndex = -1;
154 List<string> iconKeys = GetIconKeys();
155 for (
int i = 0; i < iconKeys.Count; i++)
157 if (iconName == iconKeys[i])
159 selectedIconIndex = i;
163 int newIconIndex =
UnityEditor.EditorGUILayout.Popup(
"Icon", selectedIconIndex, iconKeys.ToArray());
165 iconName = (newIconIndex < 0 ?
string.Empty : iconKeys[newIconIndex]);
170 public class CustomEditor : ProfileInspector
172 protected override void DrawCustomFooter()
177 for (
int i = 0; i < iconProfile.
CustomIcons.Length; i++)
180 icon = (Texture2D)
UnityEditor.EditorGUILayout.ObjectField(icon != null ? icon.name :
"(Empty)", icon, typeof(Texture2D),
false, GUILayout.MaxHeight(textureSize));
184 if (GUILayout.Button(
"Add custom icon"))
Texture2D KeyboardClassic
override bool GetIcon(string iconName, MeshRenderer targetRenderer, MeshFilter targetMesh, bool useDefaultIfNotFound)
Searches for an icon If found, the icon texture is applied to the target renderer's material and the ...
Texture2D OpenInNewWindow
Texture2D GlobalNavButton
Icon profile that returns textures
override List< string > GetIconKeys()
(Icons starting with '_' will not be included in icon list)