Skip to content

Commit a4fc312

Browse files
committed
Update pinball event nodes.
1 parent 1eb88cd commit a4fc312

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
namespace VisualPinball.Unity.VisualScripting.Editor
2626
{
2727
[Widget(typeof(PinballEventUnit))]
28-
public sealed class CustomEventUnitWidget : UnitWidget<PinballEventUnit>
28+
public sealed class PinballEventUnitWidget : GleUnitWidget<PinballEventUnit>
2929
{
30-
public CustomEventUnitWidget(FlowCanvas canvas, PinballEventUnit unit) : base(canvas, unit)
30+
public PinballEventUnitWidget(FlowCanvas canvas, PinballEventUnit unit) : base(canvas, unit)
3131
{
3232
}
3333
}

Editor/Widgets/CustomEventUnitWidget.cs.meta renamed to Editor/Widgets/PinballEventUnitWidget.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
// ReSharper disable UnusedType.Global
18+
19+
using Unity.VisualScripting;
20+
21+
namespace VisualPinball.Unity.VisualScripting.Editor
22+
{
23+
[Widget(typeof(TriggerPinballEventUnit))]
24+
public sealed class TriggerPinballEventUnitWidget : GleUnitWidget<TriggerPinballEventUnit>
25+
{
26+
public TriggerPinballEventUnitWidget(FlowCanvas canvas, TriggerPinballEventUnit unit) : base(canvas, unit)
27+
{
28+
}
29+
}
30+
}

Editor/Widgets/TriggerPinballEventUnitWidget.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Nodes/Event/PinballEventUnit.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ namespace VisualPinball.Unity.VisualScripting
2828
/// </summary>
2929
[UnitTitle("On Pinball Event")]
3030
[UnitCategory("Events/Visual Pinball")]
31-
public class PinballEventUnit : GameObjectEventUnit<PinballEventArgs>
31+
public class PinballEventUnit : GleEventUnit<PinballEventArgs>
3232
{
3333
[Serialize, Inspectable, UnitHeaderInspectable]
3434
public EventDefinition Event { get; set; }
3535

36-
public override Type MessageListenerType => null;
37-
protected override string hookName => VisualScriptingEventNames.PinballEvent;
38-
3936
[SerializeAs(nameof(argumentCount))]
4037
private int _argumentCount;
4138

@@ -50,6 +47,9 @@ public int argumentCount
5047
[DoNotSerialize]
5148
public List<ValueOutput> argumentPorts { get; } = new List<ValueOutput>();
5249

50+
protected override bool register => true;
51+
public override EventHook GetHook(GraphReference reference) => new(VisualScriptingEventNames.PinballEvent);
52+
5353
protected override void Definition()
5454
{
5555
base.Definition();
@@ -71,9 +71,9 @@ protected override void AssignArguments(Flow flow, PinballEventArgs args)
7171
}
7272
}
7373

74-
public static void Trigger(GameObject target, string name, params object[] args)
74+
public static void Trigger(GameObject target, string id, params object[] args)
7575
{
76-
EventBus.Trigger(VisualScriptingEventNames.PinballEvent, target, new PinballEventArgs(name, args));
76+
EventBus.Trigger(VisualScriptingEventNames.PinballEvent, target, new PinballEventArgs(id, args));
7777
}
7878
}
7979

Runtime/Nodes/Event/TriggerPinballEventUnit.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace VisualPinball.Unity.VisualScripting
3131
[UnitShortTitle("Trigger")]
3232
[TypeIcon(typeof(CustomEvent))]
3333
[UnitCategory("Events/Visual Pinball")]
34-
public sealed class TriggerPinballEventUnit : Unit
34+
public sealed class TriggerPinballEventUnit : GleUnit
3535
{
3636
[Serialize, Inspectable, UnitHeaderInspectable]
3737
public EventDefinition Event { get; set; }
@@ -57,39 +57,30 @@ public int argumentCount {
5757
[PortLabelHidden]
5858
public ControlOutput OutputTrigger { get; private set; }
5959

60-
/// <summary>
61-
/// The target of the event.
62-
/// </summary>
63-
[DoNotSerialize]
64-
[PortLabelHidden]
65-
[NullMeansSelf]
66-
public ValueInput target { get; private set; }
67-
6860
protected override void Definition()
6961
{
7062
InputTrigger = ControlInput(nameof(InputTrigger), Trigger);
7163
OutputTrigger = ControlOutput(nameof(OutputTrigger));
7264

73-
74-
target = ValueInput<GameObject>(nameof(target), null).NullMeansSelf();
7565
Arguments = new List<ValueInput>();
76-
7766
for (var i = 0; i < argumentCount; i++) {
7867
var argument = ValueInput<object>("argument_" + i);
7968
Arguments.Add(argument);
8069
Requirement(argument, InputTrigger);
8170
}
8271

83-
Requirement(target, InputTrigger);
8472
Succession(InputTrigger, OutputTrigger);
8573
}
8674

8775
private ControlOutput Trigger(Flow flow)
8876
{
89-
var t = flow.GetValue<GameObject>(this.target);
90-
var args = Arguments.Select(flow.GetConvertedValue).ToArray();
77+
if (!AssertVsGle(flow)) {
78+
Debug.LogError("Cannot find GLE.");
79+
return OutputTrigger;
80+
}
9181

92-
PinballEventUnit.Trigger(t, Event.Id, args);
82+
var args = Arguments.Select(flow.GetConvertedValue).ToArray();
83+
PinballEventUnit.Trigger(VsGle.gameObject, Event.Id, args);
9384

9485
return OutputTrigger;
9586
}

0 commit comments

Comments
 (0)