Skip to content

Commit accdff8

Browse files
committed
Make TestUnit executable with a GUI button
1 parent 30395c0 commit accdff8

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

Editor/TestUnitDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public TestUnitDescriptor(TEvent @event) : base(@event) { }
1717
// }
1818
protected override string DefinedSummary()
1919
{
20-
return "Double click to execute this node."
20+
return "Click on the Run button to execute this node."
2121
+ "\nWorks in both Edit Mode and Play Mode."
2222
+ "\nNote 1: Coroutine tests are only usable in Play Mode."
2323
+ "\nNote 2: Exceptions in edit mode won't go away on their own. "

Editor/TestUnitWidget.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,26 @@ namespace CHM.VisualScriptingPlus.Editor
99
[Widget(typeof(TestUnit))]
1010
public class TestUnitWidget : UnitWidget<TestUnit>
1111
{
12+
public override bool foregroundRequiresInput => true;
1213
public TestUnitWidget(FlowCanvas canvas, TestUnit unit) : base(canvas, unit)
1314
{
1415
}
15-
protected override void OnDoubleClick()
16+
17+
public override void DrawForeground()
1618
{
17-
base.OnDoubleClick();
18-
Execute();
19+
base.DrawForeground();
20+
// We implement the button here instead of using a custom button attribute
21+
// on TestUnit, because crucially a node needs a GraphReference when triggered.
22+
// Units don't have direct access to GraphReferences, but widgets do.
23+
Rect buttonPosition = portsBackgroundPosition;
24+
Vector2 margin = Vector2.one * 8;
25+
buttonPosition.position += margin / 2;
26+
buttonPosition.size -= margin;
27+
buttonPosition.size -= Vector2.right * 22;
28+
if(GUI.Button(buttonPosition, "Run"))
29+
{
30+
Execute();
31+
}
1932
}
2033

2134
private void Execute()
@@ -27,10 +40,12 @@ private void Execute()
2740
}
2841
unit.Trigger(reference, 0);
2942
}
43+
3044
private void ClearExceptions()
3145
{
3246
GraphUtility.ClearExceptionsInActiveWindow();
3347
}
48+
3449
protected override IEnumerable<DropdownOption> contextOptions
3550
{
3651
get

Runtime/TestUnit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ namespace CHM.VisualScriptingPlus
99
[UnitCategory("Events\\VSPlus")]//Set the path to find the node in the fuzzy finder as Events > My Events.
1010
public class TestUnit : EventUnit<int>
1111
{
12-
protected override bool register => true;
12+
protected override bool register => false;
1313
}
1414
}

0 commit comments

Comments
 (0)