Advertisement
bjoWasTaken

UnityAppController.mm modification

Aug 5th, 2016
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)applicationDidEnterBackground:(UIApplication*)application
  2. {
  3.     ::printf("-> applicationDidEnterBackground()\n");
  4.    
  5.     if(_unityAppReady)
  6.     {
  7.         UnitySetPlayerFocus(0);
  8.        
  9.         _wasPausedExternal = UnityIsPaused();
  10.         if (_wasPausedExternal == false)
  11.         {
  12.             // do pause unity only if we dont need special background processing
  13.             // otherwise batched player loop can be called to run user scripts
  14.             int bgBehavior = UnityGetAppBackgroundBehavior();
  15.             if(bgBehavior == appbgSuspend || bgBehavior == appbgExit)
  16.             {
  17.                 // Force player to do one more frame, so scripts get a chance to render custom screen for minimized app in task manager.
  18.                 // NB: UnityWillPause will schedule OnApplicationPause message, which will be sent normally inside repaint (unity player loop)
  19.                 // NB: We will actually pause after the loop (when calling UnityPause).
  20.                 UnityWillPause();
  21.                 [self repaint];
  22.                 UnityPause(1);
  23.                
  24.                 // this is done on the next frame so that
  25.                 // in the case where unity is paused while going
  26.                 // into the background and an input is deactivated
  27.                 // we don't mess with the view hierarchy while taking
  28.                 // a view snapshot (case 760747).
  29.                 dispatch_async(dispatch_get_main_queue(), ^{
  30.                     _snapshotView = [self createSnapshotView];
  31.                     if(_snapshotView)
  32.                         [_rootView addSubview:_snapshotView];
  33.                 });
  34.             }
  35.            
  36.             //Periodically force Unity to run the update loop while going to the background
  37.             [UnityiOSForcedUpdater startBackgroundUpdateTimer];
  38.         }
  39.     }
  40.    
  41.     _didResignActive = true;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement