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, Intensity)" ) ]
2426 [ UnitSurtitle ( "Gamelogic Engine" ) ]
2527 [ UnitCategory ( "Visual Pinball" ) ]
26- public class SetLampUnit : GleUnit
28+ public class SetLampUnit : GleUnit , IMultiInputUnit
2729 {
2830 [ DoNotSerialize ]
2931 [ PortLabelHidden ]
@@ -33,9 +35,19 @@ public class SetLampUnit : GleUnit
3335 [ PortLabelHidden ]
3436 public ControlOutput OutputTrigger ;
3537
38+ [ SerializeAs ( nameof ( inputCount ) ) ]
39+ private int _inputCount = 1 ;
40+
3641 [ DoNotSerialize ]
37- [ PortLabel ( "Lamp ID" ) ]
38- public ValueInput Id { get ; private set ; }
42+ [ Inspectable , UnitHeaderInspectable ( "Lamp IDs" ) ]
43+ public int inputCount
44+ {
45+ get => _inputCount ;
46+ set => _inputCount = Mathf . Clamp ( value , 1 , 10 ) ;
47+ }
48+
49+ [ DoNotSerialize ]
50+ public ReadOnlyCollection < ValueInput > multiInputs { get ; private set ; }
3951
4052 [ DoNotSerialize ]
4153 [ PortLabel ( "Value" ) ]
@@ -46,26 +58,36 @@ protected override void Definition()
4658 InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
4759 OutputTrigger = ControlOutput ( nameof ( OutputTrigger ) ) ;
4860
49- Id = ValueInput < string > ( nameof ( Id ) , string . Empty ) ;
50- Value = ValueInput < float > ( nameof ( Value ) , 0f ) ;
61+ var _multiInputs = new List < ValueInput > ( ) ;
5162
52- Requirement ( Id , InputTrigger ) ;
53- Succession ( InputTrigger , OutputTrigger ) ;
63+ multiInputs = _multiInputs . AsReadOnly ( ) ;
64+
65+ for ( var i = 0 ; i < inputCount ; i ++ )
66+ {
67+ var input = ValueInput ( i . ToString ( ) , string . Empty ) ;
68+ _multiInputs . Add ( input ) ;
5469
70+ Requirement ( input , InputTrigger ) ;
71+ }
72+
73+ Value = ValueInput ( nameof ( Value ) , 0f ) ;
74+
75+ Succession ( InputTrigger , OutputTrigger ) ;
5576 }
5677
5778 private ControlOutput Process ( Flow flow )
5879 {
59-
6080 if ( ! AssertGle ( flow ) ) {
6181 Debug . LogError ( "Cannot find GLE." ) ;
6282 return OutputTrigger ;
6383 }
6484
65- var id = flow . GetValue < string > ( Id ) ;
66- var value = flow . GetValue < float > ( Value ) ;
85+ var value = flow . GetValue < float > ( Value ) * 255f ;
6786
68- Gle . SetLamp ( id , value * 255f ) ;
87+ foreach ( var input in multiInputs ) {
88+ var lampId = flow . GetValue < string > ( input ) ;
89+ Gle . SetLamp ( lampId , value ) ;
90+ }
6991
7092 return OutputTrigger ;
7193 }
0 commit comments