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 ;
18+ using System . Collections . ObjectModel ;
1719using Unity . VisualScripting ;
1820using UnityEngine ;
1921
@@ -23,7 +25,7 @@ namespace VisualPinball.Unity.VisualScripting
2325 [ UnitTitle ( "Set Lamp (ID, on/off)" ) ]
2426 [ UnitSurtitle ( "Gamelogic Engine" ) ]
2527 [ UnitCategory ( "Visual Pinball" ) ]
26- public class SetLampEnabledUnit : GleUnit
28+ public class SetLampEnabledUnit : GleUnit , IMultiInputUnit
2729 {
2830 [ DoNotSerialize ]
2931 [ PortLabelHidden ]
@@ -33,9 +35,19 @@ public class SetLampEnabledUnit : GleUnit
3335 [ PortLabelHidden ]
3436 public ControlOutput OutputTrigger ;
3537
38+ [ SerializeAs ( nameof ( inputCount ) ) ]
39+ private int _inputCount = 1 ;
40+
41+ [ DoNotSerialize ]
42+ [ Inspectable , UnitHeaderInspectable ( "Lamp IDs" ) ]
43+ public int inputCount
44+ {
45+ get => _inputCount ;
46+ set => _inputCount = Mathf . Clamp ( value , 1 , 10 ) ;
47+ }
48+
3649 [ DoNotSerialize ]
37- [ PortLabel ( "Lamp ID" ) ]
38- public ValueInput Id { get ; private set ; }
50+ public ReadOnlyCollection < ValueInput > multiInputs { get ; private set ; }
3951
4052 [ DoNotSerialize ]
4153 [ PortLabel ( "Is Enabled" ) ]
@@ -46,10 +58,19 @@ protected override void Definition()
4658 InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
4759 OutputTrigger = ControlOutput ( nameof ( OutputTrigger ) ) ;
4860
49- Id = ValueInput ( nameof ( Id ) , string . Empty ) ;
61+ var _multiInputs = new List < ValueInput > ( ) ;
62+
63+ multiInputs = _multiInputs . AsReadOnly ( ) ;
64+
65+ for ( var i = 0 ; i < inputCount ; i ++ ) {
66+ var input = ValueInput ( i . ToString ( ) , string . Empty ) ;
67+ _multiInputs . Add ( input ) ;
68+
69+ Requirement ( input , InputTrigger ) ;
70+ }
71+
5072 IsEnabled = ValueInput ( nameof ( IsEnabled ) , false ) ;
5173
52- Requirement ( Id , InputTrigger ) ;
5374 Succession ( InputTrigger , OutputTrigger ) ;
5475 }
5576
@@ -60,10 +81,12 @@ private ControlOutput Process(Flow flow)
6081 return OutputTrigger ;
6182 }
6283
63- var id = flow . GetValue < string > ( Id ) ;
6484 var isEnabled = flow . GetValue < bool > ( IsEnabled ) ;
6585
66- Gle . SetLamp ( id , isEnabled ? 255f : 0f ) ;
86+ foreach ( var input in multiInputs ) {
87+ var lampId = flow . GetValue < string > ( input ) ;
88+ Gle . SetLamp ( lampId , isEnabled ? 255f : 0f ) ;
89+ }
6790
6891 return OutputTrigger ;
6992 }
0 commit comments