-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAssetTreeEditorWindow.cs
74 lines (56 loc) · 1.58 KB
/
AssetTreeEditorWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/**
* TreeNode.cs
* Author: Luke Holland (http://lukeholland.me/)
*/
namespace TreeView {
public class AssetTreeEditorWindow : EditorWindow
{
[MenuItem("Tools/Tree View Example Window")]
private static void CreateEditorWindow()
{
EditorWindow.GetWindow<AssetTreeEditorWindow>("Asset Tree");
}
private AssetTree _assetTree;
private AssetTreeIMGUI _assetTreeGUI;
private Vector2 _scrollPosition;
private string _searchString;
protected void OnEnable()
{
// setup
_assetTree = new AssetTree();
_assetTreeGUI = new AssetTreeIMGUI(_assetTree.Root);
// fill tree with example data
_searchString = "t:Script";
Search(_searchString);
}
protected void OnGUI()
{
// draw search
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
EditorGUILayout.LabelField("Search:",EditorStyles.miniLabel,GUILayout.Width(40));
EditorGUI.BeginChangeCheck();
_searchString = EditorGUILayout.TextField(_searchString,EditorStyles.toolbarTextField,GUILayout.ExpandWidth(true));
if(EditorGUI.EndChangeCheck()){
Search(_searchString);
}
EditorGUILayout.EndHorizontal();
// draw tree
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
_assetTreeGUI.DrawTreeLayout();
EditorGUILayout.EndScrollView();
}
private void Search(string query)
{
_assetTree.Clear();
string[] guids = AssetDatabase.FindAssets(query);
int i = 0, l = guids.Length;
for(; i<l; ++i){
_assetTree.AddAsset(guids[i]);
}
}
}
}