20 private const string PREF_PREFIX =
"HierarchyPostProcess_ShouldDelete_";
22 private bool _expandComponentTypes =
false;
25 base.OnInspectorGUI();
31 bool isPrefab = Utils.IsObjectPartOfPrefabAsset(
target);
32 EditorGUI.BeginDisabledGroup(isPrefab);
34 EditorGUILayout.Space();
35 if (GUILayout.Button(
new GUIContent(
"Build Playback Prefab",
36 isPrefab ?
"Draw this object into the scene "
37 +
"before converting its raw recording "
38 +
"data into AnimationClip data."
40 EditorApplication.delayCall += () => {
45 EditorGUI.EndDisabledGroup();
47 EditorGUILayout.Space();
48 _expandComponentTypes = EditorGUILayout.Foldout(_expandComponentTypes,
"Component List");
49 if (_expandComponentTypes) {
50 EditorGUI.indentLevel++;
52 var components =
target.GetComponentsInChildren<
Component>(includeInactive:
true).
53 Where(c => !(c is Transform || c is RectTransform)).
54 Select(c => c.GetType()).
56 Where(m => m.Namespace !=
"Leap.Unity.Recording").
59 var groups = components.GroupBy(t => t.Namespace).OrderBy(g => g.Key);
61 if (GUILayout.Button(
"Delete All Checked Components", GUILayout.Height(EditorGUIUtility.singleLineHeight * 2))) {
62 foreach (var c
in components.Where(t => EditorPrefs.GetBool(getTypePrefKey(t), defaultValue:
false)).
63 SelectMany(c =>
target.GetComponentsInChildren(c, includeInactive:
true))) {
64 Undo.DestroyObjectImmediate(c);
68 foreach (var group
in groups) {
69 EditorGUILayout.Space();
71 using (
new GUILayout.VerticalScope(EditorStyles.helpBox)) {
72 using (
new GUILayout.HorizontalScope()) {
73 var uniform = group.Query().
74 Select(getTypePrefKey).
75 Select(k => EditorPrefs.GetBool(k, defaultValue:
false)).
78 bool valueToUse =
false;
79 uniform.Match(val => {
84 EditorGUI.showMixedValue =
true;
87 EditorGUI.BeginChangeCheck();
88 valueToUse = EditorGUILayout.ToggleLeft(group.Key ??
"Dev", valueToUse, EditorStyles.boldLabel);
89 if (EditorGUI.EndChangeCheck()) {
90 foreach (var t
in group) {
91 EditorPrefs.SetBool(getTypePrefKey(t), valueToUse);
95 EditorGUI.showMixedValue =
false;
98 EditorGUILayout.Space();
99 GUILayout.Box(
"", GUILayout.ExpandWidth(
true), GUILayout.Height(1));
101 foreach (var type
in group) {
102 using (
new GUILayout.HorizontalScope()) {
103 string prefKey = getTypePrefKey(type);
104 bool curValue = EditorPrefs.GetBool(prefKey, defaultValue:
false);
106 EditorGUI.BeginChangeCheck();
107 curValue = EditorGUILayout.ToggleLeft(type.Name, curValue);
108 if (EditorGUI.EndChangeCheck()) {
109 EditorPrefs.SetBool(prefKey, curValue);
112 if (GUILayout.Button(
"Select", GUILayout.ExpandWidth(
false))) {
113 Selection.objects =
target.GetComponentsInChildren(type, includeInactive:
true).Select(t => t.gameObject).ToArray();
116 if (GUILayout.Button(
"Delete", GUILayout.ExpandWidth(
false))) {
117 var toDelete =
target.GetComponentsInChildren(type, includeInactive:
true);
118 foreach (var t
in toDelete) {
119 Undo.DestroyObjectImmediate(t);
129 private static string getTypePrefKey(Type type) {
130 return PREF_PREFIX + type.Namespace +
"_" + type.Name;
UnityEngine.Component Component
This class allows you to easily give feedback of an action as it completes.
override void OnInspectorGUI()
A Query object is a type of immutable ordered collection of elements that can be used to perform usef...