Merge pull request #1 from thomas-stockx/feature/ar
Add Unity AR Foundation support.
This commit is contained in:
commit
5277f942a8
|
@ -1,9 +0,0 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="7">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="6">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/flutter_unity_widget.iml" filepath="$PROJECT_DIR$/flutter_unity_widget.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/android/flutter_unity_widget_android.iml" filepath="$PROJECT_DIR$/android/flutter_unity_widget_android.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/example/android/flutter_unity_widget_example_android.iml" filepath="$PROJECT_DIR$/example/android/flutter_unity_widget_example_android.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/example/ios/.symlinks/plugins/flutter_unity_widget" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
17
README.md
17
README.md
|
@ -128,6 +128,16 @@ IOS will export unity project to `ios/UnityExport`.
|
|||
```
|
||||
|
||||
<br />
|
||||
|
||||
### 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/\<architecture\>/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<UnityDemoScreen>{
|
|||
## 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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<String, Object> params = (Map<String, Object>) args;
|
||||
|
||||
if (params.containsKey("ar")) {
|
||||
UnityUtils.isAR = (boolean) params.get("ar");
|
||||
}
|
||||
|
||||
return new FlutterUnityView(context, mPluginRegistrar, i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<UnityWidget> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Map<String, dynamic> creationParams = <String, dynamic>{
|
||||
'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(
|
||||
|
|
Reference in New Issue