Accessing Unity3D View Controller

GameCenter requires that you give access to a view controller to display the leader board.

The function in question is:

presentModalViewController:animated:

To do so is quite easy.

In “AppController.mm”,

  1. scroll to int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight, int* openglesVersion)

  2. comment out [_window addSubview:view]

  3. below put _window.rootViewController = controller;

  4. wherever the view controller is necessary, you can put [[[UIApplication sharedApplication] keyWindow] rootViewController]

an example to display the leaderboard:

// displaying the default leaderboard
-(void) showLeaderboard {
       GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
       if (leaderboardController != nil) {
              leaderboardController.leaderboardDelegate = self;

              [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:leaderboardController animated:YES];
       }
}

:sunglasses:

Thanks. Very helpful. :wink:

Just out of curiosity, why does one have to comment out the addSubView line? Never did any native iphone development, so just wondering…