Home
  • Manual
  • Node Index
  • API
  • Changelog
Search Results for

    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
        • • Generating prefabs
        • • Tile/prefab/tilemap set weights
        • • Syncing named color sets
        • • Groups
        • • Notes & comments
        • • Sub graphs
        • • Tilemap Sets
        • • Optimization tips
        • • Static seed (daily challenges)
        • • Running a graph asynchronously or multi-threaded
        • • Object pooling
        • • Tips for rule tiles
        • • Saving and loading maps
      • Tutorials for coders
        • • Running graphs from scripts
        • • Output parameters
        • • Custom nodes
        • • Custom node views
        • • Adding a constant node type
        • • Custom styling for the graph editor
        • • Dependencies for custom nodes
    • Sample Project
    • Troubleshooting
    • Support

    Adding a constant node type

    In order to create a constant node of a certain type, a node view for that particular type needs to be defined.

    Here's an example of a constant node view for an enum:

    using System;
    using InsaneScatterbrain.ScriptGraph;
    using InsaneScatterbrain.ScriptGraph.Editor;
    using UnityEditor.UIElements;
    
    // Adding this attribute adds the node view to the graph's context menu under "Constant"
    [ConstantNodeView(typeof(MyEnum))]
    public class MyEnumConstantNodeView : ConstantNodeView
    {
        public MyEnumConstantNodeView(ConstantNode node, ScriptGraphView graphView) : base(node, graphView)
        {
            var myEnumValue = (MyEnum) node.Value;
            // AddDefaultField creates the EnumField and makes sure that value changes are persisted.
            var field = AddDefaultField<Enum, EnumField>(myEnumValue);  
        
            // Init needs to be called to make the field aware of the enum's specific type.
            // The field will be empty otherwise.
            field.Init(myEnumValue);    
        }
    }
    
    In This Article
    Back to top Generated by DocFX