- Home /
integrate native IOS with unity, the unity change to be lag and low performance
I need to integrate IOS native code with unity project. My main page is a Native view controller. And I need to jump into a Unity page from the main page. And also can go back.
(1)From native main page to Unity,I invoke 'showUnityWindow ' method of AppDelegate, hasStartUnityBefore is just a marker.
-(void)showUnityWindow{
[self.window resignKeyWindow];
if (self.hasStartUnityBefore) {
[[UnityAppController sharedInstance] restartUnity];
[[[UnityGetMainWindow() rootViewController] view] setHidden:NO];
[UnityGetMainWindow() makeKeyAndVisible];
}else{
self.hasStartUnityBefore = YES;
[[UnityAppController sharedInstance] application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOption];
[[UnityAppController sharedInstance] startUnity:[UIApplication sharedApplication]];
[UnityGetMainWindow() makeKeyAndVisible];
}
}
(2)go back to main page from unity,the 'HideUnityWindow' method of AppDelegate
-(void)HideUnityWindow{
[UnityGetMainWindow() resignKeyWindow];
[[[UnityGetMainWindow() rootViewController] view] setHidden:YES]; [self.window makeKeyAndVisible];
UnityPause(true); _didResignActive = YES; Profiler_UninitProfiler();
}
(3)related method in UnityAppController
(void)restartUnity{
if (_didResignActive) UnityPause(false);
_didResignActive = NO;
}
(void)startUnityUIApplication*)application { NSAssert(_unityAppReady == NO, @"[UnityAppController startUnity:] called after Unity has been initialized");
UnityInitApplicationGraphics();
// we make sure that first level gets correct display list and orientation [[DisplayManager Instance] updateDisplayListInUnity];
UnityLoadApplication(); Profiler_InitProfiler();
[self showGameUI]; [self createDisplayLink];
UnitySetPlayerFocus(1); }
inline UnityAppController* GetAppController() { return [UnityAppController sharedInstance]; }
(UnityAppController*)sharedInstance { static UnityAppController *sharedInstance = nil; static dispatch_once_t once; dispatch_once(&once, ^{ sharedInstance = [[self alloc] init]; });
return sharedInstance; }
(4)The problem is afterI jump into unity and go back native main page for several times,,unity page become lag ,but native page is still OK. It seems not memory problem. Anyone can tell me the reason and how to resolve such problem. Deeply thx.