private void PopulateAssets(string path) { _assets = new List <AssetDir>(); DirectoryInfo dir = new DirectoryInfo(path); // find all directories // NOTE: ONLY GOES ONE LEVEL DEEP. don't rlly feel like making this recursive DirectoryInfo[] subDirs = dir.GetDirectories(); foreach (DirectoryInfo d in subDirs) { AssetDir assetDir = new AssetDir(d.Name); // find all prefabs in each directory FileInfo[] info = d.GetFiles("*.prefab"); foreach (FileInfo file in info) { string assetPath = _assetPath + "/" + assetDir.name + "/" + file.Name; assetDir.assets.Add(new AssetObj(assetPath)); } _assets.Add(assetDir); } }
// creates the LevelBuilder window void OnGUI() { GUILayout.Label(_titleString, EditorStyles.boldLabel); if (GUILayout.Button("Clear Selected Object")) { ClearSelection(); } GUILayout.Label("Search", EditorStyles.label); search = GUILayout.TextField(search); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); // SCROLL var window = EditorWindow.GetWindow <LevelBuilder>(); _scrollPos = GUILayout.BeginScrollView(_scrollPos, GUILayout.Width(window.position.width), GUILayout.Height(window.position.height - _scrollFudgeFactor)); // create lists for each directory for (int i = 0; i < _assets.Count; i++) { AssetDir dir = _assets[i]; GUILayout.Label(dir.name, EditorStyles.boldLabel); // filter assets by search term List <AssetObj> assets = FindAssetsWithTerm(dir.assets, search); if (assets.Count > 0) { // load all assets into buttons // button click loads corresponding object into active object GUILayout.BeginHorizontal(GUILayout.Width(assets[0].icon.width * assets.Count)); foreach (AssetObj ao in assets) { GUILayout.BeginVertical(); GUILayout.Label(ao.name, EditorStyles.label); // highlight button for active object if (_activeObj == ao.obj) { GUI.backgroundColor = Color.blue; } else { GUI.backgroundColor = Color.white; } if (GUILayout.Button(ao.icon, GUILayout.Width(ao.icon.width), GUILayout.Height(ao.icon.height))) { if (_activeObj != ao.obj) { _activeObj = ao.obj; } else { _activeObj = null; // de-select obj when clicking a selected button } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); // END SCROLL }