Skip to content

Instantly share code, notes, and snippets.

@BennyKok
Last active July 27, 2020 11:32
Show Gist options
  • Save BennyKok/78776e0ae79afc61834ed7ec52c082ee to your computer and use it in GitHub Desktop.
Save BennyKok/78776e0ae79afc61834ed7ec52c082ee to your computer and use it in GitHub Desktop.
A simple editor which reveal hidden component, and lets you delete it.
using UnityEditor;
using UnityEngine;
public class HiddenComponentViewer : EditorWindow
{
[MenuItem("Tools/HiddenComponentViewer")]
private static void ShowWindow()
{
var window = GetWindow<HiddenComponentViewer>();
window.titleContent = new GUIContent("HiddenComponentViewer");
window.Show();
}
GameObject target;
Component[] componentCache;
public void Refresh()
{
if (!target)
{
componentCache = null;
return;
}
componentCache = target.GetComponents<Component>();
}
private void OnGUI()
{
EditorGUI.BeginChangeCheck();
target = EditorGUILayout.ObjectField(target, typeof(GameObject), true) as GameObject;
if (EditorGUI.EndChangeCheck())
{
Refresh();
}
if (componentCache == null) return;
foreach (var component in componentCache)
{
if (!component.hideFlags.HasFlag(HideFlags.HideInInspector)) continue;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(component.GetType().Name);
if (GUILayout.Button("Delete"))
{
Undo.DestroyObjectImmediate(component);
EditorUtility.SetDirty(target);
Refresh();
}
EditorGUILayout.EndHorizontal();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment