1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
1717using Unity . VisualScripting ;
18+ using UnityEngine ;
1819
1920namespace VisualPinball . Unity . VisualScripting
2021{
@@ -24,27 +25,49 @@ public class SetCoilUnit : GleUnit
2425 {
2526 [ DoNotSerialize ]
2627 [ PortLabelHidden ]
27- public ControlInput inputTrigger ;
28+ public ControlInput InputTrigger ;
2829
2930 [ DoNotSerialize ]
3031 [ PortLabelHidden ]
31- public ControlOutput outputTrigger ;
32+ public ControlOutput OutputTrigger ;
3233
3334 [ DoNotSerialize ]
3435 [ PortLabel ( "Coil ID" ) ]
35- public ValueInput id { get ; private set ; }
36+ public ValueInput Id { get ; private set ; }
3637
3738 [ DoNotSerialize ]
3839 [ PortLabel ( "Value" ) ]
39- public ValueInput enabled { get ; private set ; }
40+ public ValueInput IsEnabled { get ; private set ; }
4041
4142 protected override void Definition ( )
4243 {
43- inputTrigger = ControlInput ( nameof ( inputTrigger ) , _ => outputTrigger ) ;
44- outputTrigger = ControlOutput ( nameof ( outputTrigger ) ) ;
44+ InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
45+ OutputTrigger = ControlOutput ( nameof ( OutputTrigger ) ) ;
4546
46- id = ValueInput < string > ( nameof ( id ) , string . Empty ) ;
47- enabled = ValueInput < bool > ( nameof ( enabled ) , false ) ;
47+ Id = ValueInput < string > ( nameof ( Id ) , string . Empty ) ;
48+ IsEnabled = ValueInput < bool > ( nameof ( IsEnabled ) , false ) ;
49+
50+ Requirement ( Id , InputTrigger ) ;
51+ Succession ( InputTrigger , OutputTrigger ) ;
52+ }
53+ private ControlOutput Process ( Flow flow )
54+ {
55+ var gle = flow . stack . gameObject . GetComponentInParent < VisualScriptingGamelogicEngine > ( ) ;
56+
57+ if ( gle != null ) {
58+
59+ var id = flow . GetValue < string > ( Id ) ;
60+ var isEnabled = flow . GetValue < bool > ( IsEnabled ) ;
61+
62+ gle . SetCoil ( id , isEnabled ) ;
63+
64+ } else {
65+ Debug . LogError ( "Cannot find GLE." ) ;
66+ }
67+
68+ return OutputTrigger ;
4869 }
70+
71+
4972 }
5073}
0 commit comments