Repository navigation
Expand file tree
/
Copy pathEventUnitWrapper.cs
More file actions
64 lines (52 loc) · 1.9 KB
/
Copy pathEventUnitWrapper.cs
File metadata and controls
64 lines (52 loc) · 1.9 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Meta Platforms, Inc. and affiliates.
using Meta.XR.Samples;
using Unity.VisualScripting;
namespace SpatialLingo.VisualScriptingUnits
{
[MetaCodeSample("SpatialLingo")]
public abstract class EventUnitWrapper<T> : EventUnit<T>
{
[DoNotSerialize] public ValueOutput Result;
protected abstract string EventName { get; }
protected override bool register => true;
public override EventHook GetHook(GraphReference reference) => new(EventName);
protected override void Definition()
{
base.Definition();
Result = ValueOutput<T>(nameof(Result));
}
protected override void AssignArguments(Flow flow, T data)
{
flow.SetValue(Result, data);
}
}
[MetaCodeSample("SpatialLingo")]
public abstract class EventUnitWrapper : EventUnit<EmptyEventArgs>
{
protected abstract string EventName { get; }
protected override bool register => true;
public override EventHook GetHook(GraphReference reference) => new(EventName);
}
[MetaCodeSample("SpatialLingo")]
public class TriggerCustomEvent : Unit
{
[DoNotSerialize]
[PortLabelHidden]
public ControlInput InputTrigger { get; private set; }
[DoNotSerialize]
[PortLabelHidden]
public ControlOutput OutputTrigger { get; private set; }
[DoNotSerialize] public ValueInput EventName { get; private set; }
protected override void Definition()
{
InputTrigger = ControlInput(nameof(InputTrigger), Trigger);
OutputTrigger = ControlOutput(nameof(OutputTrigger));
EventName = ValueInput(nameof(EventName), string.Empty);
}
private ControlOutput Trigger(Flow flow)
{
EventBus.Trigger(flow.GetValue<string>(EventName));
return OutputTrigger;
}
}
}