@@ -63,6 +63,7 @@ public class EMAddPointsUnit : GleUnit
6363 [ PortLabel ( "Point Value" ) ]
6464 public ValueOutput OutputPointValue { get ; private set ; }
6565
66+ private State State => VsGle . TableState ;
6667 private static string VARIABLE_EM_SCORE_MOTOR = "EM_SCORE_MOTOR" ;
6768
6869 protected override void Definition ( )
@@ -88,75 +89,81 @@ protected override void Definition()
8889
8990 private IEnumerator Process ( Flow flow )
9091 {
91- var running = false ;
92-
93- if ( Variables . Application . IsDefined ( VARIABLE_EM_SCORE_MOTOR ) ) {
94- running = Variables . Application . Get < bool > ( VARIABLE_EM_SCORE_MOTOR ) ;
92+ if ( ! AssertVsGle ( flow ) ) {
93+ yield return OutputTrigger ;
9594 }
95+ else {
96+ var running = false ;
9697
97- yield return OutputTrigger ;
98-
99- var points = flow . GetValue < int > ( pointValue ) ;
98+ if ( State . IsDefined ( VARIABLE_EM_SCORE_MOTOR ) ) {
99+ running = State . Get < Bool > ( VARIABLE_EM_SCORE_MOTOR ) ;
100+ }
101+ else {
102+ State . AddProperty ( new StateVariable ( VARIABLE_EM_SCORE_MOTOR , "" , false ) ) ;
103+ }
104+
105+ var points = flow . GetValue < int > ( pointValue ) ;
100106
101- if ( points > 0 ) {
102- var pulses =
103- ( points % 100000 == 0 ) ? points / 100000 :
104- ( points % 10000 == 0 ) ? points / 10000 :
105- ( points % 1000 == 0 ) ? points / 1000 :
106- ( points % 100 == 0 ) ? points / 100 :
107- ( points % 10 == 0 ) ? points / 10 :
108- points ;
107+ if ( points > 0 ) {
108+ var pulses =
109+ ( points % 100000 == 0 ) ? points / 100000 :
110+ ( points % 10000 == 0 ) ? points / 10000 :
111+ ( points % 1000 == 0 ) ? points / 1000 :
112+ ( points % 100 == 0 ) ? points / 100 :
113+ ( points % 10 == 0 ) ? points / 10 :
114+ points ;
109115
110- if ( pulses == 1 ) {
111- if ( ! running || ( running && ! flow . GetValue < bool > ( blockPoints ) ) ) {
112- Debug . Log ( $ "Single pulse triggering with { points } points") ;
116+ if ( pulses == 1 ) {
117+ if ( ! running || ( running && ! flow . GetValue < bool > ( blockPoints ) ) ) {
118+ Debug . Log ( $ "Single pulse triggering with { points } points") ;
113119
114- flow . SetValue ( OutputPointValue , points ) ;
120+ flow . SetValue ( OutputPointValue , points ) ;
115121
116- yield return pulse ;
122+ yield return pulse ;
123+ }
117124 }
118- }
119- else if ( running )
120- {
121- Debug . Log ( $ "Score motor is already running.") ;
122- }
123- else {
124- Debug . Log ( "Starting score motor" ) ;
125+ else if ( running ) {
126+ Debug . Log ( $ "Score motor is already running.") ;
127+ }
128+ else {
129+ Debug . Log ( "Starting score motor" ) ;
125130
126- Variables . Application . Set ( VARIABLE_EM_SCORE_MOTOR , true ) ;
127-
128- yield return started ;
131+ State . Set < Bool > ( VARIABLE_EM_SCORE_MOTOR , true ) ;
129132
130- var motorPositions = flow . GetValue < int > ( positions ) ;
133+ yield return started ;
131134
132- var delay = ( flow . GetValue < float > ( duration ) / 1000f ) / motorPositions ;
133- var realtime = flow . GetValue < bool > ( unscaledTime ) ;
135+ var motorPositions = flow . GetValue < int > ( positions ) ;
134136
135- var pointsPerPulse = points / pulses ;
137+ var delay = ( flow . GetValue < float > ( duration ) / 1000f ) / motorPositions ;
138+ var realtime = flow . GetValue < bool > ( unscaledTime ) ;
136139
137- for ( int loop = 0 ; loop < motorPositions ; loop ++ ) {
138- var outputPoints = loop < pulses ? pointsPerPulse : 0 ;
140+ var pointsPerPulse = points / pulses ;
139141
140- Debug . Log ( $ "Pulse { loop + 1 } of { motorPositions } - waiting { delay } ms and triggering with { outputPoints } points") ;
142+ for ( int loop = 0 ; loop < motorPositions ; loop ++ ) {
143+ var outputPoints = loop < pulses ? pointsPerPulse : 0 ;
141144
142- if ( realtime ) {
143- yield return new WaitForSecondsRealtime ( delay ) ;
144- }
145- else {
146- yield return new WaitForSeconds ( delay ) ;
147- }
145+ Debug . Log ( $ "Pulse { loop + 1 } of { motorPositions } - waiting { delay } ms and triggering with { outputPoints } points") ;
148146
149- flow . SetValue ( OutputPointValue , outputPoints ) ;
147+ if ( realtime ) {
148+ yield return new WaitForSecondsRealtime ( delay ) ;
149+ }
150+ else {
151+ yield return new WaitForSeconds ( delay ) ;
152+ }
150153
151- yield return pulse ;
152- }
154+ flow . SetValue ( OutputPointValue , outputPoints ) ;
155+
156+ yield return pulse ;
157+ }
153158
154- Debug . Log ( "Stopping score motor" ) ;
159+ Debug . Log ( "Stopping score motor" ) ;
155160
156- Variables . Application . Set ( VARIABLE_EM_SCORE_MOTOR , false ) ;
161+ State . Set < Bool > ( VARIABLE_EM_SCORE_MOTOR , false ) ;
157162
158- yield return stopped ;
163+ yield return stopped ;
164+ }
159165 }
166+
160167 }
161168 }
162169 }
0 commit comments