Hey all,
I’m presently converting many of my editor tools over to use the new UIElements.
Many of my tools use node based graphs and I’m eager to make use of the experimental GraphView system to handle those tools, since it has support for tons of features that my own graphs didn’t (like good looking zooming!
)
I’ll be honest: I’m out of my depth. I’ve seen rygo6’s example system, and I’ve been picking my way through the code on the Shader Graph and VFX Graph githubs, but it is a lot to take in.
Here’s what I was hoping: Is there anyone who can provide me a thorough, but bare-bones example?
How would I get this example code working to the point that I can see a GraphView with a boring old labeled node?
public class TestGraphWindow : EditorWindow
{
public static void OpenWindow()
{
TestGraphWindow wnd = GetWindow<TestGraphWindow>();
wnd.titleContent = new GUIContent("Test Graph Window");
wnd.CreateElement();
}
private void CreateElement()
{
TestGraphView graphView = new TestGraphView() { name = "Graph View" };
graphView.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/TestGraphView.uss"));
GridBackground gridBackground = new GridBackground();
gridBackground.name = "Grid";
graphView.Add(gridBackground);
graphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale);
graphView.AddManipulator(new ContentDragger());
graphView.AddManipulator(new SelectionDragger());
graphView.AddManipulator(new RectangleSelector());
graphView.AddManipulator(new ClickSelector());
rootVisualElement.Add(graphView);
TestNode exampleNode = new TestNode() { name = "Example Node" };
exampleNode.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/TestNode.uss"));
graphView.AddElement(exampleNode);
}
}
Right now, this seems to be showing me the gray background of the grid background, but no node. I have experimented enough to find that I can add a button to the node and if I hunt, I can find that button and successfully click it… I just can’t see the node at all.
So that’s as far as I’m trying get right now. No ports, inputs, outputs, or edges. Even the graph view manipulators are extra: I don’t mind removing them if that helps me get this first part working.
So far, I just want to make a GraphView named “GraphView”, with a grid background and an example node called “Example Node”.
I just want a gray box of a node with a label that reads “Example Node”. And that’s all. Just so I have a good toe in the water to start from.
A few questions:
-What, if any, UXML files might I need?
-What info do I need in TestGraphView.uss and TestNode.uss?
Thank you, genuinely, to any kind soul that can help.
