Tanoda
HierarchyPostProcessEditor.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using UnityEditor;
11using System;
12using System.Linq;
14
16 using Query;
17
18 [CustomEditor(typeof(HierarchyPostProcess))]
19 public class HierarchyPostProcessEditor : CustomEditorBase<HierarchyPostProcess> {
20 private const string PREF_PREFIX = "HierarchyPostProcess_ShouldDelete_";
21
22 private bool _expandComponentTypes = false;
23
24 public override void OnInspectorGUI() {
25 base.OnInspectorGUI();
26
27 if (target == null) {
28 return;
29 }
30
31 bool isPrefab = Utils.IsObjectPartOfPrefabAsset(target);
32 EditorGUI.BeginDisabledGroup(isPrefab);
33
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."
39 : ""))) {
40 EditorApplication.delayCall += () => {
41 target.BuildPlaybackPrefab(new ProgressBar());
42 };
43 }
44
45 EditorGUI.EndDisabledGroup();
46
47 EditorGUILayout.Space();
48 _expandComponentTypes = EditorGUILayout.Foldout(_expandComponentTypes, "Component List");
49 if (_expandComponentTypes) {
50 EditorGUI.indentLevel++;
51
52 var components = target.GetComponentsInChildren<Component>(includeInactive: true).
53 Where(c => !(c is Transform || c is RectTransform)).
54 Select(c => c.GetType()).
55 Distinct().
56 Where(m => m.Namespace != "Leap.Unity.Recording").
57 OrderBy(m => m.Name);
58
59 var groups = components.GroupBy(t => t.Namespace).OrderBy(g => g.Key);
60
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);
65 }
66 }
67
68 foreach (var group in groups) {
69 EditorGUILayout.Space();
70
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)).
76 UniformOrNone();
77
78 bool valueToUse = false;
79 uniform.Match(val => {
80 valueToUse = val;
81 },
82 () => {
83 valueToUse = false;
84 EditorGUI.showMixedValue = true;
85 });
86
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);
92 }
93 }
94
95 EditorGUI.showMixedValue = false;
96 }
97
98 EditorGUILayout.Space();
99 GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
100
101 foreach (var type in group) {
102 using (new GUILayout.HorizontalScope()) {
103 string prefKey = getTypePrefKey(type);
104 bool curValue = EditorPrefs.GetBool(prefKey, defaultValue: false);
105
106 EditorGUI.BeginChangeCheck();
107 curValue = EditorGUILayout.ToggleLeft(type.Name, curValue);
108 if (EditorGUI.EndChangeCheck()) {
109 EditorPrefs.SetBool(prefKey, curValue);
110 }
111
112 if (GUILayout.Button("Select", GUILayout.ExpandWidth(false))) {
113 Selection.objects = target.GetComponentsInChildren(type, includeInactive: true).Select(t => t.gameObject).ToArray();
114 }
115
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);
120 }
121 }
122 }
123 }
124 }
125 }
126 }
127 }
128
129 private static string getTypePrefKey(Type type) {
130 return PREF_PREFIX + type.Namespace + "_" + type.Name;
131 }
132 }
133}
UnityEngine.Component Component
This class allows you to easily give feedback of an action as it completes.
Definition: ProgressBar.cs:66
override void OnInspectorGUI()
A Query object is a type of immutable ordered collection of elements that can be used to perform usef...
Definition: Query.cs:90