@@ -15,36 +15,34 @@ public class LampGroupSequenceUnit : Unit
1515 public ValueInput lightGroup ;
1616
1717 [ DoNotSerialize ]
18+ [ PortLabelHidden ]
1819 public ValueInput maxLights ;
1920
2021 [ DoNotSerialize ]
2122 public ControlOutput outputTrigger ;
2223
2324 private TableApi _tableApi ;
24- private int _currentIndex ;
25+ private int _currentIndex = 0 ;
2526
2627 protected override void Definition ( )
2728 {
2829 inputTrigger = ControlInput ( "In" , ( flow ) => Process ( flow ) ) ;
2930
3031 lightGroup = ValueInput < LightGroupComponent > ( nameof ( lightGroup ) ) ;
31- maxLights = ValueInput < int > ( nameof ( maxLights ) ) ;
32+ maxLights = ValueInput < int > ( nameof ( maxLights ) , 1 ) ;
3233
3334 outputTrigger = ControlOutput ( "" ) ;
3435 }
3536
3637 private ControlOutput Process ( Flow flow , bool invert = false )
3738 {
38-
39- if ( _tableApi == null )
40- {
39+ if ( _tableApi == null ) {
4140 _tableApi = UnityEngine . Object . FindObjectOfType < Player > ( ) . TableApi ;
4241 }
4342
4443 // GetValue throws an exception because they are not basic types
4544
46- try
47- {
45+ try {
4846 EnableLightGroup ( flow . GetValue < LightGroupComponent > ( lightGroup ) , flow . GetValue < int > ( maxLights ) ) ;
4947 }
5048 catch ( Exception ) { } ;
@@ -54,35 +52,14 @@ private ControlOutput Process(Flow flow, bool invert = false)
5452
5553 private void EnableLightGroup ( LightGroupComponent lightGroupComponent , int maxLights )
5654 {
57- int index = 0 ;
58- int count = 0 ;
55+ var totalLights = lightGroupComponent . Lights . Count ( ) ;
5956
60- bool enabled = false ;
61-
62- var lights = lightGroupComponent . Lights . SelectMany ( l => l . GetComponentsInChildren < LightComponent > ( ) ) ;
63-
64- foreach ( var light in lights )
65- {
66- if ( index == _currentIndex )
67- {
68- enabled = true ;
69- }
70-
71- if ( enabled && ++ count > maxLights )
72- {
73- enabled = false ;
74- }
75-
76- var lightState = _tableApi . Light ( light ) ;
77- lightState . State = enabled ? 1 : 0 ;
78-
79- index ++ ;
57+ for ( var index = 0 ; index < totalLights ; index ++ ) {
58+ _tableApi . Light ( lightGroupComponent . Lights [ index ] . GetComponentInChildren < LightComponent > ( ) ) . State =
59+ ( index >= ( _currentIndex * maxLights ) && index < ( ( _currentIndex + 1 ) * maxLights ) ) ? 1 : 0 ;
8060 }
8161
82- _currentIndex += maxLights ;
83-
84- if ( _currentIndex > lights . Count ( ) )
85- {
62+ if ( ++ _currentIndex >= totalLights / maxLights ) {
8663 _currentIndex = 0 ;
8764 }
8865 }
0 commit comments