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/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 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); } 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. 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) {