1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
1717using System . Collections . Generic ;
18+ using System . Collections . ObjectModel ;
1819using Unity . VisualScripting ;
1920using UnityEngine ;
2021
@@ -23,7 +24,7 @@ namespace VisualPinball.Unity.VisualScripting
2324 [ UnitTitle ( "Pulse Coil" ) ]
2425 [ UnitSurtitle ( "Gamelogic Engine" ) ]
2526 [ UnitCategory ( "Visual Pinball" ) ]
26- public class PulseCoilUnit : GleUnit
27+ public class PulseCoilUnit : GleUnit , IMultiInputUnit
2728 {
2829 [ DoNotSerialize ]
2930 [ PortLabelHidden ]
@@ -45,7 +46,7 @@ public int inputCount
4546 }
4647
4748 [ DoNotSerialize ]
48- public List < ValueInput > Items { get ; private set ; }
49+ public ReadOnlyCollection < ValueInput > multiInputs { get ; private set ; }
4950
5051 [ DoNotSerialize ]
5152 [ PortLabel ( "Duration (ms)" ) ]
@@ -56,13 +57,15 @@ protected override void Definition()
5657 InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
5758 OutputTrigger = ControlOutput ( nameof ( OutputTrigger ) ) ;
5859
59- Items = new List < ValueInput > ( ) ;
60+ var _multiInputs = new List < ValueInput > ( ) ;
61+
62+ multiInputs = _multiInputs . AsReadOnly ( ) ;
6063
6164 for ( var i = 0 ; i < inputCount ; i ++ ) {
62- var item = ValueInput ( i . ToString ( ) , string . Empty ) ;
63- Items . Add ( item ) ;
65+ var input = ValueInput ( i . ToString ( ) , string . Empty ) ;
66+ _multiInputs . Add ( input ) ;
6467
65- Requirement ( item , InputTrigger ) ;
68+ Requirement ( input , InputTrigger ) ;
6669 }
6770
6871 PulseDuration = ValueInput ( nameof ( PulseDuration ) , 80 ) ;
@@ -84,11 +87,10 @@ private ControlOutput Process(Flow flow)
8487
8588 var pulseDuration = flow . GetValue < int > ( PulseDuration ) ;
8689
87- foreach ( var item in Items ) {
88- var id = flow . GetValue < string > ( item ) ;
89-
90- Gle . SetCoil ( id , true ) ;
91- Player . ScheduleAction ( pulseDuration , ( ) => Gle . SetCoil ( id , false ) ) ;
90+ foreach ( var input in multiInputs ) {
91+ var coilId = flow . GetValue < string > ( input ) ;
92+ Gle . SetCoil ( coilId , true ) ;
93+ Player . ScheduleAction ( pulseDuration , ( ) => Gle . SetCoil ( coilId , false ) ) ;
9294 }
9395
9496 return OutputTrigger ;
0 commit comments