Skip to content

Instantly share code, notes, and snippets.

@eunjin3786
Last active February 24, 2022 06:29
Show Gist options
  • Save eunjin3786/a802a4e9e7c384fec6b0090d92671259 to your computer and use it in GitHub Desktop.
Save eunjin3786/a802a4e9e7c384fec6b0090d92671259 to your computer and use it in GitHub Desktop.
class UnityManager: NSObject {
...
private var hostMainWindow : UIWindow?
func setHostMainWindow(_ hostMainWindow: UIWindow?) {
self.hostMainWindow = hostMainWindow
}
func launchUnity() {
let isInitialized = self.ufw?.appController() != nil
if isInitialized {
self.ufw?.showUnityWindow()
} else {
guard let ufw = self.loadUnityFramework() else { return }
self.ufw = ufw
ufw.setDataBundleId(dataBundleId)
✅ ufw.register(self)
ufw.runEmbedded(
withArgc: CommandLine.argc,
argv: CommandLine.unsafeArgv,
appLaunchOpts: nil
)
}
}
func closeUnity() {
self.ufw?.unloadApplication()
}
...
}
extension UnityManager: UnityFrameworkListener {
func unityDidUnload(_ notification: Notification!) {
self.ufw?.unregisterFrameworkListener(self)
self.ufw = nil
self.hostMainWindow?.makeKeyAndVisible()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment