Skip to content

Instantly share code, notes, and snippets.

@superbderrick
Last active January 12, 2022 08:27
Show Gist options
  • Save superbderrick/c49d842a0f14e6c8db62be94dd0f9ad3 to your computer and use it in GitHub Desktop.
Save superbderrick/c49d842a0f14e6c8db62be94dd0f9ad3 to your computer and use it in GitHub Desktop.
func initUnity() {
if let nativeWindow = self.window {
if unityIsInitialized() {
UnitySampleUtils.showAlert(Constants.ERRORMESSAGES.ALREADY_INIT, Constants.ERRORMESSAGES.UNLOAD_FIREST, window: nativeWindow)
return
}
if didQuit {
UnitySampleUtils.showAlert(Constants.ERRORMESSAGES.CANNOTBE_INITIALIZED, Constants.ERRORMESSAGES.USE_UNLOAD, window:nativeWindow)
return
}
}
self.unityFramework = getUnityFramework()
if let unityframework = self.unityFramework {
unityframework.setDataBundleId("com.unity3d.framework")
unityframework.register(self)
NSClassFromString("FrameworkLibAPI")?.registerAPIforNativeCalls(self)
unityframework.runEmbedded(withArgc: CommandLine.argc, argv: CommandLine.unsafeArgv, appLaunchOpts: appLaunchOpts)
attachUnityView()
}
}
func attachUnityView() {
guard let unityRootView = unityFramework?.appController()?.rootView else {
return
}
self.unitySampleView = UnityUIView(frame: UIScreen.main.bounds)
unityRootView.addSubview(self.unitySampleView)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment