Created
September 14, 2020 05:23
-
-
Save instance-id/836a809f6b69a928f650f9c16fb7b04d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
using UnityEngine.UIElements; | |
namespace MultiplayerARPG | |
{ | |
public class ClassList : EditorWindow | |
{ | |
static string searchTerm = "t:PlayerCharacter"; // <-- A search filter to find each PlayerCharacter object in the project | |
private PlayerCharacter[] objectList; | |
private VisualElement root; | |
[MenuItem("Tools/Class List")] | |
private static void ShowWindow() | |
{ | |
var window = GetWindow<ClassList>(); | |
window.titleContent = new GUIContent("Class List"); | |
window.Show(); | |
} | |
private void Awake() | |
{ | |
root = rootVisualElement; | |
} | |
private void OnEnable() | |
{ | |
var scroller = new ScrollView {style = {paddingLeft = 10, paddingRight = 10, paddingTop = 5}}; | |
objectList = LoadData(); // <-- Loads the data from disk | |
foreach (var playerCharacter in objectList) | |
{ | |
scroller.Add(new Label($"{playerCharacter.title} : {playerCharacter.ClassID.ToString()}")); | |
} // For each playerCharacter that was loaded from disk, create a label and add the title and classid, | |
// then add it to the editor windows ScrollView object. | |
root.Add(scroller); | |
} | |
PlayerCharacter[] LoadData() | |
{ // --- Uses the search filter to locate all PlayerCharacter Scriptable objects | |
var objects = AssetDatabase.FindAssets(searchTerm) | |
.Select(guid => AssetDatabase.LoadAssetAtPath<PlayerCharacter>(AssetDatabase.GUIDToAssetPath(guid))).ToArray(); // <== Returns them as an array | |
// |^ -- Uses the found PlayerCharacter ScriptableObject results and loads each one from disk | |
foreach (var item in objects) | |
{ | |
Debug.Log($"Found: {item.name}"); | |
} | |
return objects; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment