将Unity 5.6.2与ARKit集成到Swift项目

时间:2017-09-01 01:23:41

标签: unity3d swift3 swift4

我能够成功地将Unity项目集成到我的Swift项目中,但是由于我收到以下错误,因此无法运行Unity窗口: enter image description here     ***由于未捕获的异常而终止应用程序' 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
    }
}
}

附件是错误的屏幕截图:

1 个答案:

答案 0 :(得分:0)

终于解决了!我能以某种方式找到ObjC生成的头部中的unityAppController对象在派生源下。这不适用于我正在创建的示例应用程序,我觉得桥接头没有正确连接。

相关问题