Skip to content

Commit 68bc573

Browse files
committed
Search Prefabs
- Added function to Search Prefabs with key, returning List of matches.
1 parent 81fcac1 commit 68bc573

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

Assets/MapEditor/Editor/TreeView/PrefabsList/PrefabsListTreeView.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ public static void TreeToList(TreeViewItem root, IList<TreeViewItem> result)
5757
result.Add(current);
5858

5959
if (current.hasChildren && current.children[0] != null)
60-
{
6160
for (int i = current.children.Count - 1; i >= 0; i--)
62-
{
6361
stack.Push(current.children[i]);
64-
}
65-
}
6662
}
6763
}
6864

@@ -257,10 +253,7 @@ protected override bool CanMultiSelect(TreeViewItem item)
257253
return false;
258254
}
259255

260-
protected override void SelectionChanged(IList<int> selectedIds)
261-
{
262-
SetItemSelected(selectedIds[0]);
263-
}
256+
protected override void SelectionChanged(IList<int> selectedIds) => SetItemSelected(selectedIds[0]);
264257

265258
protected override void DoubleClickedItem(int id)
266259
{

Assets/MapEditor/Editor/TreeView/TreeDataModel/TreeViewWithTreeModel.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,12 @@ void Search(T searchFromThis, string search, List<TreeViewItem> result)
119119
T current = stack.Pop();
120120
// Matches search?
121121
if (current.name.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
122-
{
123122
if (!current.hasChildren) // Filters out including parent objects in the search.
124-
{
125123
result.Add(new TreeViewItem<T>(current.id, kItemDepth, current.name, current));
126-
}
127-
}
128124

129125
if (current.children != null && current.children.Count > 0)
130-
{
131126
foreach (var element in current.children)
132-
{
133127
stack.Push((T)element);
134-
}
135-
}
136128
}
137129
}
138130

@@ -239,4 +231,4 @@ bool ValidDrag(TreeViewItem parent, List<TreeViewItem> draggedItems)
239231

240232
}
241233

242-
}
234+
}

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Unity.EditorCoroutines.Editor;
55
using System.Collections;
66
using System.Collections.Generic;
7+
using System.Linq;
78

89
public static class PrefabManager
910
{
@@ -21,6 +22,9 @@ public static class Callbacks
2122
public static Transform PrefabParent { get; private set; }
2223
public static GameObject PrefabToSpawn;
2324

25+
/// <summary>List of prefab names from the asset bundle.</summary>
26+
private static List<string> Prefabs;
27+
2428
public static PrefabDataHolder[] CurrentMapPrefabs { get => PrefabParent.gameObject.GetComponentsInChildren<PrefabDataHolder>(); }
2529

2630
public static Dictionary<string, Transform> PrefabCategories = new Dictionary<string, Transform>();
@@ -61,6 +65,22 @@ public static GameObject Load(uint id)
6165
return Load(AssetManager.ToPath(id));
6266
}
6367

68+
/// <summary>Searches through all prefabs found in bundle files, returning matches.</summary>
69+
/// <returns>List of strings containing the path matching the <paramref name="key"/>.</returns>
70+
public static List<string> Search(string key)
71+
{
72+
if (Prefabs == null)
73+
{
74+
Prefabs = new List<string>();
75+
foreach (var i in AssetManager.AssetPaths)
76+
if (i.EndsWith(".prefab"))
77+
Prefabs.Add(i);
78+
79+
Prefabs.OrderBy(x => x);
80+
}
81+
82+
return Prefabs.Where(x => x.Contains(key)).ToList();
83+
}
6484

6585
/// <summary>Gets the parent prefab category transform from the hierachy.</summary>
6686
public static Transform GetParent(string category)

0 commit comments

Comments
 (0)