1414// You should have received a copy of the GNU General Public License
1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17+ using System . Collections . Generic ;
1718using Unity . VisualScripting ;
1819using UnityEngine ;
1920
@@ -32,9 +33,19 @@ public class PulseCoilUnit : GleUnit
3233 [ PortLabelHidden ]
3334 public ControlOutput OutputTrigger ;
3435
36+ [ SerializeAs ( nameof ( idCount ) ) ]
37+ private int _idCount = 1 ;
38+
39+ [ DoNotSerialize ]
40+ [ Inspectable , UnitHeaderInspectable ( "Coil IDs" ) ]
41+ public int idCount
42+ {
43+ get => _idCount ;
44+ set => _idCount = Mathf . Clamp ( value , 1 , 10 ) ;
45+ }
46+
3547 [ DoNotSerialize ]
36- [ PortLabel ( "Coil ID" ) ]
37- public ValueInput Id { get ; private set ; }
48+ public List < ValueInput > Ids { get ; private set ; }
3849
3950 [ DoNotSerialize ]
4051 [ PortLabel ( "Duration (ms)" ) ]
@@ -45,10 +56,17 @@ protected override void Definition()
4556 InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
4657 OutputTrigger = ControlOutput ( nameof ( OutputTrigger ) ) ;
4758
48- Id = ValueInput < string > ( nameof ( Id ) , string . Empty ) ;
59+ Ids = new List < ValueInput > ( ) ;
60+
61+ for ( var i = 0 ; i < idCount ; i ++ ) {
62+ var id = ValueInput < string > ( "Coil ID " + ( i + 1 ) , string . Empty ) ;
63+ Ids . Add ( id ) ;
64+
65+ Requirement ( id , InputTrigger ) ;
66+ }
67+
4968 PulseDuration = ValueInput < int > ( nameof ( PulseDuration ) , 80 ) ;
5069
51- Requirement ( Id , InputTrigger ) ;
5270 Succession ( InputTrigger , OutputTrigger ) ;
5371 }
5472
@@ -60,15 +78,17 @@ private ControlOutput Process(Flow flow)
6078 }
6179
6280 if ( ! AssertPlayer ( flow ) ) {
63- Debug . LogError ( "Cannot find GLE ." ) ;
81+ Debug . LogError ( "Cannot find Player ." ) ;
6482 return OutputTrigger ;
6583 }
6684
67- var id = flow . GetValue < string > ( Id ) ;
68- var pulseDuration = flow . GetValue < int > ( PulseDuration ) ;
85+ foreach ( var id in Ids ) {
86+ var idValue = flow . GetValue < string > ( id ) ;
87+ var pulseDuration = flow . GetValue < int > ( PulseDuration ) ;
6988
70- Gle . SetCoil ( id , true ) ;
71- Player . ScheduleAction ( pulseDuration , ( ) => Gle . SetCoil ( id , false ) ) ;
89+ Gle . SetCoil ( idValue , true ) ;
90+ Player . ScheduleAction ( pulseDuration , ( ) => Gle . SetCoil ( idValue , false ) ) ;
91+ }
7292
7393 return OutputTrigger ;
7494 }
0 commit comments