From c86d50e2698b8dea0d0679018321f60df46a8c7f Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Sun, 5 Apr 2020 23:24:09 -0400 Subject: [PATCH] Disabled disposing of the native Unity player. Improved documentation and type annotations. --- .gitignore | 23 +++-- .../flutterunitywidget/FlutterUnityView.java | 2 +- example/.flutter-plugins-dependencies | 2 +- example/.gitignore | 87 ------------------- lib/flutter_unity_widget.dart | 38 ++++---- 5 files changed, 35 insertions(+), 117 deletions(-) delete mode 100644 example/.gitignore diff --git a/.gitignore b/.gitignore index ba5596d..5875314 100644 --- a/.gitignore +++ b/.gitignore @@ -25,20 +25,23 @@ node_modules/ # Flutter/Dart/Pub related **/doc/api/ -.dart_tool/ -.flutter-plugins -.packages -.pub-cache/ -.pub/ -build/ +**/.dart_tool/ +**/.flutter-plugins +**/.packages +**/.pub-cache/ +**/.pub/ +**/build/ -android/UnityExport/ +**/android/UnityExport/ +**/ios/UnityExport/ #example/ example/unity/DemoApp/Builds/ example/unity/DemoApp/Library/ example/unity/DemoApp/Logs/ example/unity/DemoApp/Temp/ +example/unity/DemoApp/.vs +example/coverage/ # Android related **/android/**/gradle-wrapper.jar @@ -49,6 +52,9 @@ example/unity/DemoApp/Temp/ **/android/local.properties **/android/**/GeneratedPluginRegistrant.java +**/android/key.properties +*.jks + # iOS/XCode related **/ios/**/*.mode1v3 **/ios/**/*.mode2v3 @@ -74,6 +80,7 @@ example/unity/DemoApp/Temp/ **/ios/Flutter/flutter_assets/ **/ios/ServiceDefinitions.json **/ios/Runner/GeneratedPluginRegistrant.* +**/ios/Flutter/flutter_export_environment.sh # Exceptions to above rules. !**/ios/**/default.mode1v3 @@ -82,4 +89,4 @@ example/unity/DemoApp/Temp/ !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages -example/unity/ARDemoApp/test \ No newline at end of file +example/unity/ARDemoApp/test diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java index 84ee3d4..bacedf8 100644 --- a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java +++ b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java @@ -89,7 +89,7 @@ public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallH @Override public void dispose() { if (UnityUtils.isUnityReady()) { - UnityUtils.getPlayer().quit(); + // UnityUtils.getPlayer().quit(); } } diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index e6ba6b6..480e61c 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_unity_widget","dependencies":[]}]} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_unity_widget","path":"/Users/michael/.pub-cache/hosted/pub.dartlang.org/flutter_unity_widget-0.1.6+8/","dependencies":[]}],"android":[{"name":"flutter_unity_widget","path":"/Users/michael/.pub-cache/hosted/pub.dartlang.org/flutter_unity_widget-0.1.6+8/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_unity_widget","dependencies":[]}],"date_created":"2020-04-05 22:00:19.385164","version":"1.14.6"} \ No newline at end of file diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index 28d2588..0000000 --- a/example/.gitignore +++ /dev/null @@ -1,87 +0,0 @@ -# Miscellaneous -*.class -*.lock -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# Visual Studio Code related -.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ -.dart_tool/ -.flutter-plugins -.packages -.pub-cache/ -.pub/ -build/ - -android/UnityExport/ -ios/UnityExport/ -unity/DemoApp/.vs - -#example/ -example/unity/DemoApp/Builds/ -example/unity/DemoApp/Library/ -example/unity/DemoApp/Logs/ -example/unity/DemoApp/Temp/ - -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java -**/android/key.properties -*.jks - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* - -# Coverage -coverage/ - -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages \ No newline at end of file diff --git a/lib/flutter_unity_widget.dart b/lib/flutter_unity_widget.dart index 52d55fa..929999b 100644 --- a/lib/flutter_unity_widget.dart +++ b/lib/flutter_unity_widget.dart @@ -24,37 +24,33 @@ class UnityWidgetController { ); } - Future isReady() async { - final bool isReady = await channel.invokeMethod('isReady'); - return isReady; - } + /// Returns true if Unity is ready and false otherwise. + Future isReady() => channel.invokeMethod('isReady'); - Future createUnity() async { - final bool isReady = await channel.invokeMethod('createUnity'); - return isReady; - } + /// Returns true once Unity is ready. + Future createUnity() => channel.invokeMethod('createUnity'); - postMessage(String gameObject, methodName, message) { - channel.invokeMethod('postMessage', { + Future postMessage(String gameObject, methodName, message) => channel.invokeMethod('postMessage', { 'gameObject': gameObject, 'methodName': methodName, 'message': message, }); - } - pause() async { + /// Unless an error is thrown, always returns true. + Future pause() { print('Pressed paused'); - await channel.invokeMethod('pause'); + return channel.invokeMethod('pause'); } - resume() async { - await channel.invokeMethod('resume'); - } + /// Unless an error is thrown, always returns true. + Future resume() => channel.invokeMethod('resume'); + /// Called from [UnityWidget.dispose] Future _dispose() async { - await channel.invokeMethod('dispose'); + // await channel.invokeMethod('dispose'); } + /// Handles a method call from Android (on behalf of Unity) to Flutter. Future _handleMethod(MethodCall call) async { switch (call.method) { case "onUnityMessage": @@ -136,11 +132,13 @@ class _UnityWidgetState extends State { void _onPlatformViewCreated(int id) { _controller = UnityWidgetController.init(id, this); + + print('--------------------------------------------'); + print('| Internal setup complete '); + print('--------------------------------------------'); + if (widget.onUnityViewCreated != null) { widget.onUnityViewCreated(_controller); } - print('********************************************'); - print('Controller setup complete'); - print('********************************************'); } }