private void DrawInspector(SearchSelection selection, float width) { if (m_Editors == null) { return; } for (int i = 0; i < m_Editors.Length; ++i) { var e = m_Editors[i]; if (!e) { continue; } EditorGUIUtility.labelWidth = 0.4f * width; bool foldout = false; if (!m_EditorTypeFoldout.TryGetValue(e.GetType().Name, out foldout)) { foldout = true; } using (new EditorGUIUtility.IconSizeScope(new Vector2(16, 16))) { var sectionContent = selection.Count == 1 ? EditorGUIUtility.ObjectContent(e.target, e.GetType()) : e.GetPreviewTitle(); if (selection.Count == 1) { sectionContent.tooltip = sectionContent.text; } else { sectionContent.tooltip = String.Join("\r\n", e.targets.Select(t => $"{SearchUtils.GetObjectPath(t)} ({t.GetInstanceID()})")); } foldout = EditorGUILayout.BeginToggleGroup(sectionContent, foldout); if (foldout) { try { if (e.target is Transform) { e.DrawDefaultInspector(); } else { e.OnInspectorGUI(); } m_EditorTypeFoldout[e.GetType().Name] = foldout; } catch { // Ignore } } EditorGUILayout.EndToggleGroup(); } } }
private void SetupEditors(SearchSelection selection) { int selectionHash = 0; foreach (var s in selection) { selectionHash ^= s.id.GetHashCode(); } if (selectionHash == m_EditorsHash) { return; } ResetEditors(); var targets = new List <UnityEngine.Object>(); foreach (var s in selection) { var item = s; var itemObject = item.provider.toObject?.Invoke(item, typeof(UnityEngine.Object)); if (!itemObject) { continue; } if (itemObject is GameObject go) { var components = go.GetComponents <Component>(); foreach (var c in components.Skip(components.Length > 1 ? 1 : 0)) { if (!c || c.hideFlags.HasFlag(HideFlags.HideInInspector)) { continue; } targets.Add(c); } } else { targets.Add(itemObject); } } m_Editors = targets.GroupBy(t => t.GetType()).Select(g => Editor.CreateEditor(g.ToArray())).ToArray(); m_EditorsHash = selectionHash; }