Home
  • Manual
  • Node Index
  • API
  • Changelog
Show / Hide Table of Contents
  • Tutorials
    • Creating your first map generator
      • 1. Creating your first map graph
      • 2. Running a graph at runtime
      • 3. Adding more nodes
      • 4. Object placement
    • Basic map types
      • • Cave-like maps
      • • Room-based maps
      • • Sample-based maps
      • • Combining map types
    • More Tutorials
      • • Using prefabs instead of tilemaps
      • • Changing tile/prefab/tilemap set probabilities (weighted random)
      • • Linking a named color set to tilesets/prefab sets
      • • Organizing nodes into groups
      • • Adding notes & comments
      • • Running a graph within a graph (Sub graphs)
      • • Tilemap Sets
      • • Optimization tips
      • • Static seed (daily challenges)
      • • Running a graph asynchronously/multi-threaded
      • • Object pooling
      • • Tips for rule tiles
      • • Saving and loading maps
    • Tutorials for coders
      • • Running graphs from scripts
      • • Output parameters
      • • Creating your own nodes
      • • Creating your own node views
      • • Adding a constant node type
  • Sample Project
  • Troubleshooting
  • Support

Creating your own node views

Once you've created your own node, you can create your own node view for it. By creating a node view for your custom node, you can add additional elements to display in the graph editor.

For example, you can add a preview image, like a lot of the built-in nodes have.

Here's how you create a custom node view:

using InsaneScatterbrain.ScriptGraph.Editor;
using UnityEditor.UIElements;
 
// Adding this attribute tells Map Graph that this class is a node view for nodes of type ExampleNode
[ScriptNodeView(typeof(ExampleNode))]
public class ExampleNodeView : ScriptNodeView
{
    public ExampleNodeView(ExampleNode node, ScriptGraphView graphView) : base(node, graphView)
    {
        // Here you can add UI elements to the view node.
        var label = new Label("Hello, Node View!");
        mainContainer.Add(label);

        // This is how to easily add a preview image to your node.
        // The callback should return the Texture2D that the preview image will display each time the node is processed.
        this.AddPreview<ExampleNode>(GetPreviewTexture);
    }
    
    private Texture2D GetPreviewTexture(ExampleNode node) => node.TextureData.ToTexture2D();
}
In This Article
Back to top Generated by DocFX