@@ -22,6 +22,8 @@ public class WebsocketManager : Singleton<WebsocketManager> {
2222 /// Websocket context
2323 /// </summary>
2424 private WebSocket websocket ;
25+
26+ int counter = 0 ;
2527 /// <summary>
2628 /// Dictionary of unprocessed responses
2729 /// </summary>
@@ -579,30 +581,37 @@ private void HandleStateBefore(string obj) {
579581 try {
580582
581583 IO . Swagger . Model . ActionStateBefore actionStateBefore = JsonConvert . DeserializeObject < IO . Swagger . Model . ActionStateBefore > ( obj ) ;
584+ if ( ! string . IsNullOrEmpty ( actionStateBefore . Data . ActionId ) ) {
585+ puck_id = actionStateBefore . Data . ActionId ;
582586
583- puck_id = actionStateBefore . Data . ActionId ;
584-
585- if ( ! ProjectManager . Instance . Valid ) {
586- Debug . LogWarning ( "Project not yet loaded, ignoring current action" ) ;
587- GameManager . Instance . ActionRunningOnStartupId = puck_id ;
588- return ;
587+ if ( ! ProjectManager . Instance . Valid ) {
588+ Debug . LogWarning ( "Project not yet loaded, ignoring current action" ) ;
589+ GameManager . Instance . ActionRunningOnStartupId = puck_id ;
590+ return ;
591+ }
592+ // Stop previously running action (change its color to default)
593+ if ( ActionsManager . Instance . CurrentlyRunningAction != null )
594+ ActionsManager . Instance . CurrentlyRunningAction . StopAction ( ) ;
595+
596+ Action puck = ProjectManager . Instance . GetAction ( puck_id ) ;
597+ ActionsManager . Instance . CurrentlyRunningAction = puck ;
598+ // Run current action (set its color to running)
599+ puck . RunAction ( ) ;
600+ } else {
601+ if ( ActionsManager . Instance . CurrentlyRunningAction != null )
602+ ActionsManager . Instance . CurrentlyRunningAction . StopAction ( ) ;
603+ ActionsManager . Instance . CurrentlyRunningAction = null ;
589604 }
605+
606+
590607
591608 } catch ( NullReferenceException e ) {
592609 Debug . Log ( "Parse error in HandleCurrentAction()" ) ;
593610 return ;
611+ } catch ( ItemNotFoundException e ) {
612+ Debug . LogError ( e ) ;
594613 }
595- // Stop previously running action (change its color to default)
596- if ( ActionsManager . Instance . CurrentlyRunningAction != null )
597- ActionsManager . Instance . CurrentlyRunningAction . StopAction ( ) ;
598- try {
599- Action puck = ProjectManager . Instance . GetAction ( puck_id ) ;
600- ActionsManager . Instance . CurrentlyRunningAction = puck ;
601- // Run current action (set its color to running)
602- puck . RunAction ( ) ;
603- } catch ( ItemNotFoundException ex ) {
604- Debug . LogError ( ex ) ;
605- }
614+
606615 }
607616
608617 private void HandleActionStateAfter ( string obj ) {
@@ -613,11 +622,10 @@ private void HandleActionStateAfter(string obj) {
613622 try {
614623
615624 IO . Swagger . Model . ActionStateAfter actionStateBefore = JsonConvert . DeserializeObject < IO . Swagger . Model . ActionStateAfter > ( obj ) ;
616-
617- puck_id = actionStateBefore . Data . ActionId ;
618-
619-
620-
625+ if ( ActionsManager . Instance . CurrentlyRunningAction != null )
626+ ActionsManager . Instance . CurrentlyRunningAction . StopAction ( ) ;
627+ ActionsManager . Instance . CurrentlyRunningAction = null ;
628+
621629 } catch ( NullReferenceException e ) {
622630 Debug . Log ( "Parse error in HandleCurrentAction()" ) ;
623631 return ;
0 commit comments