From d93c2fa42e2f7dadb597032ce1e4b4fdef4999a5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 23 Jul 2019 15:35:00 +0200 Subject: [PATCH 1/4] Update Readme.md as it crashes with Vulkan. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a6ff96c..aeed860 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,11 @@ Now your project files should look like this. 3. Change `Product Name` to Name of the Xcode project, You can find it follow `ios/${XcodeProjectName}.xcodeproj`. **Android Platform**: - 1. Change `Scripting Backend` to IL2CPP. + 1. Make sure your `Graphics APIs` are set to OpenGLES3 with a fallback to OpenGLES2 (no Vulkan) + + 2. Change `Scripting Backend` to IL2CPP. - 2. Mark the following `Target Architectures` : + 3. Mark the following `Target Architectures` : - ARMv7 ✅ - ARM64 ✅ - x86 ✅ @@ -276,4 +278,4 @@ class _UnityDemoScreenState extends State{ [github-watch-badge]: https://img.shields.io/github/watchers/snowballdigital/flutter-unity-view-widget.svg?style=social [github-watch]: https://github.com/snowballdigital/flutter-unity-view-widget/watchers [github-star-badge]: https://img.shields.io/github/stars/snowballdigital/flutter-unity-view-widget.svg?style=social -[github-star]: https://github.com/snowballdigital/flutter-unity-view-widget/stargazers \ No newline at end of file +[github-star]: https://github.com/snowballdigital/flutter-unity-view-widget/stargazers From 21669128b4bbce98e2b41e0f0ea80902955c2cd8 Mon Sep 17 00:00:00 2001 From: Thomas Stockx Date: Wed, 24 Jul 2019 13:27:27 +0200 Subject: [PATCH 2/4] Fix postMessage throwing exceptions on Android --- .idea/codeStyles/Project.xml | 29 -- .idea/libraries/Dart_SDK.xml | 19 - .idea/workspace.xml | 695 ---------------------------------- flutter_unity_widget.iml | 19 - lib/flutter_unity_widget.dart | 12 +- 5 files changed, 7 insertions(+), 767 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/libraries/Dart_SDK.xml delete mode 100644 .idea/workspace.xml delete mode 100644 flutter_unity_widget.iml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index 7221a18..0000000 --- a/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index f3f4a81..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,695 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - unityView - UnityUtils - getUnityView - inAppBrowserActivity - onMess - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1551719267177 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/flutter_unity_widget.iml b/flutter_unity_widget.iml deleted file mode 100644 index 73e7ebd..0000000 --- a/flutter_unity_widget.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lib/flutter_unity_widget.dart b/lib/flutter_unity_widget.dart index 5fea340..f9ac9a5 100644 --- a/lib/flutter_unity_widget.dart +++ b/lib/flutter_unity_widget.dart @@ -41,7 +41,11 @@ class UnityWidgetController { } postMessage(String gameObject, methodName, message) { - _channel.invokeMethod('postMessage', [gameObject, methodName, message]); + _channel.invokeMethod('postMessage', { + 'gameObject': gameObject, + 'methodName': methodName, + 'message': message, + }); } pause() async { @@ -78,7 +82,6 @@ class UnityWidget extends StatefulWidget { ///Event fires when the [UnityWidget] gets a message from unity. final onUnityMessageCallback onUnityMessage; - UnityWidget( {Key key, @required this.onUnityViewCreated, this.onUnityMessage}); @@ -87,17 +90,16 @@ class UnityWidget extends StatefulWidget { } class _UnityWidgetState extends State { - UnityWidgetController _controller; @override void initState() { - // widget.controller = + // widget.controller = super.initState(); } -@override + @override void dispose() { super.dispose(); if (_controller != null) { From 62bd95b43bc54d32b20c7d9e6253c67c80038539 Mon Sep 17 00:00:00 2001 From: Thomas Stockx Date: Wed, 24 Jul 2019 15:14:40 +0200 Subject: [PATCH 3/4] Remove java and UnityPlayer changes to the windowmanager so it can be fully handled by Flutter --- .../flutterunitywidget/UnityUtils.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java b/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java index b1317cd..e41dec2 100644 --- a/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java +++ b/android/src/main/java/com/rexraphael/flutterunitywidget/UnityUtils.java @@ -1,6 +1,7 @@ package com.rexraphael.flutterunitywidget; import android.app.Activity; +import android.content.ContextWrapper; import android.graphics.PixelFormat; import android.os.Build; import android.view.ViewGroup; @@ -48,13 +49,8 @@ public class UnityUtils { @Override public void run() { activity.getWindow().setFormat(PixelFormat.RGBA_8888); - int flag = activity.getWindow().getAttributes().flags; - boolean fullScreen = false; - if((flag & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) { - fullScreen = true; - } - unityPlayer = new UnityPlayer(activity); + unityPlayer = new UnityPlayer((ContextWrapper) activity.getApplicationContext()); try { // wait a moument. fix unity cannot start when startup. @@ -63,16 +59,11 @@ public class UnityUtils { } // start unity - addUnityViewToBackground(); + addUnityViewToBackground(activity); unityPlayer.windowFocusChanged(true); unityPlayer.requestFocus(); unityPlayer.resume(); - // restore window layout - if (!fullScreen) { - activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); - activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - } _isUnityReady = true; callback.onReady(); } @@ -120,7 +111,7 @@ public class UnityUtils { mUnityEventListeners.remove(listener); } - public static void addUnityViewToBackground() { + public static void addUnityViewToBackground(final Activity activity) { if (unityPlayer == null) { return; } @@ -130,7 +121,6 @@ public class UnityUtils { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { unityPlayer.setZ(-1f); } - final Activity activity = ((Activity)unityPlayer.getContext()); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(1, 1); activity.addContentView(unityPlayer, layoutParams); } From b0541d730216963a837d46e35dd2bde2f2d394a0 Mon Sep 17 00:00:00 2001 From: Thomas Stockx Date: Tue, 30 Jul 2019 10:44:09 +0200 Subject: [PATCH 4/4] Change input source of Flutter touch events so they get handled by Unity. --- .idea/codeStyles/Project.xml | 29 - .idea/workspace.xml | 695 ------------------ .../flutterunitywidget/UnityView.java | 9 + 3 files changed, 9 insertions(+), 724 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index f3f4a81..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,695 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - unityView - UnityUtils - getUnityView - inAppBrowserActivity - onMess - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1551719267177 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/UnityView.java b/android/src/main/java/com/rexraphael/flutterunitywidget/UnityView.java index 1d93c50..0741e89 100644 --- a/android/src/main/java/com/rexraphael/flutterunitywidget/UnityView.java +++ b/android/src/main/java/com/rexraphael/flutterunitywidget/UnityView.java @@ -2,6 +2,8 @@ package com.rexraphael.flutterunitywidget; import android.content.Context; import android.content.res.Configuration; +import android.view.InputDevice; +import android.view.MotionEvent; import android.widget.FrameLayout; import com.unity3d.player.UnityPlayer; @@ -35,6 +37,13 @@ public class UnityView extends FrameLayout { } } + @Override + public boolean dispatchTouchEvent(MotionEvent ev) { + ev.setSource(InputDevice.SOURCE_TOUCHSCREEN); + view.injectEvent(ev); + return super.dispatchTouchEvent(ev); + } + @Override protected void onDetachedFromWindow() { // todo: fix more than one unity view, don't add to background.