File size: 1,406 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Unity.VisualScripting
{
[UnitCategory("Graphs/Graph Nodes")]
public abstract class GetGraphs<TGraph, TGraphAsset, TMachine> : Unit
where TGraph : class, IGraph, new()
where TGraphAsset : Macro<TGraph>
where TMachine : Machine<TGraph, TGraphAsset>
{
/// <summary>
/// The GameObject to retrieve the graphs from.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
[NullMeansSelf]
public ValueInput gameObject { get; protected set; }
/// <summary>
/// The graph that is set on the GameObject.
/// </summary>
[DoNotSerialize]
[PortLabel("Graphs")]
[PortLabelHidden]
public ValueOutput graphList { get; protected set; }
protected override void Definition()
{
gameObject = ValueInput<GameObject>(nameof(gameObject), null).NullMeansSelf();
graphList = ValueOutput(nameof(graphList), Get);
}
List<TGraphAsset> Get(Flow flow)
{
var go = flow.GetValue<GameObject>(gameObject);
return go.GetComponents<TMachine>()
.Where(machine => go.GetComponent<TMachine>().nest.macro != null)
.Select(machine => machine.nest.macro)
.ToList();
}
}
}
|