1
This commit is contained in:
parent
06dd5148d3
commit
0aa9e4f666
@ -6,13 +6,16 @@ using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace AlicizaX.AnimationFlow.Editor {
|
||||
public class SearchWindowProvider : ScriptableObject, ISearchWindowProvider {
|
||||
namespace AlicizaX.AnimationFlow.Editor
|
||||
{
|
||||
public class SearchWindowProvider : ScriptableObject, ISearchWindowProvider
|
||||
{
|
||||
private GraphWindow graphWindow;
|
||||
private GraphView graphView;
|
||||
private Texture2D icon;
|
||||
|
||||
public void Initialize(GraphWindow graphWindow, GraphView graphView) {
|
||||
public void Initialize(GraphWindow graphWindow, GraphView graphView)
|
||||
{
|
||||
this.graphWindow = graphWindow;
|
||||
this.graphView = graphView;
|
||||
icon = new Texture2D(1, 1);
|
||||
@ -20,39 +23,56 @@ namespace AlicizaX.AnimationFlow.Editor {
|
||||
icon.Apply();
|
||||
}
|
||||
|
||||
List<SearchTreeEntry> ISearchWindowProvider.CreateSearchTree(SearchWindowContext context) {
|
||||
List<SearchTreeEntry> entries = new() {
|
||||
List<SearchTreeEntry> ISearchWindowProvider.CreateSearchTree(SearchWindowContext context)
|
||||
{
|
||||
List<SearchTreeEntry> entries = new()
|
||||
{
|
||||
new SearchTreeGroupEntry(new GUIContent("Create Node", icon))
|
||||
};
|
||||
Dictionary<string, List<Type>> dicType = new();
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
|
||||
foreach (var type in assembly.GetTypes()) {
|
||||
if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(ActionNode))) {
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (assembly.FullName.Contains("Sirenix")) continue;
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(ActionNode)))
|
||||
{
|
||||
CategoryAttribute categoryAttribute = type.GetCustomAttributes(typeof(CategoryAttribute), true).FirstOrDefault() as CategoryAttribute;
|
||||
if (categoryAttribute == null || string.IsNullOrEmpty(categoryAttribute.category)) {
|
||||
if (categoryAttribute == null || string.IsNullOrEmpty(categoryAttribute.category))
|
||||
{
|
||||
NameAttribute nameAttribute = type.GetCustomAttributes(typeof(NameAttribute), true).FirstOrDefault() as NameAttribute;
|
||||
entries.Add(new SearchTreeEntry(new GUIContent(nameAttribute != null && !string.IsNullOrEmpty(nameAttribute.name) ? nameAttribute.name : type.Name, icon)) { level = 1, userData = type });
|
||||
} else {
|
||||
if (dicType.TryGetValue(categoryAttribute.category, out var list)) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dicType.TryGetValue(categoryAttribute.category, out var list))
|
||||
{
|
||||
list.Add(type);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
dicType.Add(categoryAttribute.category, new List<Type>() { type });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var kv in dicType) {
|
||||
|
||||
foreach (var kv in dicType)
|
||||
{
|
||||
entries.Add(new SearchTreeGroupEntry(new GUIContent(kv.Key), 1));
|
||||
foreach (Type type in kv.Value) {
|
||||
foreach (Type type in kv.Value)
|
||||
{
|
||||
NameAttribute nameAttribute = type.GetCustomAttributes(typeof(NameAttribute), true).FirstOrDefault() as NameAttribute;
|
||||
entries.Add(new SearchTreeEntry(new GUIContent(nameAttribute != null && !string.IsNullOrEmpty(nameAttribute.name) ? nameAttribute.name : type.Name, icon)) { level = 2, userData = type });
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
bool ISearchWindowProvider.OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context) {
|
||||
bool ISearchWindowProvider.OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
|
||||
{
|
||||
var type = searchTreeEntry.userData as Type;
|
||||
var data = Activator.CreateInstance(type) as ActionNode;
|
||||
data.uuid = Guid.NewGuid().ToString();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user