first commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[UnitCategory("Graphs/Graph Nodes")]
|
||||
public abstract class GetGraph<TGraph, TGraphAsset, TMachine> : Unit
|
||||
where TGraph : class, IGraph, new()
|
||||
where TGraphAsset : Macro<TGraph>
|
||||
where TMachine : Machine<TGraph, TGraphAsset>
|
||||
{
|
||||
/// <summary>
|
||||
/// The GameObject to retrieve the graph from.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
[NullMeansSelf]
|
||||
public ValueInput gameObject { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The graph that is set on the GameObject.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Graph")]
|
||||
[PortLabelHidden]
|
||||
public ValueOutput graphOutput { get; protected set; }
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
gameObject = ValueInput<GameObject>(nameof(gameObject), null).NullMeansSelf();
|
||||
graphOutput = ValueOutput(nameof(graphOutput), Get);
|
||||
}
|
||||
|
||||
TGraphAsset Get(Flow flow)
|
||||
{
|
||||
var go = flow.GetValue<GameObject>(gameObject);
|
||||
return go.GetComponent<TMachine>().nest.macro;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 682aa02f705de452d8a79077d532a627
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d09df1476ce5a4e72af8be7f3006d3fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a ScriptGraphAsset from a GameObject
|
||||
/// </summary>
|
||||
[TypeIcon(typeof(FlowGraph))]
|
||||
public class GetScriptGraph : GetGraph<FlowGraph, ScriptGraphAsset, ScriptMachine> { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0617241f63fdf4b819789715e39c4a90
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a list of all the ScriptGraphs from a GameObject
|
||||
/// </summary>
|
||||
[TypeIcon(typeof(FlowGraph))]
|
||||
public class GetScriptGraphs : GetGraphs<FlowGraph, ScriptGraphAsset, ScriptMachine> { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1741ba912c026413193538282d720958
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[UnitCategory("Graphs/Graph Nodes")]
|
||||
public abstract class HasGraph<TGraph, TMacro, TMachine> : Unit
|
||||
where TGraph : class, IGraph, new()
|
||||
where TMacro : Macro<TGraph>
|
||||
where TMachine : Machine<TGraph, TMacro>
|
||||
{
|
||||
/// <summary>
|
||||
/// The entry point for the node.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ControlInput enter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The GameObject or the Machine where to look for the graph.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
[NullMeansSelf]
|
||||
public ValueInput target { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Graph to look for.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Graph")]
|
||||
[PortLabelHidden]
|
||||
public ValueInput graphInput { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if a Graph if found.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Has Graph")]
|
||||
[PortLabelHidden]
|
||||
public ValueOutput hasGraphOutput { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The action to execute once the graph has been set.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ControlOutput exit { get; private set; }
|
||||
|
||||
protected abstract bool isGameObject { get; }
|
||||
Type targetType => isGameObject ? typeof(GameObject) : typeof(TMachine);
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
enter = ControlInput(nameof(enter), TriggerHasGraph);
|
||||
target = ValueInput(targetType, nameof(target)).NullMeansSelf();
|
||||
target.SetDefaultValue(targetType.PseudoDefault());
|
||||
|
||||
graphInput = ValueInput<TMacro>(nameof(graphInput), null);
|
||||
hasGraphOutput = ValueOutput(nameof(hasGraphOutput), OutputHasGraph);
|
||||
exit = ControlOutput(nameof(exit));
|
||||
|
||||
Requirement(graphInput, enter);
|
||||
Assignment(enter, hasGraphOutput);
|
||||
Succession(enter, exit);
|
||||
}
|
||||
|
||||
ControlOutput TriggerHasGraph(Flow flow)
|
||||
{
|
||||
flow.SetValue(hasGraphOutput, OutputHasGraph(flow));
|
||||
return exit;
|
||||
}
|
||||
|
||||
bool OutputHasGraph(Flow flow)
|
||||
{
|
||||
var macro = flow.GetValue<TMacro>(graphInput);
|
||||
var targetValue = flow.GetValue(target, targetType);
|
||||
|
||||
if (targetValue is GameObject gameObject)
|
||||
{
|
||||
if (gameObject != null)
|
||||
{
|
||||
var stateMachines = gameObject.GetComponents<TMachine>();
|
||||
macro = flow.GetValue<TMacro>(graphInput);
|
||||
|
||||
return stateMachines
|
||||
.Where(currentMachine => currentMachine != null)
|
||||
.Any(currentMachine => currentMachine.graph != null && currentMachine.graph.Equals(macro.graph));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TMachine machine = flow.GetValue<TMachine>(target);
|
||||
|
||||
if (machine.graph != null && machine.graph.Equals(macro.graph))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a3ffd951e0554203aff7d10d1a9b2f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if a GameObject or ScriptMachine has a ScriptGraph
|
||||
/// </summary>
|
||||
[TypeIcon(typeof(FlowGraph))]
|
||||
[UnitCategory("Graphs/Graph Nodes")]
|
||||
public sealed class HasScriptGraph : HasGraph<FlowGraph, ScriptGraphAsset, ScriptMachine>
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of object that handles the graph.
|
||||
/// </summary>
|
||||
[Serialize, Inspectable, UnitHeaderInspectable, UsedImplicitly]
|
||||
public ScriptGraphContainerType containerType { get; set; }
|
||||
|
||||
protected override bool isGameObject => containerType == ScriptGraphContainerType.GameObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f359ec5aa5009497db03289f98400d76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
public enum ScriptGraphContainerType
|
||||
{
|
||||
GameObject,
|
||||
ScriptMachine
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ad0f7bc8a1f5415dbd2bf02efc850bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
[UnitCategory("Graphs/Graph Nodes")]
|
||||
public abstract class SetGraph<TGraph, TMacro, TMachine> : Unit
|
||||
where TGraph : class, IGraph, new()
|
||||
where TMacro : Macro<TGraph>
|
||||
where TMachine : Machine<TGraph, TMacro>
|
||||
{
|
||||
/// <summary>
|
||||
/// The entry point for the node.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ControlInput enter { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The GameObject or the ScriptMachine where the graph will be set.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
[NullMeansSelf]
|
||||
public ValueInput target { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The script graph.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Graph")]
|
||||
[PortLabelHidden]
|
||||
public ValueInput graphInput { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The graph that has been set to the ScriptMachine.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabel("Graph")]
|
||||
[PortLabelHidden]
|
||||
public ValueOutput graphOutput { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The action to execute once the graph has been set.
|
||||
/// </summary>
|
||||
[DoNotSerialize]
|
||||
[PortLabelHidden]
|
||||
public ControlOutput exit { get; protected set; }
|
||||
|
||||
protected abstract bool isGameObject { get; }
|
||||
Type targetType => isGameObject ? typeof(GameObject) : typeof(TMachine);
|
||||
|
||||
protected override void Definition()
|
||||
{
|
||||
enter = ControlInput(nameof(enter), SetMacro);
|
||||
target = ValueInput(targetType, nameof(target)).NullMeansSelf();
|
||||
target.SetDefaultValue(targetType.PseudoDefault());
|
||||
|
||||
graphInput = ValueInput<TMacro>(nameof(graphInput), null);
|
||||
graphOutput = ValueOutput<TMacro>(nameof(graphOutput));
|
||||
exit = ControlOutput(nameof(exit));
|
||||
|
||||
Requirement(graphInput, enter);
|
||||
Assignment(enter, graphOutput);
|
||||
Succession(enter, exit);
|
||||
}
|
||||
|
||||
ControlOutput SetMacro(Flow flow)
|
||||
{
|
||||
var macro = flow.GetValue<TMacro>(graphInput);
|
||||
var targetValue = flow.GetValue(target, targetType);
|
||||
|
||||
if (targetValue is GameObject go)
|
||||
{
|
||||
go.GetComponent<TMachine>().nest.SwitchToMacro(macro);
|
||||
}
|
||||
else
|
||||
{
|
||||
((TMachine)targetValue).nest.SwitchToMacro(macro);
|
||||
}
|
||||
|
||||
flow.SetValue(graphOutput, macro);
|
||||
|
||||
return exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8e5de80638a4adfa1d2630c14b86f4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Unity.VisualScripting
|
||||
{
|
||||
/// <summary>
|
||||
/// Set a ScriptGraph to a ScriptMachine
|
||||
/// </summary>
|
||||
[TypeIcon(typeof(FlowGraph))]
|
||||
public sealed class SetScriptGraph : SetGraph<FlowGraph, ScriptGraphAsset, ScriptMachine>
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of object that handles the graph.
|
||||
/// </summary>
|
||||
[Serialize, Inspectable, UnitHeaderInspectable, UsedImplicitly]
|
||||
public ScriptGraphContainerType containerType { get; set; }
|
||||
|
||||
protected override bool isGameObject => containerType == ScriptGraphContainerType.GameObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 596f580b21e640b9bf2f5d49c8c6a689
|
||||
timeCreated: 1618342367
|
||||
Reference in New Issue
Block a user