2025-02-07 16:05:13 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AlicizaX.AnimationFlow.Runtime;
|
|
|
|
|
using UnityEditor.Experimental.GraphView;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
2025-11-14 20:52:00 +08:00
|
|
|
namespace AlicizaX.AnimationFlow.Editor
|
|
|
|
|
{
|
|
|
|
|
public class SearchWindowProvider : ScriptableObject, ISearchWindowProvider
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
private GraphWindow graphWindow;
|
|
|
|
|
private GraphView graphView;
|
|
|
|
|
private Texture2D icon;
|
|
|
|
|
|
2025-11-14 20:52:00 +08:00
|
|
|
public void Initialize(GraphWindow graphWindow, GraphView graphView)
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
this.graphWindow = graphWindow;
|
|
|
|
|
this.graphView = graphView;
|
|
|
|
|
icon = new Texture2D(1, 1);
|
|
|
|
|
icon.SetPixel(0, 0, Color.clear);
|
|
|
|
|
icon.Apply();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-14 20:52:00 +08:00
|
|
|
List<SearchTreeEntry> ISearchWindowProvider.CreateSearchTree(SearchWindowContext context)
|
|
|
|
|
{
|
|
|
|
|
List<SearchTreeEntry> entries = new()
|
|
|
|
|
{
|
|
|
|
|
new SearchTreeGroupEntry(new GUIContent("Create Node", icon))
|
2025-02-07 16:05:13 +08:00
|
|
|
};
|
|
|
|
|
Dictionary<string, List<Type>> dicType = new();
|
2025-11-14 20:52:00 +08:00
|
|
|
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)))
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
CategoryAttribute categoryAttribute = type.GetCustomAttributes(typeof(CategoryAttribute), true).FirstOrDefault() as CategoryAttribute;
|
2025-11-14 20:52:00 +08:00
|
|
|
if (categoryAttribute == null || string.IsNullOrEmpty(categoryAttribute.category))
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
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 });
|
2025-11-14 20:52:00 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (dicType.TryGetValue(categoryAttribute.category, out var list))
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
list.Add(type);
|
2025-11-14 20:52:00 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
dicType.Add(categoryAttribute.category, new List<Type>() { type });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-14 20:52:00 +08:00
|
|
|
|
|
|
|
|
foreach (var kv in dicType)
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
entries.Add(new SearchTreeGroupEntry(new GUIContent(kv.Key), 1));
|
2025-11-14 20:52:00 +08:00
|
|
|
foreach (Type type in kv.Value)
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
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 });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-14 20:52:00 +08:00
|
|
|
|
2025-02-07 16:05:13 +08:00
|
|
|
return entries;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-14 20:52:00 +08:00
|
|
|
bool ISearchWindowProvider.OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
|
|
|
|
|
{
|
2025-02-07 16:05:13 +08:00
|
|
|
var type = searchTreeEntry.userData as Type;
|
|
|
|
|
var data = Activator.CreateInstance(type) as ActionNode;
|
|
|
|
|
data.uuid = Guid.NewGuid().ToString();
|
|
|
|
|
data.nodePos = graphView.contentViewContainer.WorldToLocal(context.screenMousePosition - graphWindow.position.position);
|
|
|
|
|
graphView.AddNodeView(data);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|