Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Last active December 11, 2020 04:05
Show Gist options
  • Save noppefoxwolf/95a30f702e570f70796d787e279a8d01 to your computer and use it in GitHub Desktop.
Save noppefoxwolf/95a30f702e570f70796d787e279a8d01 to your computer and use it in GitHub Desktop.
class Unity: UnityFrameworkListener {
static let shared = Unity()
private let unityFramework: UnityFramework
var view: UIView { unityFramework.appController()!.window }
override init() {
let frameworkPath = Bundle.main.bundlePath.appending("/Frameworks/UnityFramework.framework")
let bundle = Bundle(path: frameworkPath)!
unityFramework = bundle.principalClass!.getInstance()
super.init()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
unityFramework.register(self)
NSClassFromString("FrameworkLibAPI")?.registerAPIforNativeCalls(self)
unityFramework.setDataBundleId("com.unity3d.framework")
unityFramework.runEmbedded(withArgc: CommandLine.argc, argv: CommandLine.unsafeArgv, appLaunchOpts: launchOptions)
unityFramework.showUnityWindow()
}
}
/// 起動直後に呼ぶやつ
extension AppDelegate {
func setupUnity(_ application: UIApplication, launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
let window = UIApplication.shared.findKeyWindow()
Unity.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
window?.makeKeyAndVisible()
}
}
@noppefoxwolf
Copy link
Author

showUnityWindowを呼ぶ必要があるので、読んですぐに元々のkeyWindowに戻す。
あとは任意のタイミングでUnity.shared.viewを適当な場所にaddSubViewする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment