Open SGoerzen opened 2 weeks ago
Hi @SGoerzen,
We have experimented with this at Red-Point, with a little bit of success, but haven't made a concerted effort to use MAUI over the top of Unity.
It is possible (somewhat) but we found it had a few caveats:
Rather than injecting the view through your changes above, you can use native embedding (your usage of ToPlatform
) and inject the UIView into the framework.AppController().RootView
.
This is a sample of how we were experimenting with it:
var mauiContext = new MauiContext(App.ServiceProvider);
overlay = new UnityPlayerOverlay();
overlay.Handler ??= overlay.ToHandler(mauiContext);
var overlayView = overlay.Handler.PlatformView as UIKit.UIView;
var controller = framework.AppController();
controller.RootView.AddSubview(overlayView);
controller.RootView.BringSubviewToFront(overlayView);
overlayView.Frame = controller.RootView.Frame;
overlayView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
overlayView.SetNeedsDisplay();
We found it worked (somewhat) but it caused issues with touch events inside the 3D player. At this point in time, we won't be pursuing it further.
Hopefully that answers your question!
@matthewrdev Thank you for reply! Sad to hear but it helps a lot.
Do you know if it has the same issues on other platforms? (As Unity has mentioned it on their page) Or is it just a MAUI problem?
@SGoerzen I would image this affects other platforms as Unity explicitly mentions it in their documentation.
To use native controls for Unity, the approach is to host them inside the Unity root view, rather than hosting the Unity viewer inside the native control.
Best of luck with the project!
@matthewrdev thanks for your quick answers!
tried out the Flutter widget and integrated my AR application into the Flutter app with working gesture control (Vuforia is still to be tested).
I really dislike Flutter... but I guess I need to use it for now.
For long term: What do you think, would it be possible to adapt this widget for MAUI? I think there is needed to adapt AppDelegate.cs and e.g. translate especially these classes into C# and MAUI: https://github.com/juicycleff/flutter-unity-view-widget/tree/master/ios/Classes
Is it worth trying it?
Hello,
I very like MAUI and your approach. Thanks for that!
It would be nice, if Unity can be somehow embedded in a subview instead of fullscreen. This way it would be easy to overlay MAUI controls over the application. I have seen many similar approach in other stacks (native ObjC, native Swift, ReactNative, Flutter).
I thought about to add another runEmbedded function and map it in maui by providing a UIView.
I am C# expert, but not ObjC or MAUI. So the scripts are not maybe not the correct way, but a first try for achieving this.
Unity project:
Classes/main.mm
add in UnityFramework.h
- (void)runEmbeddedWithArgc:(int)argc argv:(char*[])argv appLaunchOpts:(NSDictionary*)appLaunchOpts inView:(UIView*)parentView;
iOSBridge Project:
ApiDefinitions.cs (interface UnityFramework)
MAUI Project:
Extend UnityBridge.iOS.cs by following
and call this stuff from anywhere by element.
UnityBridge.ShowUnityWindow(unityHost.ToPlatform(Handler.MauiContext));
, whereunityHost
is aDo you have an idea how to solve this use case? @matthewrdev