diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml deleted file mode 100644 index 53449da..0000000 --- a/.idea/libraries/Flutter_Plugins.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index dd94e31..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index eb76631..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 8d99ef5..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 2c37500..9116d94 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,16 @@ IOS will export unity project to `ios/UnityExport`. ```
+ +### AR Foundation (ANDROID only at the moment) +If you want to use Unity for integrating Augmented Reality in your Flutter app, a few more changes are required: + 1. Export the Unity Project as previously stated (using the Editor Build script). + 2. Check if the exported project includes all required Unity libraries (.so) files (`lib/\/libUnityARCore.so` and `libarpresto_api.so`). There seems to be a bug where a Unity export does not include all lib files. If they are missing, use Unity to build a standalone .apk of your AR project, unzip the resulting apk, and copy over the missing .lib files to the `UnityExport` module. + 3. Similar to how you've created the `unity-classes` module in Android Studio, create similar modules for all exported .aar and .jar files in the `UnityExport/libs` folder (`arcore_client.aar`, `unityandroidpermissions.aar`, `UnityARCore.aar`). + 4. Update the build.gradle script of the `UnityExport` module to depend on the new modules (again, similar to how it depends on `unity-classes`). + 5. Finally, update your Dart code build method where you include the `UnityWidget` and add `isARScene: true,`. + Sadly, this does have the side effect of making your Flutter activity act in full screen, as Unity requires control of your Activity for running in AR, and it makes several modifications to your Activity as a result (including setting it to full screen). + ### Add UnityMessageManager Support @@ -266,8 +276,11 @@ class _UnityDemoScreenState extends State{ ## API - pause() -## Known issues and their fix - - Android Export gradle issues +## Known issues + - no iOS support yet + - Android Export requires several manual changes + - Using AR will make the activity run in full screen (hiding status and navigation bar). + [version-badge]: https://img.shields.io/pub/v/flutter_unity_widget.svg?style=flat-square [package]: https://pub.dartlang.org/packages/flutter_unity_widget/versions/0.1.2 diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java index 024da8d..ba040c7 100644 --- a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java +++ b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java @@ -39,12 +39,21 @@ public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallH public void onMethodCall(MethodCall methodCall, final MethodChannel.Result result) { switch (methodCall.method) { case "createUnity": + String isAR; + isAR = methodCall.argument("isAR"); + + if (isAR != null) { + UnityUtils.isAR = true; + } + UnityUtils.createPlayer(registrar.activity(), new UnityUtils.CreateCallback() { @Override public void onReady() { - result.success(true); + result.success(true); } }); + + break; case "isReady": result.success(UnityUtils.isUnityReady()); diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityViewFactory.java b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityViewFactory.java index 0512dde..46e2e23 100644 --- a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityViewFactory.java +++ b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityViewFactory.java @@ -4,6 +4,8 @@ package com.rexraphael.flutterunitywidget; import android.content.Context; // import io.flutter.plugin.common.BinaryMessenger; +import java.util.Map; + import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.StandardMessageCodec; import io.flutter.plugin.platform.PlatformView; @@ -22,7 +24,13 @@ public class FlutterUnityViewFactory extends PlatformViewFactory { } @Override - public PlatformView create(Context context, int i, Object o) { + public PlatformView create(Context context, int i, Object args) { + Map params = (Map) args; + + if (params.containsKey("ar")) { + UnityUtils.isAR = (boolean) params.get("ar"); + } + return new FlutterUnityView(context, mPluginRegistrar, i); } } diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java b/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java index e41dec2..bb4730d 100644 --- a/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java +++ b/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java @@ -18,6 +18,8 @@ public class UnityUtils { void onReady(); } + public static boolean isAR = false; + private static UnityPlayer unityPlayer; private static boolean _isUnityReady; private static boolean _isUnityPaused; @@ -50,7 +52,7 @@ public class UnityUtils { public void run() { activity.getWindow().setFormat(PixelFormat.RGBA_8888); - unityPlayer = new UnityPlayer((ContextWrapper) activity.getApplicationContext()); + unityPlayer = new UnityPlayer(isAR ? activity : activity.getApplicationContext()); try { // wait a moument. fix unity cannot start when startup. diff --git a/lib/flutter_unity_widget.dart b/lib/flutter_unity_widget.dart index f9ac9a5..02b4fae 100644 --- a/lib/flutter_unity_widget.dart +++ b/lib/flutter_unity_widget.dart @@ -82,8 +82,10 @@ class UnityWidget extends StatefulWidget { ///Event fires when the [UnityWidget] gets a message from unity. final onUnityMessageCallback onUnityMessage; + final bool isARScene; + UnityWidget( - {Key key, @required this.onUnityViewCreated, this.onUnityMessage}); + {Key key, @required this.onUnityViewCreated, this.onUnityMessage, this.isARScene = false}); @override _UnityWidgetState createState() => _UnityWidgetState(); @@ -110,11 +112,15 @@ class _UnityWidgetState extends State { @override Widget build(BuildContext context) { + final Map creationParams = { + 'ar': widget.isARScene, + }; if (defaultTargetPlatform == TargetPlatform.android) { return AndroidView( viewType: 'unity_view', onPlatformViewCreated: _onPlatformViewCreated, creationParamsCodec: const StandardMessageCodec(), + creationParams: creationParams, ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { return UiKitView(