Advertisement
Demigiant

UnityEditor: change Project/Inspector icon of given objects

Apr 24th, 2020
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1.         // If icon is NULL resets the objects to their default icon
  2.         static int SetObjectsIcons(List<Object> objects, Texture2D icon)
  3.         {
  4.             int totApplied = 0;
  5.             MethodInfo setIconForObject = typeof(EditorGUIUtility).GetMethod("SetIconForObject", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
  6.             MethodInfo getIconForObject = typeof(EditorGUIUtility).GetMethod("GetIconForObject", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
  7.             Assembly unityEditorAssembly = typeof(Editor).Assembly;
  8.             MethodInfo copyMonoScriptIconToImporters = unityEditorAssembly.GetType("UnityEditor.MonoImporter").GetMethod("CopyMonoScriptIconToImporters", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
  9.             foreach (Object obj in objects) {
  10.                 Texture2D currIcon = getIconForObject.Invoke(null, new object[] { obj }) as Texture2D;
  11.                 if (currIcon == icon) continue;
  12.                 totApplied++;
  13.                 setIconForObject.Invoke(null, new object[] { obj, icon });
  14.                 if (obj is MonoScript) copyMonoScriptIconToImporters.Invoke(null, new object[] { obj });
  15.             }
  16.             return totApplied;
  17.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement