11using UnityEngine ;
22using Unity . VisualScripting ;
3+ using System . Collections ;
4+ using System ;
35
4- namespace Bolt . Addons . Community . Fundamentals
6+ namespace Unity . VisualScripting . Community
57{
68 [ UnitTitle ( "If" ) ]
79 [ UnitCategory ( "Community/Control" ) ]
810 [ TypeIcon ( typeof ( Unity . VisualScripting . If ) ) ]
9- public class If : Unit
11+ [ RenamedFrom ( "Bolt.Addons.Community.Fundamentals.If" ) ]
12+ [ RenamedFrom ( "Bolt.Addons.Community.Fundamentals.BetterIf" ) ]
13+ public class BetterIf : Unit
1014 {
1115 [ DoNotSerialize ]
1216 [ PortLabelHidden ]
@@ -21,11 +25,12 @@ public class If : Unit
2125 [ DoNotSerialize ]
2226 public ControlOutput False ;
2327 [ DoNotSerialize ]
28+ [ PortLabel ( "Next" ) ]
2429 public ControlOutput Finished ;
2530
2631 protected override void Definition ( )
2732 {
28- In = ControlInput ( nameof ( In ) , Enter ) ;
33+ In = ControlInputCoroutine ( nameof ( In ) , Enter , EnterCoroutine ) ;
2934 True = ControlOutput ( nameof ( True ) ) ;
3035 False = ControlOutput ( nameof ( False ) ) ;
3136 Finished = ControlOutput ( nameof ( Finished ) ) ;
@@ -35,32 +40,40 @@ protected override void Definition()
3540 Succession ( In , True ) ;
3641 Succession ( In , False ) ;
3742 Succession ( In , Finished ) ;
43+ Requirement ( Condition , In ) ;
3844 }
3945
40- private ControlOutput Enter ( Flow flow )
46+ private IEnumerator EnterCoroutine ( Flow flow )
4147 {
4248 bool condition = flow . GetValue < bool > ( Condition ) ;
4349
44- if ( flow . isCoroutine )
50+ if ( condition )
4551 {
46- GraphReference reference = flow . stack . ToReference ( ) ;
47- Flow _flow = Flow . New ( reference ) ;
48- _flow . StartCoroutine ( Finished ) ;
52+ yield return True ;
4953 }
5054 else
5155 {
52- flow . Invoke ( Finished ) ;
56+ yield return False ;
5357 }
5458
59+ yield return Finished ;
60+ }
61+
62+ private ControlOutput Enter ( Flow flow )
63+ {
64+ bool condition = flow . GetValue < bool > ( Condition ) ;
65+
5566 if ( condition )
5667 {
57- return True ;
68+ flow . Invoke ( True ) ;
5869 }
5970 else
6071 {
61- return False ;
72+ flow . Invoke ( False ) ;
6273 }
63-
74+
75+ return Finished ;
76+
6477 }
65- }
78+ }
6679}
0 commit comments