Closed dandepeched closed 2 years ago
Hi, technically Unity should always be fullscreen... However, setting it fullscreen and overlaying other views on top will work. I am not a pro of Swift UI and I generally work with Swift developers that made it work.
I'm also trying to make it work with Swift. Maybe you can share some code example of such native overlay that worked for you?
I can't share code because it's from work. However, this sample in this repo succeeds to display a text view above Unity, using a ZStkack. Something prevents you to simply add another fullscreen opaque element on top of Unity?
Actually I can cover it over, but new screen is not interactive, like whole app is stuck now. I do not use SwiftUI, so to show Unity I directly call your implementation on MainViewController:
UnityBridge.getInstance().onReady = {
UnityBridge.getInstance().show(controller: self.unityVc) //where unityVc = UIViewController()
}
Then to do overlay I use your bridge call and present another controller from MainViewController:
self.present(webView, animated: true, completion: nil) //where webView.modalPresentationStyle = .fullScreen
New controller is displayed, but no interaction is available. That is why I came to the idea that Unity need to be dismissed first, but I didn't find a way to do this.
Sorry for the late answer. It doesn't need to be dismissed. I am not sure how to get your interactions back I haven't had this issue with SwiftUI. Do you manually need to say what controller is active or something?
I'm having the same issue as @dandepeched. The uaal example from unity doesn't seem to have this issue so I'm not sure why this would if @DavidPeicho's project is mostly just bridging from Swift. Have you solved the problem or are you still stuck?
Hi, just FYI: updated Unity today and the same error occurs to me. I am wondering if something hasn't change regarding window management
The problem is obvious: they actually use a single window.... See here.
This is a little bit annoying and I have to modify my app at work...
I think the way to go would be to:
I successfully made that work now with Unity 2021, but then no event just like @dandepeched, because they are obviously capture by either Unity / the UI window
Alright @cameron-erdogan @dandepeched I have a good fix. The way I integrate everything is completely different now, but that seems to work quite well and not I don't add the UnityView anywhere else.
I will try to find some time to explain the new solution through another blog post and will post the code.
The main
branch of this repository has been updated with my new solution. Blog post describing it:
https://davidpeicho.github.io/blog/unity-swiftui-integration-revisited/
I went really fast to write the blog post. If you see any mistake (spelling included), please make a PR on my github.io that would be lovely!
Hi @DavidPeicho , I'm trying to switch between native views and Unity back and force with API calls. The problem is that I cannot hide Unity after it was first shown. Any new native controller is hidden behind Unity. I've tried dismissing it, removing from parent, but Unity is always on top. Even unloading it with your method only freezes the view without possibility to remove it. I would appreciate any suggestions.