Created
August 21, 2019 06:13
-
-
Save nshelton/c1d6ee88e2b5376bf0cab1905b71e9b9 to your computer and use it in GitHub Desktop.
draw icons in the unity hierarchy view (put in your Editor folder)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
using System.Collections.Generic; | |
using UnityEngine.Tilemaps; | |
using UnityEngine.Timeline; | |
using UnityEngine.UI; | |
using UnityEngine.U2D; | |
using UnityEngine.Rendering; | |
using UnityEngine.Playables; | |
using UnityEngine.EventSystems; | |
using UnityEngine.Video; | |
using UnityEngine.Experimental.VFX; | |
using UnityEditor.Animations; | |
using UnityEngine.Animations; | |
[InitializeOnLoad] | |
class HierarchyIcons | |
{ | |
private static Dictionary<System.Type, string> m_iconPaths = new Dictionary<System.Type, string>() | |
{ | |
{typeof(GridBrush), "GridBrush Icon"}, | |
{typeof(Microphone), "Microphone Icon"}, | |
{typeof(AnimatorController), "AnimatorController Icon"}, | |
{typeof(AnimatorState), "AnimatorState Icon"}, | |
{typeof(AnimatorStateMachine), "AnimatorStateMachine Icon"}, | |
{typeof(AnimatorStateTransition), "AnimatorStateTransition Icon"}, | |
{typeof(BlendTree), "BlendTree Icon"}, | |
{typeof(DefaultAsset), "DefaultAsset Icon"}, | |
{typeof(EditorSettings), "EditorSettings Icon"}, | |
{typeof(HumanTemplate), "HumanTemplate Icon"}, | |
{typeof(LightingDataAsset), "LightingDataAsset Icon"}, | |
{typeof(LightmapParameters), "LightmapParameters Icon"}, | |
{typeof(SceneAsset), "SceneAsset Icon"}, | |
{typeof(Animation), "Animation Icon"}, | |
{typeof(AnimationClip), "AnimationClip Icon"}, | |
{typeof(AimConstraint), "AimConstraint Icon"}, | |
{typeof(LookAtConstraint), "LookAtConstraint Icon"}, | |
{typeof(ParentConstraint), "ParentConstraint Icon"}, | |
{typeof(PositionConstraint), "PositionConstraint Icon"}, | |
{typeof(RotationConstraint), "RotationConstraint Icon"}, | |
{typeof(ScaleConstraint), "ScaleConstraint Icon"}, | |
{typeof(Animator), "Animator Icon"}, | |
{typeof(AnimatorOverrideController), "AnimatorOverrideController Icon"}, | |
{typeof(AreaEffector2D), "AreaEffector2D Icon"}, | |
{typeof(AudioChorusFilter), "AudioChorusFilter Icon"}, | |
{typeof(AudioClip), "AudioClip Icon"}, | |
{typeof(AudioDistortionFilter), "AudioDistortionFilter Icon"}, | |
{typeof(AudioEchoFilter), "AudioEchoFilter Icon"}, | |
{typeof(AudioHighPassFilter), "AudioHighPassFilter Icon"}, | |
{typeof(AudioListener), "AudioListener Icon"}, | |
{typeof(AudioLowPassFilter), "AudioLowPassFilter Icon"}, | |
{typeof(AudioReverbFilter), "AudioReverbFilter Icon"}, | |
{typeof(AudioReverbZone), "AudioReverbZone Icon"}, | |
{typeof(AudioSource), "AudioSource Icon"}, | |
{typeof(Avatar), "Avatar Icon"}, | |
{typeof(AvatarMask), "AvatarMask Icon"}, | |
{typeof(BillboardAsset), "BillboardAsset Icon"}, | |
{typeof(BillboardRenderer), "BillboardRenderer Icon"}, | |
{typeof(BoxCollider), "BoxCollider Icon"}, | |
{typeof(BoxCollider2D), "BoxCollider2D Icon"}, | |
{typeof(BuoyancyEffector2D), "BuoyancyEffector2D Icon"}, | |
{typeof(Camera), "Camera Icon"}, | |
{typeof(Canvas), "Canvas Icon"}, | |
{typeof(CanvasGroup), "CanvasGroup Icon"}, | |
{typeof(CanvasRenderer), "CanvasRenderer Icon"}, | |
{typeof(CapsuleCollider), "CapsuleCollider Icon"}, | |
{typeof(CapsuleCollider2D), "CapsuleCollider2D Icon"}, | |
{typeof(CharacterController), "CharacterController Icon"}, | |
{typeof(CharacterJoint), "CharacterJoint Icon"}, | |
{typeof(CircleCollider2D), "CircleCollider2D Icon"}, | |
{typeof(Cloth), "Cloth Icon"}, | |
{typeof(CompositeCollider2D), "CompositeCollider2D Icon"}, | |
{typeof(ComputeShader), "ComputeShader Icon"}, | |
{typeof(ConfigurableJoint), "ConfigurableJoint Icon"}, | |
{typeof(ConstantForce), "ConstantForce Icon"}, | |
{typeof(ConstantForce2D), "ConstantForce2D Icon"}, | |
{typeof(Cubemap), "Cubemap Icon"}, | |
{typeof(DistanceJoint2D), "DistanceJoint2D Icon"}, | |
{typeof(EdgeCollider2D), "EdgeCollider2D Icon"}, | |
{typeof(EventSystem), "EventSystem Icon"}, | |
{typeof(EventTrigger), "EventTrigger Icon"}, | |
{typeof(Physics2DRaycaster), "Physics2DRaycaster Icon"}, | |
{typeof(PhysicsRaycaster), "PhysicsRaycaster Icon"}, | |
{typeof(StandaloneInputModule), "StandaloneInputModule Icon"}, | |
{typeof(VisualEffect), "VisualEffect Icon"}, | |
{typeof(VisualEffectAsset), "VisualEffectAsset Icon"}, | |
{typeof(FixedJoint), "FixedJoint Icon"}, | |
{typeof(FixedJoint2D), "FixedJoint2D Icon"}, | |
{typeof(Flare), "Flare Icon"}, | |
{typeof(FlareLayer), "FlareLayer Icon"}, | |
{typeof(Font), "Font Icon"}, | |
{typeof(FrictionJoint2D), "FrictionJoint2D Icon"}, | |
{typeof(GameObject), "GameObject Icon"}, | |
{typeof(Grid), "Grid Icon"}, | |
{typeof(GUISkin), "GUISkin Icon"}, | |
{typeof(HingeJoint), "HingeJoint Icon"}, | |
{typeof(HingeJoint2D), "HingeJoint2D Icon"}, | |
{typeof(LensFlare), "LensFlare Icon"}, | |
{typeof(Light), "Light Icon"}, | |
{typeof(LightProbeGroup), "LightProbeGroup Icon"}, | |
{typeof(LightProbeProxyVolume), "LightProbeProxyVolume Icon"}, | |
{typeof(LightProbes), "LightProbes Icon"}, | |
{typeof(LineRenderer), "LineRenderer Icon"}, | |
{typeof(LODGroup), "LODGroup Icon"}, | |
{typeof(Material), "Material Icon"}, | |
{typeof(Mesh), "Mesh Icon"}, | |
{typeof(MeshCollider), "MeshCollider Icon"}, | |
{typeof(MeshFilter), "MeshFilter Icon"}, | |
{typeof(MeshRenderer), "MeshRenderer Icon"}, | |
{typeof(Motion), "Motion Icon"}, | |
{typeof(OcclusionArea), "OcclusionArea Icon"}, | |
{typeof(OcclusionPortal), "OcclusionPortal Icon"}, | |
{typeof(ParticleSystem), "ParticleSystem Icon"}, | |
{typeof(ParticleSystemForceField), "ParticleSystemForceField Icon"}, | |
{typeof(PhysicMaterial), "PhysicMaterial Icon"}, | |
{typeof(PhysicsMaterial2D), "PhysicsMaterial2D Icon"}, | |
{typeof(PlatformEffector2D), "PlatformEffector2D Icon"}, | |
{typeof(PlayableDirector), "PlayableDirector Icon"}, | |
{typeof(PointEffector2D), "PointEffector2D Icon"}, | |
{typeof(PolygonCollider2D), "PolygonCollider2D Icon"}, | |
{typeof(Projector), "Projector Icon"}, | |
{typeof(RectTransform), "RectTransform Icon"}, | |
{typeof(ReflectionProbe), "ReflectionProbe Icon"}, | |
{typeof(RelativeJoint2D), "RelativeJoint2D Icon"}, | |
{typeof(SortingGroup), "SortingGroup Icon"}, | |
{typeof(RenderTexture), "RenderTexture Icon"}, | |
{typeof(Rigidbody), "Rigidbody Icon"}, | |
{typeof(Rigidbody2D), "Rigidbody2D Icon"}, | |
{typeof(ScriptableObject), "ScriptableObject Icon"}, | |
{typeof(Shader), "Shader Icon"}, | |
{typeof(ShaderVariantCollection), "ShaderVariantCollection Icon"}, | |
{typeof(SkinnedMeshRenderer), "SkinnedMeshRenderer Icon"}, | |
{typeof(Skybox), "Skybox Icon"}, | |
{typeof(SliderJoint2D), "SliderJoint2D Icon"}, | |
{typeof(SphereCollider), "SphereCollider Icon"}, | |
{typeof(SpringJoint), "SpringJoint Icon"}, | |
{typeof(SpringJoint2D), "SpringJoint2D Icon"}, | |
{typeof(Sprite), "Sprite Icon"}, | |
{typeof(SpriteMask), "SpriteMask Icon"}, | |
{typeof(SpriteRenderer), "SpriteRenderer Icon"}, | |
{typeof(StreamingController), "StreamingController Icon"}, | |
{typeof(SurfaceEffector2D), "SurfaceEffector2D Icon"}, | |
{typeof(TargetJoint2D), "TargetJoint2D Icon"}, | |
{typeof(Terrain), "Terrain Icon"}, | |
{typeof(TerrainCollider), "TerrainCollider Icon"}, | |
{typeof(TerrainData), "TerrainData Icon"}, | |
{typeof(TextAsset), "TextAsset Icon"}, | |
{typeof(TextMesh), "TextMesh Icon"}, | |
{typeof(Texture), "Texture Icon"}, | |
{typeof(Texture2D), "Texture2D Icon"}, | |
{typeof(Tile), "Tile Icon"}, | |
{typeof(Tilemap), "Tilemap Icon"}, | |
{typeof(TilemapCollider2D), "TilemapCollider2D Icon"}, | |
{typeof(TilemapRenderer), "TilemapRenderer Icon"}, | |
{typeof(TimelineAsset), "TimelineAsset Icon"}, | |
{typeof(TrailRenderer), "TrailRenderer Icon"}, | |
// {typeof(Transform), "Transform Icon"}, | |
{typeof(SpriteAtlas), "SpriteAtlas Icon"}, | |
{typeof(AspectRatioFitter), "AspectRatioFitter Icon"}, | |
{typeof(Button), "Button Icon"}, | |
{typeof(CanvasScaler), "CanvasScaler Icon"}, | |
{typeof(ContentSizeFitter), "ContentSizeFitter Icon"}, | |
{typeof(Dropdown), "Dropdown Icon"}, | |
{typeof(GraphicRaycaster), "GraphicRaycaster Icon"}, | |
{typeof(GridLayoutGroup), "GridLayoutGroup Icon"}, | |
{typeof(HorizontalLayoutGroup), "HorizontalLayoutGroup Icon"}, | |
{typeof(Image), "Image Icon"}, | |
{typeof(InputField), "InputField Icon"}, | |
{typeof(LayoutElement), "LayoutElement Icon"}, | |
{typeof(Mask), "Mask Icon"}, | |
{typeof(Outline), "Outline Icon"}, | |
{typeof(PositionAsUV1), "PositionAsUV1 Icon"}, | |
{typeof(RawImage), "RawImage Icon"}, | |
{typeof(RectMask2D), "RectMask2D Icon"}, | |
{typeof(Scrollbar), "Scrollbar Icon"}, | |
{typeof(ScrollRect), "ScrollRect Icon"}, | |
{typeof(Selectable), "Selectable Icon"}, | |
{typeof(Shadow), "Shadow Icon"}, | |
{typeof(Slider), "Slider Icon"}, | |
{typeof(Text), "Text Icon"}, | |
{typeof(Toggle), "Toggle Icon"}, | |
{typeof(ToggleGroup), "ToggleGroup Icon"}, | |
{typeof(VerticalLayoutGroup), "VerticalLayoutGroup Icon"}, | |
{typeof(VideoClip), "VideoClip Icon"}, | |
{typeof(VideoPlayer), "VideoPlayer Icon"}, | |
{typeof(WheelCollider), "WheelCollider Icon"}, | |
{typeof(WheelJoint2D), "WheelJoint2D Icon"}, | |
{typeof(WindZone), "WindZone Icon"}, | |
{typeof(MonoBehaviour), "cs Script Icon"}, | |
}; | |
private static Dictionary<System.Type, GUIContent> m_icons = new Dictionary<System.Type, GUIContent>(); | |
private static Dictionary<int, Dictionary<System.Type, int>> m_objectMap = new Dictionary<int, Dictionary<System.Type, int>>(); | |
static HierarchyIcons() | |
{ | |
foreach ( var kvp in m_iconPaths) | |
{ | |
m_icons[kvp.Key] = EditorGUIUtility.IconContent(kvp.Value); | |
} | |
EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB; | |
EditorApplication.hierarchyChanged += UpdateList; | |
UpdateList(); | |
} | |
static void UpdateList() | |
{ | |
GameObject[] go = Object.FindObjectsOfType(typeof(GameObject)) as GameObject[]; | |
foreach (GameObject g in go) | |
{ | |
var id = g.GetInstanceID(); | |
var components = g.GetComponents<Component>(); | |
var typeList = new List<System.Type>(); | |
m_objectMap[id] = new Dictionary<System.Type, int>(); | |
foreach (Component c in components) | |
{ | |
var type = c.GetType(); | |
if ( type.IsSubclassOf(typeof(MonoBehaviour))) | |
{ | |
type = typeof(MonoBehaviour); | |
} | |
if (!m_objectMap[id].ContainsKey(type)) | |
{ | |
m_objectMap[id][type] = 1; | |
} | |
else | |
{ | |
m_objectMap[id][type]++; | |
} | |
} | |
} | |
} | |
static void HierarchyItemCB(int instanceID, Rect selectionRect) | |
{ | |
if (m_objectMap.ContainsKey(instanceID)) | |
{ | |
Rect r = new Rect(selectionRect); | |
r.x = r.width; | |
r.width = 18; | |
foreach (var typeAndCount in m_objectMap[instanceID]) | |
{ | |
if (m_icons.ContainsKey(typeAndCount.Key)) | |
{ | |
r.x -= 15; | |
GUI.Label(r, m_icons[typeAndCount.Key]); | |
if (typeAndCount.Value > 1) | |
{ | |
GUI.Label(r, typeAndCount.Value.ToString()); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment