1- using Unity . VisualScripting ;
1+ // Visual Pinball Engine
2+ // Copyright (C) 2021 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 Unity . VisualScripting ;
218
319namespace VisualPinball . Unity . VisualScripting
420{
5- [ UnitTitle ( "Get Lamp Value" ) ]
6- [ UnitCategory ( "Visual Pinball" ) ]
7- public class GetLampValueUnit : Unit
8- {
9- [ DoNotSerialize ]
10- [ PortLabelHidden ]
11- public ValueInput id { get ; private set ; }
12-
13- [ DoNotSerialize ]
14- [ PortLabelHidden ]
15- public ValueOutput value { get ; private set ; }
16-
17- [ DoNotSerialize ]
18- [ PortLabelHidden ]
19- public ValueOutput enabled { get ; private set ; }
20-
21- private Player _player ;
22-
23- protected override void Definition ( )
24- {
25- id = ValueInput ( nameof ( id ) , string . Empty ) ;
26-
27- value = ValueOutput ( nameof ( value ) , GetValue ) ;
28- enabled = ValueOutput ( nameof ( enabled ) , GetEnabled ) ;
29- }
30-
31- private float GetValue ( Flow flow )
32- {
33- if ( _player == null ) {
34- _player = UnityEngine . Object . FindObjectOfType < Player > ( ) ;
35- }
36-
37- var key = flow . GetValue < string > ( id ) ;
38- return _player . LampStatuses . ContainsKey ( key ) ? _player . LampStatuses [ key ] : 0 ;
39- }
40-
41- private bool GetEnabled ( Flow flow )
42- {
43- if ( _player == null ) {
44- _player = UnityEngine . Object . FindObjectOfType < Player > ( ) ;
45- }
46-
47- var key = flow . GetValue < string > ( id ) ;
48- return _player . LampStatuses . ContainsKey ( key ) ? ( _player . LampStatuses [ key ] > 0 ) : false ;
49- }
50- }
51- }
21+ [ UnitTitle ( "Get Lamp Value" ) ]
22+ [ UnitCategory ( "Visual Pinball" ) ]
23+ public class GetLampValueUnit : Unit
24+ {
25+ [ DoNotSerialize ]
26+ [ PortLabelHidden ]
27+ public ValueInput id { get ; private set ; }
28+
29+ [ DoNotSerialize ]
30+ [ PortLabelHidden ]
31+ public ValueOutput value { get ; private set ; }
32+
33+ [ DoNotSerialize ]
34+ [ PortLabelHidden ]
35+ public ValueOutput enabled { get ; private set ; }
36+
37+ private Player _player ;
38+
39+ protected override void Definition ( )
40+ {
41+ id = ValueInput ( nameof ( id ) , string . Empty ) ;
42+
43+ value = ValueOutput ( nameof ( value ) , GetValue ) ;
44+ enabled = ValueOutput ( nameof ( enabled ) , GetEnabled ) ;
45+ }
46+
47+ private float GetValue ( Flow flow )
48+ {
49+ if ( _player == null ) {
50+ _player = UnityEngine . Object . FindObjectOfType < Player > ( ) ;
51+ }
52+
53+ var key = flow . GetValue < string > ( id ) ;
54+ return _player . LampStatuses . ContainsKey ( key ) ? _player . LampStatuses [ key ] : 0 ;
55+ }
56+
57+ private bool GetEnabled ( Flow flow )
58+ {
59+ if ( _player == null ) {
60+ _player = flow . stack . self . GetComponentInParent < Player > ( ) ;
61+ }
62+
63+ var key = flow . GetValue < string > ( id ) ;
64+ return _player . LampStatuses . ContainsKey ( key ) && ( _player . LampStatuses [ key ] > 0 ) ;
65+ }
66+ }
67+ }
0 commit comments