Unity-Technologies / uaal-example

Other
736 stars 234 forks source link

Improvement for real-world applications #60

Open DavidPeicho opened 2 years ago

DavidPeicho commented 2 years ago

Hey, thanks for the sample!

I think there is something where everyone struggles though: making the app work in a real application context, i.e.,

I know that it already kind of works, but it still seems weird to me. There is a window right now that simply host nothing. The views are added directly as a child of the UnityView, which will not work at all with stuff like SwiftUI.

ROBYER1 commented 2 years ago

I too am looking into making Unity a subview in IOS, I achieved that successfully on android using Fragments in Android Studio and it was actually fairly simple.

Did you have any luck with subviews on IOS?

DavidPeicho commented 2 years ago

I used to resize unity by adding it as a subview of other elements. It worked until ~Unity 2021. It's anyway not recommended to do that.

I went for a better solution now. I have two windows, one for Unity, and one for the UI that is in the foreground. There is a complete example + explanation about how that works on my blog here.

Unity is still running on the fullscreen, but that's not much of an issue for me

ROBYER1 commented 2 years ago

@DavidPeicho I just realised it was your sample I built yesterday when I was investigating a few ways of having Unity as a subview on IOS. Thanks for the fantastic example repo!

If you were to have unity as a smaller view within a UI element, such as a smaller viewer of Unity to show a 3d model within a fullscreen native app inside a scrollfield, would you resize the unity window and keep it in sync with the UI in front of it by moving it up or down? Or is there no way at all of getting sub views to work again?

I am talking to our native IOS developer later about this as I've got it working that way on android with fragments and views so I was hoping that subviews would be a similar solution on IOS. If we also find a solution I will post it back to help others with the same dilemmas.

DavidPeicho commented 2 years ago

I used to do it this way. Basically the Unity view was added as a child of another view, and it was also getting resized (you can play with the frame of the view).

It turns out it didn't really work well with Unity 2021. The problem is that they create their own window, and moving the view out of the window just didn't work.

Your case is tricky, you want to scroll and to display several 3D models?

ROBYER1 commented 2 years ago

I see, I wonder if I can hijack the creation of the window and retarget it somehow, we are using 2021 too unfortunately.

We want to have the Unity view as a child of another (native) view so that we can move it around, resize it etc. It was interesting doing it on android as loads of people said it couldn't be done but it did work in a fragment.

Something like this image

I'm guessing I need to look at where Unity 2021 creates a window instead of a view if this is the case and defer the creation of it, failing that find out if there is any way to convert that window into a subview or nest it as a child of another window somehow.

bdeweygit commented 1 year ago

@ROBYER1 I think my fork does what you want.

ROBYER1 commented 1 year ago

@ROBYER1 I think my fork does what you want.

Thanks! I'll take a look but I definitely cracked this on a recent project myself too :)