Unity Visual Script 写一个可以自动获取 Graph 变量的节点

使用c# 封装一个获取Graph 对象的节点,使得不需要每次都输入变量名,避免出错,提高效率

using System.Collections;  
using System.Collections.Generic;  
using TreeEditor;  
using Unity.VisualScripting;  
using UnityEngine;  
using static UnityEditorInternal.ReorderableList;

[UnitTitle("Get Map Item")]
[UnitCategory("Game\\GetVariable")]
MapItem of the current node")]  
[TypeIcon(typeof(This))]
public class VS_FlowLogic_GetMapItem : Unit  
{
    [DoNotSerialize]
    public ValueOutput mapItem { get; set; }

    private MapItem  mapItemCache;

    protected bool IsDefined(Flow flow)
    {
        return GetDeclarations(flow)?.IsDefined("MapItem") ?? false;
    }

    protected override void Definition()
    {
        mapItem = ValueOutput<MapItem>(nameof(mapItem), Get).PredictableIf(IsDefined);
    }


    protected  MapItem Get(Flow flow)
    {
        return GetDeclarations(flow).Get<MapItem>("MapItem");
    }

    protected VariableDeclarations GetDeclarations(Flow flow)
    {
        return Variables.Graph(flow.stack);
    }
}

截图

kisence

潮落江平未有风。