diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a3de97a..643a203 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,7 +6,18 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -23,39 +34,48 @@
-
-
-
+
+
+
+
-
+
-
-
+
+
+
+
+
-
-
+
+
+
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
+
@@ -65,17 +85,8 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -83,28 +94,21 @@
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -113,48 +117,62 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
@@ -171,20 +189,25 @@
unityView
UnityUtils
+ getUnityView
+
+
+
@@ -193,11 +216,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -210,12 +250,6 @@
-
-
-
-
-
-
@@ -276,6 +310,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -299,44 +355,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -395,7 +413,7 @@
-
+
@@ -405,18 +423,19 @@
-
+
-
+
+
@@ -435,68 +454,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -507,23 +471,99 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/.idea/caches/build_file_checksums.ser b/android/.idea/caches/build_file_checksums.ser
index e6924e8..a0ca71b 100644
Binary files a/android/.idea/caches/build_file_checksums.ser and b/android/.idea/caches/build_file_checksums.ser differ
diff --git a/android/.idea/caches/gradle_models.ser b/android/.idea/caches/gradle_models.ser
index e6e5036..2473041 100644
Binary files a/android/.idea/caches/gradle_models.ser and b/android/.idea/caches/gradle_models.ser differ
diff --git a/android/.idea/vcs.xml b/android/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/android/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/build.gradle b/android/build.gradle
index 4fdeadb..c287741 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -34,5 +34,8 @@ android {
}
dependencies {
- implementation fileTree(include: ['*.jar'], dir: 'libs')
+ implementation project(':UnityExport')
+
+ //Remember to add unity jar from unity export as a module dependency and add the module below
+ // implementation project(':unity-jar')
}
\ No newline at end of file
diff --git a/android/libs/unity-classes.jar b/android/libs/unity-classes.jar
index 15251e0..d4a15d4 100644
Binary files a/android/libs/unity-classes.jar and b/android/libs/unity-classes.jar differ
diff --git a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java
index 14809af..edd0c4b 100644
--- a/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java
+++ b/android/src/main/java/com/rexraphael/flutterunitywidget/FlutterUnityView.java
@@ -12,8 +12,7 @@ import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformView;
@SuppressLint("NewApi")
-public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallHandler,
- View.OnAttachStateChangeListener, UnityEventListener {
+public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallHandler, UnityEventListener {
private final Context context;
UnityView unityView;
MethodChannel channel;
@@ -24,13 +23,13 @@ public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallH
this.registrar = registrar;
unityView = getUnityView(registrar);
- channel = new MethodChannel(registrar.messenger(), "nativeweb_" + id);
+ channel = new MethodChannel(registrar.messenger(), "unity_view");
channel.setMethodCallHandler(this);
}
@Override
- public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
+ public void onMethodCall(MethodCall methodCall, final MethodChannel.Result result) {
switch (methodCall.method) {
case "createUnity":
UnityUtils.createPlayer(registrar.activity(), new UnityUtils.CreateCallback() {
@@ -76,12 +75,12 @@ public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallH
private UnityView getUnityView(PluginRegistry.Registrar registrar) {
final UnityView view = new UnityView(registrar.context());
- view.addOnAttachStateChangeListener(this);
+ // view.addOnAttachStateChangeListener(this);
if (UnityUtils.getPlayer() != null) {
view.setUnityPlayer(UnityUtils.getPlayer());
} else {
- UnityUtils.createPlayer((Activity) context, new UnityUtils.CreateCallback() {
+ UnityUtils.createPlayer(registrar.activity(), new UnityUtils.CreateCallback() {
@Override
public void onReady() {
view.setUnityPlayer(UnityUtils.getPlayer());
@@ -106,17 +105,6 @@ public class FlutterUnityView implements PlatformView, MethodChannel.MethodCallH
}
}
-
- @Override
- public void onViewAttachedToWindow(View view) {
- restoreUnityUserState();
- }
-
- @Override
- public void onViewDetachedFromWindow(View view) {
-
- }
-
@Override
public void onMessage(String message) {
diff --git a/example/lib/main.dart b/example/lib/main.dart
index bb9c153..254d7e6 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -12,7 +12,6 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State {
- String _platformVersion = 'Unknown';
@override
void initState() {
@@ -27,7 +26,7 @@ class _MyAppState extends State {
title: const Text('Unity example app'),
),
body: Center(
- child: Text('Running on'),
+ child: UnityWidget(),
),
),
);
diff --git a/lib/flutter_unity_widget.dart b/lib/flutter_unity_widget.dart
index 4d0a9b3..80bc05b 100644
--- a/lib/flutter_unity_widget.dart
+++ b/lib/flutter_unity_widget.dart
@@ -4,28 +4,46 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
-typedef void FlutterUnityWidgetCreatedCallback(UnityWidgetController controller);
+typedef void UnityWidgetCreatedCallback(UnityWidgetController controller);
class UnityWidgetController {
static MethodChannel _channel =
- const MethodChannel('flutter_unity_widget');
+ const MethodChannel('unity_view');
UnityWidgetController();
init(int id) {
- _channel = new MethodChannel('nativeweb_$id');
+ _channel = new MethodChannel('unity_view');
}
- static Future get platformVersion async {
- final String version = await _channel.invokeMethod('getPlatformVersion');
- return version;
+ Future isReady() async {
+ final bool isReady = await _channel.invokeMethod('isReady');
+ return isReady;
+ }
+
+ Future createUnity() async {
+ final bool isReady = await _channel.invokeMethod('createUnity');
+ return isReady;
+ }
+
+
+ postMessage(String gameObject, methodName, message){
+ _channel.invokeMethod('postMessage', [gameObject, methodName, message]);
+ }
+
+ pause() async{
+ await _channel.invokeMethod('pause');
+ }
+
+ resume() async{
+ await _channel.invokeMethod('resume');
}
}
class UnityWidget extends StatefulWidget {
- UnityWidgetController onUnityViewCreated;
+ UnityWidgetCreatedCallback onUnityViewCreated;
UnityWidget({
Key key,
@@ -41,14 +59,14 @@ class _UnityWidgetState extends State {
Widget build(BuildContext context) {
if(defaultTargetPlatform == TargetPlatform.android) {
return AndroidView(
- viewType: 'unityview',
+ viewType: 'unity_view',
onPlatformViewCreated: onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
} else if(defaultTargetPlatform == TargetPlatform.iOS) {
return UiKitView(
- viewType: 'unityview',
+ viewType: 'unity_view',
onPlatformViewCreated: onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
@@ -61,7 +79,7 @@ class _UnityWidgetState extends State {
if (widget.onUnityViewCreated == null) {
return;
}
- widget.onUnityViewCreated = new UnityWidgetController().init(id);
+ widget.onUnityViewCreated(new UnityWidgetController().init(id));
}
}
diff --git a/pubspec.yaml b/pubspec.yaml
index dd723c1..97dd183 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,8 +1,9 @@
name: flutter_unity_widget
description: Flutter unity 3D widget for embedding unity in flutter
-version: 0.0.1
-author:
-homepage:
+version: 0.1.2
+authors:
+ - Rex Raphael
+homepage: https://github.com/juicycleff/flutter-unity-view-widget/tree/master
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"