1818using System . Collections . Generic ;
1919using Unity . VisualScripting ;
2020using UnityEngine ;
21- using UnityObject = UnityEngine . Object ;
2221
2322namespace VisualPinball . Unity . VisualScripting
2423{
2524 [ Serializable ]
26- public class LampIdValue : UnityObject
25+ public struct LampIdValue
2726 {
2827 public string id ;
2928 public int value ;
3029
31- public static LampIdValue Empty = new LampIdValue { id = string . Empty , value = 0 } ;
30+ public static LampIdValue FromJson ( string json )
31+ {
32+ return JsonUtility . FromJson < LampIdValue > ( json ) ;
33+ }
34+
35+ public string ToJson ( )
36+ {
37+ return JsonUtility . ToJson ( this ) ;
38+ }
39+
40+ public static readonly LampIdValue Empty = new LampIdValue { id = string . Empty , value = 0 } ;
3241 }
3342
3443 [ UnitShortTitle ( "Switch Lamp" ) ]
@@ -63,6 +72,9 @@ public int idCount
6372 [ DoNotSerialize ]
6473 public List < ValueInput > LampIdValues { get ; private set ; }
6574
75+ private List < LampIdValue > _lampIdValueList ;
76+ private int _hash ;
77+
6678 protected override void Definition ( )
6779 {
6880 InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
@@ -72,15 +84,13 @@ protected override void Definition()
7284
7385 LampIdValues = new List < ValueInput > ( ) ;
7486
75- for ( var i = 0 ; i < idCount ; i ++ )
76- {
77- var lampIdValue = ValueInput < LampIdValue > ( "Lamp ID " + ( i + 1 ) , LampIdValue . Empty ) ;
78- LampIdValues . Add ( lampIdValue ) ;
87+ for ( var i = 0 ; i < idCount ; i ++ ) {
88+ var valueInput = ValueInput ( $ "Lamp ID { i + 1 } ", LampIdValue . Empty . ToJson ( ) ) ;
89+ LampIdValues . Add ( valueInput ) ;
7990
80- Requirement ( lampIdValue , InputTrigger ) ;
91+ Requirement ( valueInput , InputTrigger ) ;
8192 }
8293
83-
8494 Succession ( InputTrigger , OutputTrigger ) ;
8595 }
8696
@@ -90,13 +100,12 @@ private ControlOutput Process(Flow flow)
90100 Debug . LogError ( "Cannot find GLE." ) ;
91101 return OutputTrigger ;
92102 }
93-
103+
94104 var value = flow . GetValue < int > ( Value ) ;
95105
96- foreach ( var lampIdValue in LampIdValues )
97- {
98- var lampIdValueStruct = flow . GetValue < LampIdValue > ( lampIdValue ) ;
99- Gle . SetLamp ( lampIdValueStruct . id , lampIdValueStruct . value == value ? 255f : 0f ) ;
106+ foreach ( var lampIdValue in LampIdValues ) {
107+ var obj = LampIdValue . FromJson ( flow . GetValue < string > ( lampIdValue ) ) ;
108+ Gle . SetLamp ( obj . id , obj . value == value ? 255f : 0f ) ;
100109 }
101110
102111 return OutputTrigger ;
0 commit comments