void OnGUI() { if (referenceStyle == null) { referenceStyle = SelectionHistoryWindow.CreateObjectReferenceStyle(); } GUILayout.BeginHorizontal(); GUILayout.Label("Required component"); componentType = GUILayout.TextField(componentType); GUILayout.EndHorizontal(); GUILayout.Label("!Currently only searches in project folder!"); if (GUILayout.Button("Find")) { foundList.Clear(); var guids = AssetDatabase.FindAssets("t:GameObject"); var i = 1; foreach (var guid in guids) { EditorUtility.DisplayProgressBar("Scanning", "Prefab:" + i + "/" + guids.Length, (float)i / (float)guids.Length); var path = AssetDatabase.GUIDToAssetPath(guid); var go = AssetDatabase.LoadAssetAtPath <GameObject>(path); foreach (var component in go.GetComponentsInChildren <Component>()) { if (component == null) { GameDebug.LogError("Prefab " + path + " has null component"); continue; } var type = component.GetType(); if (type.Name == componentType) { foundList.Add(go); break; } } i++; } EditorUtility.ClearProgressBar(); } GUILayout.Label("Found:" + foundList.Count); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); foreach (var found in foundList) { SelectionHistoryWindow.DrawObjectReference(found, found.name, referenceStyle); } EditorGUILayout.EndScrollView(); }
public override void OnGUI(Rect rect) { if (editorWindow != null) { editorWindow.minSize = new Vector2(300.0f, 450.0f); } var l = SelectionToolbar.m_HistoryStack.Length; // Prune invalid refs by iterating from edn for (int src = SelectionToolbar.m_HistoryStackEnd, dst = src, count = 0; count < l; count++) { if (src < 0) { break; } var s = SelectionToolbar.m_HistoryStack[src % l]; if (s.IsAlive && (s.Target as UnityEngine.Object) != null) { SelectionToolbar.m_HistoryStack[dst % l] = s; dst--; } src--; } var to = SelectionToolbar.m_HistoryStackEnd - 20; var from = SelectionToolbar.m_HistoryStackEnd; to = to < 0 ? 0 : to; scrollPosition = GUILayout.BeginScrollView(scrollPosition); for (var i = from; i >= to; --i) { var o = SelectionToolbar.m_HistoryStack[i % l]; if (o.IsAlive) { var uo = o.Target as UnityEngine.Object; if (uo != null) { GUILayout.BeginHorizontal(); GUILayout.Label(i == SelectionToolbar.m_HistoryStackIdx ? "+" : "", GUILayout.Width(10.0f)); SelectionHistoryWindow.DrawObjectReference(uo, uo.name, historyItemStyle); GUILayout.EndHorizontal(); } } } GUILayout.EndScrollView(); }
void OnGUI() { if (referenceStyle == null) { referenceStyle = SelectionHistoryWindow.CreateObjectReferenceStyle(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Create New")) { CreateNewSet(); } GUILayout.EndVertical(); scrollViewPos = GUILayout.BeginScrollView(scrollViewPos); Set deletedSet = null; foreach (var set in sets) { GUILayout.BeginHorizontal(); var expandButtonText = set.expanded ? "^" : "v"; if (GUILayout.Button(expandButtonText, GUILayout.Width(20))) { set.expanded = !set.expanded; } if (GUILayout.Button("S", GUILayout.Width(20))) { Selection.objects = set.entries.ToArray(); } set.name = GUILayout.TextField(set.name); if (GUILayout.Button("Add", GUILayout.Width(50))) { AddToSet(set); } if (GUILayout.Button("Set", GUILayout.Width(50))) { OverrideSet(set); } if (GUILayout.Button("-", GUILayout.Width(20))) { var result = EditorUtility.DisplayDialog("Delete set?", "Are you sure you want to delete set:" + set.name, "Delete", "Cancel"); if (result) { deletedSet = set; } } GUILayout.EndHorizontal(); if (!set.expanded) { continue; } UnityEngine.Object deletedEntry = null; foreach (var entry in set.entries) { GUILayout.BeginHorizontal(); SelectionHistoryWindow.DrawObjectReference(entry, referenceStyle); if (GUILayout.Button("-", GUILayout.Width(20))) { deletedEntry = entry; } GUILayout.EndHorizontal(); } if (deletedEntry != null) { Undo.RecordObject(this, "Remove from set"); set.entries.Remove(deletedEntry); SaveSets(); Repaint(); } } GUILayout.EndScrollView(); if (deletedSet != null) { Undo.RecordObject(this, "Delete set"); sets.Remove(deletedSet); SaveSets(); Repaint(); } }
void OnGUI() { GUILayout.BeginHorizontal(); var newMode = (Mode)EditorGUILayout.EnumPopup("Mode", m_Mode); if (newMode != m_Mode) { m_Mode = newMode; m_DependencyData.Clear(); // Clear data as it is no longer valid for current mode } if (GUILayout.Button("Find")) { if (m_Mode == Mode.FindAssetDependencies) { FindAssetDependencies(); } else { FindAssetThatDependsOn(); } } GUILayout.EndHorizontal(); m_ScrollViewPos = GUILayout.BeginScrollView(m_ScrollViewPos); foreach (var data in m_DependencyData) { var o = AssetDatabase.LoadAssetAtPath <Object>(data.AssetPath); SelectionHistoryWindow.DrawObjectReference(o, data.AssetPath, m_ReferenceStyle); foreach (var dependency in data.Dependencies) { GUILayout.BeginHorizontal(); var arrow = m_Mode == Mode.FindAssetDependencies ? " <-" : " ->"; GUILayout.Label(arrow, GUILayout.Width(40)); o = AssetDatabase.LoadAssetAtPath <Object>(dependency); SelectionHistoryWindow.DrawObjectReference(o, dependency, m_ReferenceStyle); GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Select assets WITH dependencies")) { var select = new List <Object>(); foreach (var data in m_DependencyData) { if (data.Dependencies.Count == 0) { continue; } var asset = AssetDatabase.LoadAssetAtPath <Object>(data.AssetPath); select.Add(asset); } Selection.objects = select.ToArray(); Repaint(); } if (GUILayout.Button("Select assets with NO dependencies")) { var select = new List <Object>(); foreach (var data in m_DependencyData) { if (data.Dependencies.Count > 0) { continue; } var asset = AssetDatabase.LoadAssetAtPath <Object>(data.AssetPath); select.Add(asset); } Selection.objects = select.ToArray(); Repaint(); } GUILayout.EndHorizontal(); }
private void OnEnable() { m_ReferenceStyle = SelectionHistoryWindow.CreateObjectReferenceStyle(); }