Creating Custom NodeViews - McManning/BlueGraph GitHub Wiki
Each node on the graph is rendered with a default BlueGraph.Editor.NodeView
UI Element. You can override this with your own custom view for a given type of node.
In an Editor folder add a file for the new view:
using BlueGraph.Editor;
[CustomNodeView(typeof(BlendNode))]
class BlendNodeView : NodeView
{
public override void OnInitialize()
{
// Here you can insert custom stylesheets, classes, UI Elements, etc.
StyleSheet uss = Resources.Load("Styles/BlendNodeView");
styleSheets.Add(uss);
AddToClassList("blend-node-view");
// You can get the target Node instance
var blendNode = Target as BlendNode;
}
}
The [CustomNodeView]
attribute tells the graph editor to override the default view with your implementation for every instance of BlendNode
on the graph.
OnInitialize
is called after the the view has been bound to a target BlueGraph.Node
instance and before it is added to the Canvas.
Supporting Custom Port Data Types
By default, custom classes and structs that you expose as ports can only connect to other ports of the same type or, for classes, to ports that represent an inherited class type.
You can expand supported connections by implementing IConvertible
in your class. Any type conversions allowed by the IConvertible
implementation will be considered when testing whether a new edge can be added between two ports.
For structs there is currently no custom conversion support.
USS Classes
When a custom data type is associated with a port the type's full path is used to construct a class name that is attached to that port in a USS-safe manner.
For example, if your custom type is MyGamesNamespace.Projectile
then the following USS can be used to set the color of any Projectile
port:
.portView.type-MyGamesNamespace-Projectile {
--port-color: #fdc727;
}
Additional classes are also automatically added based on the type:
.type-is-enumerable
if IEnumerable is a base class.type-is-collection
if ICollection is a base class.type-is-generic
if it's a generic.type-is-enum
if it's an enum.type-is-value
if it's a value type (e.g. struct, float, etc)