1- // Visual Pinball Engine
2- // Copyright (C) 2022 freezy and VPE Team
3- //
4- // This program is free software: you can redistribute it and/or modify
5- // it under the terms of the GNU General Public License as published by
6- // the Free Software Foundation, either version 3 of the License, or
7- // (at your option) any later version.
8- //
9- // This program is distributed in the hope that it will be useful,
10- // but WITHOUT ANY WARRANTY; without even the implied warranty of
11- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12- // GNU General Public License for more details.
13- //
14- // You should have received a copy of the GNU General Public License
15- // along with this program. If not, see <https://www.gnu.org/licenses/>.
16-
1+ // Visual Pinball Engine
2+ // Copyright (C) 2022 freezy and VPE Team
3+ //
4+ // This program is free software: you can redistribute it and/or modify
5+ // it under the terms of the GNU General Public License as published by
6+ // the Free Software Foundation, either version 3 of the License, or
7+ // (at your option) any later version.
8+ //
9+ // This program is distributed in the hope that it will be useful,
10+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ // GNU General Public License for more details.
13+ //
14+ // You should have received a copy of the GNU General Public License
15+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+ using System . Collections . Generic ;
18+ using System . Collections . ObjectModel ;
1719using Unity . VisualScripting ;
18-
20+ using UnityEngine ;
21+
1922namespace VisualPinball . Unity . VisualScripting
2023{
2124 [ UnitTitle ( "On Lamp Changed" ) ]
2225 [ UnitSurtitle ( "Gamelogic Engine" ) ]
2326 [ UnitCategory ( "Events\\ Visual Pinball" ) ]
24- public sealed class LampEventUnit : GleEventUnit < LampEventArgs >
27+ public sealed class LampEventUnit : GleEventUnit < LampEventArgs > , IMultiInputUnit
2528 {
29+ [ SerializeAs ( nameof ( inputCount ) ) ]
30+ private int _inputCount = 1 ;
31+
32+ [ DoNotSerialize ]
33+ [ Inspectable , UnitHeaderInspectable ( "Lamp IDs" ) ]
34+ public int inputCount
35+ {
36+ get => _inputCount ;
37+ set => _inputCount = Mathf . Clamp ( value , 1 , 10 ) ;
38+ }
39+
2640 [ DoNotSerialize ]
27- [ PortLabel ( "Lamp ID" ) ]
28- public ValueInput Id { get ; private set ; }
41+ public ReadOnlyCollection < ValueInput > multiInputs { get ; private set ; }
2942
3043 [ DoNotSerialize ]
3144 [ PortLabel ( "Intensity" ) ]
@@ -46,21 +59,33 @@ protected override void Definition()
4659 {
4760 base . Definition ( ) ;
4861
49- Id = ValueInput ( nameof ( Id ) , string . Empty ) ;
62+ var _multiInputs = new List < ValueInput > ( ) ;
63+
64+ multiInputs = _multiInputs . AsReadOnly ( ) ;
65+
66+ for ( var i = 0 ; i < inputCount ; i ++ ) {
67+ _multiInputs . Add ( ValueInput ( i . ToString ( ) , string . Empty ) ) ;
68+ }
5069
5170 Value = ValueOutput < float > ( nameof ( Value ) ) ;
5271 IsEnabled = ValueOutput < bool > ( nameof ( IsEnabled ) ) ;
72+ }
73+
74+ protected override bool ShouldTrigger ( Flow flow , LampEventArgs args )
75+ {
76+ foreach ( var input in multiInputs ) {
77+ if ( flow . GetValue < string > ( input ) == args . Id ) {
78+ return true ;
79+ }
80+ }
81+
82+ return false ;
5383 }
5484
5585 protected override void AssignArguments ( Flow flow , LampEventArgs args )
5686 {
5787 flow . SetValue ( Value , args . Value ) ;
5888 flow . SetValue ( IsEnabled , args . Value > 0 ) ;
5989 }
60-
61- protected override bool ShouldTrigger ( Flow flow , LampEventArgs args )
62- {
63- return args . Id == flow . GetValue < string > ( Id ) ;
64- }
6590 }
6691}
0 commit comments