yeah i dont think this is gon work
This commit is contained in:
parent
370504dcfc
commit
c76d20e362
@ -25,8 +25,8 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
||||
|
||||
public void OnDropOutsidePort(Edge edge, Vector2 position)
|
||||
{
|
||||
window.searchProvider.target = (VisualElement)window.focusController.focusedElement;
|
||||
SearchWindow.Open(new SearchWindowContext(position), window.searchProvider);
|
||||
// window.searchProvider.target = (VisualElement)window.focusController.focusedElement;
|
||||
// SearchWindow.Open(new SearchWindowContext(position), window.searchProvider);
|
||||
|
||||
List<GraphConnection> connections = new List<GraphConnection>();
|
||||
|
||||
|
@ -1,138 +1,92 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Search;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Codice.Client.Common;
|
||||
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows
|
||||
using Object = UnityEngine.Object;
|
||||
static class IPT_SearchProvider
|
||||
{
|
||||
public struct SearchContextElement
|
||||
{
|
||||
public object target { get; private set; }
|
||||
public string title { get; private set; }
|
||||
internal static string id = "IPT_Tree";
|
||||
internal static List<SearchContextElement> elements;
|
||||
|
||||
public SearchContextElement(object target, string title)
|
||||
[SearchItemProvider]
|
||||
internal static SearchProvider CreateProvider()
|
||||
{
|
||||
return new SearchProvider(id, "IPT Nodes")
|
||||
{
|
||||
this.target = target;
|
||||
this.title = title;
|
||||
filterId = "tree:",
|
||||
priority = 99999,
|
||||
showDetailsOptions = ShowDetailsOptions.Inspector | ShowDetailsOptions.Actions,
|
||||
fetchItems = (context, items, provider) => FetchItems(context, provider),
|
||||
fetchLabel = (item, context) => item.label,
|
||||
fetchDescription = (item, context) => item.description,
|
||||
toObject = (item, type) => item.data as Object
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<SearchItem> FetchItems(SearchContext context, SearchProvider provider)
|
||||
{
|
||||
if (elements == null)
|
||||
BuildElements();
|
||||
|
||||
foreach (var element in elements)
|
||||
{
|
||||
if (!element.title.ToLower().Contains(context.searchQuery.ToLower()))
|
||||
continue;
|
||||
|
||||
// var item = provider.CreateItem(context, element.title, element.title, $"Node: {element.title}", 0, element.target);
|
||||
var item = provider.CreateItem(context, element.title, element.title, element.title, null, element.target);
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
public class ImageProcessingGraphSearchProvider : ScriptableObject, ISearchWindowProvider
|
||||
|
||||
private static void BuildElements()
|
||||
{
|
||||
public ImageProcessingGraphViewWindow graph;
|
||||
public VisualElement target;
|
||||
elements = new List<SearchContextElement>();
|
||||
|
||||
public static List<SearchContextElement> elements;
|
||||
private Assembly[] assemblies;
|
||||
public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
|
||||
foreach (var type in TypeCache.GetTypesWithAttribute<NodeInfoAttribute>())
|
||||
{
|
||||
List<SearchTreeEntry> tree = new List<SearchTreeEntry>();
|
||||
tree.Add(new SearchTreeGroupEntry(new GUIContent("Nodes"), 0));
|
||||
|
||||
elements = new List<SearchContextElement>();
|
||||
|
||||
/*
|
||||
assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
*/
|
||||
var attr = type.GetCustomAttribute<NodeInfoAttribute>();
|
||||
if (string.IsNullOrEmpty(attr.MenuItem))
|
||||
continue;
|
||||
|
||||
/*foreach (var assembly in assemblies)
|
||||
{
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
{
|
||||
if (type.CustomAttributes.ToList() != null)
|
||||
{
|
||||
var attr = type.GetCustomAttribute(typeof(NodeInfoAttribute));
|
||||
if (attr != null)
|
||||
{
|
||||
NodeInfoAttribute info = attr as NodeInfoAttribute;
|
||||
var node = Activator.CreateInstance(type);
|
||||
if(string.IsNullOrEmpty(info.MenuItem)) continue;
|
||||
|
||||
elements.Add(new SearchContextElement(node, info.MenuItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
foreach (var type in TypeCache.GetTypesWithAttribute<NodeInfoAttribute>())
|
||||
{
|
||||
var attr = type.GetCustomAttribute<NodeInfoAttribute>();
|
||||
NodeInfoAttribute info = attr as NodeInfoAttribute;
|
||||
var node = Activator.CreateInstance(type);
|
||||
if(string.IsNullOrEmpty(info.MenuItem)) continue;
|
||||
|
||||
elements.Add(new SearchContextElement(node, info.MenuItem));
|
||||
}
|
||||
|
||||
elements.Sort((entry1, entry2) =>
|
||||
{
|
||||
string[] splits1 = entry1.title.Split('/');
|
||||
string[] splits2 = entry2.title.Split('/');
|
||||
|
||||
for (int i = 0; i < splits1.Length; i++)
|
||||
{
|
||||
if (i >= splits2.Length) return 1;
|
||||
|
||||
int value = splits1[i].CompareTo(splits2[i]);
|
||||
if (value != 0)
|
||||
{
|
||||
if(splits1.Length != splits2.Length && (i == splits1.Length - 1 || i == splits2.Length - 1))
|
||||
return splits1.Length < splits2.Length ? 1 : -1;
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
List<string> groups = new List<string>();
|
||||
|
||||
foreach (var element in elements)
|
||||
{
|
||||
string[] entryTitle = element.title.Split('/');
|
||||
|
||||
string groupName = "";
|
||||
|
||||
for (int i = 0; i < entryTitle.Length - 1; i++)
|
||||
{
|
||||
groupName += entryTitle[i];
|
||||
if (!groups.Contains(groupName))
|
||||
{
|
||||
tree.Add(new SearchTreeGroupEntry(new GUIContent(groupName), i + 1));
|
||||
groups.Add(groupName);
|
||||
}
|
||||
groupName += '/';
|
||||
}
|
||||
|
||||
SearchTreeEntry entry = new SearchTreeEntry(new GUIContent(entryTitle.Last()));
|
||||
entry.level = entryTitle.Length;
|
||||
entry.userData = new SearchContextElement(element.target, element.title);
|
||||
tree.Add(entry);
|
||||
}
|
||||
|
||||
return tree;
|
||||
var node = Activator.CreateInstance(type);
|
||||
elements.Add(new SearchContextElement(node, attr.MenuItem));
|
||||
}
|
||||
|
||||
public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context)
|
||||
elements.Sort((entry1, entry2) =>
|
||||
{
|
||||
var mousePos = graph.ChangeCoordinatesTo(graph, context.screenMousePosition - graph.Window.position.position);
|
||||
var graphMousePosition = graph.contentViewContainer.WorldToLocal(mousePos);
|
||||
|
||||
SearchContextElement element = (SearchContextElement)SearchTreeEntry.userData;
|
||||
|
||||
BaseImageNode node = (BaseImageNode)element.target;
|
||||
node.SetPosition(new Rect(graphMousePosition, new Vector2()));
|
||||
graph.Add(node);
|
||||
node.asset = graph.asset;
|
||||
string[] splits1 = entry1.title.Split('/');
|
||||
string[] splits2 = entry2.title.Split('/');
|
||||
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < splits1.Length; i++)
|
||||
{
|
||||
if (i >= splits2.Length) return 1;
|
||||
int value = splits1[i].CompareTo(splits2[i]);
|
||||
if (value != 0)
|
||||
{
|
||||
if (splits1.Length != splits2.Length && (i == splits1.Length - 1 || i == splits2.Length - 1))
|
||||
return splits1.Length < splits2.Length ? 1 : -1;
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchContextElement
|
||||
{
|
||||
public object target;
|
||||
public string title;
|
||||
|
||||
public SearchContextElement(object target, string title)
|
||||
{
|
||||
this.target = target;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows;
|
||||
using ImageProcessingGraph.Editor.Windows;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEditor.Search;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
@ -20,7 +21,7 @@ namespace ImageProcessingGraph.Editor
|
||||
public Dictionary<string, ImageProcessingGraphNodeVisual> nodeDictionary;
|
||||
public Dictionary<Edge, GraphConnection> connectionDictionary;
|
||||
|
||||
internal ImageProcessingGraphSearchProvider searchProvider;
|
||||
// internal ImageProcessingGraphSearchProvider searchProvider;
|
||||
internal ImageProcessingGraphEdgeConnectorListener edgeConnectorListener;
|
||||
|
||||
private bool isDropdownEnabled = false;
|
||||
@ -37,8 +38,8 @@ namespace ImageProcessingGraph.Editor
|
||||
nodeDictionary = new Dictionary<string, ImageProcessingGraphNodeVisual>();
|
||||
connectionDictionary = new Dictionary<Edge, GraphConnection>();
|
||||
|
||||
searchProvider = ScriptableObject.CreateInstance<ImageProcessingGraphSearchProvider>();
|
||||
searchProvider.graph = this;
|
||||
// searchProvider = ScriptableObject.CreateInstance<ImageProcessingGraphSearchProvider>();
|
||||
// searchProvider.graph = this;
|
||||
|
||||
edgeConnectorListener = new ImageProcessingGraphEdgeConnectorListener(this);
|
||||
|
||||
@ -491,8 +492,10 @@ namespace ImageProcessingGraph.Editor
|
||||
|
||||
private void ShowSearchWindow(NodeCreationContext obj)
|
||||
{
|
||||
searchProvider.target = (VisualElement)focusController.focusedElement;
|
||||
SearchWindow.Open(new SearchWindowContext(obj.screenMousePosition), searchProvider);
|
||||
// searchProvider.target = (VisualElement)focusController.focusedElement;
|
||||
// SearchWindow.Open(new SearchWindowContext(obj.screenMousePosition), searchProvider);
|
||||
|
||||
SearchService.ShowContextual("IPT_Tree");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user