Last active
December 11, 2020 04:05
-
-
Save noppefoxwolf/95a30f702e570f70796d787e279a8d01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
showUnityWindowを呼ぶ必要があるので、読んですぐに元々のkeyWindowに戻す。
あとは任意のタイミングでUnity.shared.viewを適当な場所にaddSubViewする