我能够成功地将Unity项目集成到我的Swift项目中,但是由于我收到以下错误,因此无法运行Unity窗口:
***由于未捕获的异常而终止应用程序' NSUnknownKeyException',原因:' [valueForUndefinedKey:]:此类与关键的currentUnityController不符合键值编码。
我知道我在某个地方犯了一个错误,但这已经花了很多时间。如果有人尝试过这个错误,我会很感激。以下是我的AppDelegate中的参考代码:
import UIKit
//@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var unityWindow: UIWindow?
var currentUnityController: UnityAppController!
var application: UIApplication?
var isUnityRunning = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
self.application = application
currentUnityController = UnityAppController()
currentUnityController.application(application, didFinishLaunchingWithOptions: launchOptions)
UnityGetMainWindow().alpha = 1.0
// first call to startUnity will do some init stuff, so just call it here and directly stop it again
startUnity()
stopUnity()
return true
}
func applicationWillResignActive(_ application: UIApplication) {
if isUnityRunning {
currentUnityController?.applicationWillResignActive(application)
}
}
func applicationDidEnterBackground(_ application: UIApplication) {
if isUnityRunning {
currentUnityController?.applicationDidEnterBackground(application)
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
if isUnityRunning {
currentUnityController?.applicationWillEnterForeground(application)
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
if isUnityRunning {
currentUnityController?.applicationDidBecomeActive(application)
}
}
func applicationWillTerminate(_ application: UIApplication) {
if isUnityRunning {
currentUnityController?.applicationWillTerminate(application)
}
}
func startUnity() {
if !isUnityRunning {
isUnityRunning = true
currentUnityController!.applicationDidBecomeActive(application!)
}
}
func stopUnity() {
if isUnityRunning {
currentUnityController!.applicationWillResignActive(application!)
isUnityRunning = false
}
}
}
附件是错误的屏幕截图:
答案 0 :(得分:0)