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 ;
1718using Unity . VisualScripting ;
1819using UnityEngine ;
1920
@@ -24,34 +25,45 @@ namespace VisualPinball.Unity.VisualScripting
2425 [ UnitCategory ( "Visual Pinball" ) ]
2526 public class GetLampUnit : GleUnit
2627 {
28+ [ Serialize , Inspectable , UnitHeaderInspectable ]
29+ public LampDataType DataType { get ; set ; }
30+
2731 [ DoNotSerialize ]
2832 [ PortLabel ( "Lamp ID" ) ]
2933 public ValueInput Id { get ; private set ; }
3034
3135 [ DoNotSerialize ]
32- [ PortLabel ( "Value" ) ]
3336 public ValueOutput Value { get ; private set ; }
3437
35- [ DoNotSerialize ]
36- [ PortLabel ( "Is Enabled" ) ]
37- public ValueOutput IsEnabled { get ; private set ; }
38-
3938 protected override void Definition ( )
4039 {
4140 Id = ValueInput ( nameof ( Id ) , string . Empty ) ;
4241
43- Value = ValueOutput ( nameof ( Value ) , GetValue ) ;
44- IsEnabled = ValueOutput ( nameof ( IsEnabled ) , GetEnabled ) ;
42+ switch ( DataType ) {
43+ case LampDataType . OnOff :
44+ Value = ValueOutput ( nameof ( Value ) , GetEnabled ) ;
45+ break ;
46+ case LampDataType . Status :
47+ Value = ValueOutput ( nameof ( Value ) , GetEnabled ) ;
48+ break ;
49+ case LampDataType . Intensity :
50+ Value = ValueOutput ( nameof ( Value ) , GetIntensity ) ;
51+ break ;
52+ case LampDataType . Color :
53+ Value = ValueOutput ( nameof ( Value ) , GetColor ) ;
54+ break ;
55+ default :
56+ throw new ArgumentOutOfRangeException ( ) ;
57+ }
4558 }
4659
47- private float GetValue ( Flow flow )
60+ private float GetIntensity ( Flow flow )
4861 {
4962 if ( ! AssertGle ( flow ) ) {
5063 Debug . LogError ( "Cannot find GLE." ) ;
5164 return 0 ;
5265 }
53-
54- return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) ;
66+ return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) . Intensity ;
5567 }
5668
5769 private bool GetEnabled ( Flow flow )
@@ -61,7 +73,17 @@ private bool GetEnabled(Flow flow)
6173 return false ;
6274 }
6375
64- return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) > 0 ;
76+ return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) . IsOn ;
77+ }
78+
79+ private Color GetColor ( Flow flow )
80+ {
81+ if ( ! AssertGle ( flow ) ) {
82+ Debug . LogError ( "Cannot find GLE." ) ;
83+ return Color . black ;
84+ }
85+
86+ return Gle . GetLamp ( flow . GetValue < string > ( Id ) ) . Color . ToUnityColor ( ) ;
6587 }
6688 }
6789}
0 commit comments