Wednesday, 8 January 2020

Embed Unity inside iOS in own ViewController

Using Unity 2019.3.0f3 and its Unity as a library feature I'm trying to embed a Unity project inside my iOS application.

Unity officially only supports full screen rendering. Nevertheless I'm looking for a way around that restriction.
In previous versions of Unity i successfully used swift-unity to do the integration. Within this approach it is easy to just get the View where Unity is rendering to (using UnityGetGLView()). I had no problems regarding stability or resources.

Using the new library approach, every time I try to access the UnityView, unity forces it's complete Window as keyWindow.

I tried accessing the UnityView in my own ViewController using

if let unityView = UnityFramework.getInstance()?.appController()?.rootViewController.view {
    // insert subview at index 0 ensures unity view is behind current UI view
    view?.insertSubview(unityView, at: 0)
}

But that immediately activates the complete unity-window and hides my parenting UITabBarController.

Trying to make the UnityFramework.getInstance()?.appController()?.rootViewController a child of my UITabBarController failed with the same result.

Furthermore it is not possible to add a child ViewController. Only adding subviews is allowed.

Does anybody know where that window-behaviour is located or how i can access the UnityView (or the RootViewController) and use it freely?



from Embed Unity inside iOS in own ViewController

No comments:

Post a Comment