diff --git a/README.md b/README.md
index 9ae9a8b..0ead409 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,8 @@ import 'package:flutter_graphql/flutter_graphql.dart';
## Preview
+![gif](https://github.com/snowballdigital/flutter-unity-view-widget/blob/master/2019_03_27_22_09_38.gif?raw=true)
+
## Setup Project
@@ -81,6 +83,7 @@ Now your project files should look like this.
Copy [`Build.cs`](https://github.com/f111fei/react-native-unity-demo/blob/master/unity/Cube/Assets/Scripts/Editor/Build.cs) and [`XCodePostBuild.cs`](https://github.com/f111fei/react-native-unity-demo/blob/master/unity/Cube/Assets/Scripts/Editor/XCodePostBuild.cs) to `unity//Assets/Scripts/Editor/`
Open your unity project in Unity Editor. Now you can export unity project with `Flutter/Export Android` or `Flutter/Export IOS` menu.
+
Android will export unity project to `android/UnityExport`.
@@ -236,7 +239,7 @@ class _UnityDemoScreenState extends State{
```
## Known issues and their fix
- - Android Export gragle issues
+ - Android Export gradle issues
[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
diff --git a/android/build.gradle b/android/build.gradle
index d19aac0..dc34d7b 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -35,7 +35,6 @@ android {
dependencies {
implementation project(':UnityExport')
-
//Remember to add unity jar from unity export as a module dependency and add the module below
implementation project(':unity-classes')
}
\ No newline at end of file
diff --git a/lib/flutter_unity_widget.dart b/lib/flutter_unity_widget.dart
index f8c2682..5fea340 100644
--- a/lib/flutter_unity_widget.dart
+++ b/lib/flutter_unity_widget.dart
@@ -8,19 +8,26 @@ typedef void UnityWidgetCreatedCallback(UnityWidgetController controller);
class UnityWidgetController {
UnityWidget _widget;
+ int _id;
static MethodChannel _channel = const MethodChannel('unity_view');
- UnityWidgetController();
-
- /*init(int id, UnityWidget widget) {
+ UnityWidgetController(int id, UnityWidget widget) {
+ _id = id;
+ _channel.setMethodCallHandler(_handleMethod);
_channel = new MethodChannel('unity_view_$id');
_channel.setMethodCallHandler(_handleMethod);
- _widget = widget;
- }*/
+ print('********************************************');
+ print('Controller setup complete');
+ print('********************************************');
+ }
init(int id) {
+ _id = id;
_channel = new MethodChannel('unity_view_$id');
_channel.setMethodCallHandler(_handleMethod);
+ print('********************************************');
+ print('Controller setup complete');
+ print('********************************************');
}
Future isReady() async {
@@ -38,6 +45,7 @@ class UnityWidgetController {
}
pause() async {
+ print('Pressed paused');
await _channel.invokeMethod('pause');
}
@@ -45,6 +53,10 @@ class UnityWidgetController {
await _channel.invokeMethod('resume');
}
+ Future _dispose() async {
+ await _channel.invokeMethod('dispose');
+ }
+
Future _handleMethod(MethodCall call) async {
switch (call.method) {
case "onUnityMessage":
@@ -66,6 +78,7 @@ 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});
@@ -74,18 +87,37 @@ class UnityWidget extends StatefulWidget {
}
class _UnityWidgetState extends State {
+
+ UnityWidgetController _controller;
+
+ @override
+ void initState() {
+ // widget.controller =
+
+ super.initState();
+ }
+
+@override
+ void dispose() {
+ super.dispose();
+ if (_controller != null) {
+ _controller._dispose();
+ _controller = null;
+ }
+ }
+
@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.android) {
return AndroidView(
viewType: 'unity_view',
- onPlatformViewCreated: onPlatformViewCreated,
+ onPlatformViewCreated: _onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
return UiKitView(
viewType: 'unity_view',
- onPlatformViewCreated: onPlatformViewCreated,
+ onPlatformViewCreated: _onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
}
@@ -94,10 +126,15 @@ class _UnityWidgetState extends State {
'$defaultTargetPlatform is not yet supported by this plugin');
}
- Future onPlatformViewCreated(id) async {
- if (widget.onUnityViewCreated == null) {
- return;
+ @override
+ void didUpdateWidget(UnityWidget oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ }
+
+ void _onPlatformViewCreated(int id) {
+ _controller = UnityWidgetController(id, widget);
+ if (widget.onUnityViewCreated != null) {
+ widget.onUnityViewCreated(_controller);
}
- widget.onUnityViewCreated(new UnityWidgetController().init(id));
}
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 97dd183..f24edb5 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,9 +1,9 @@
name: flutter_unity_widget
description: Flutter unity 3D widget for embedding unity in flutter
-version: 0.1.2
+version: 0.1.3
authors:
- Rex Raphael
-homepage: https://github.com/juicycleff/flutter-unity-view-widget/tree/master
+homepage: https://github.com/snowballdigital/flutter-unity-view-widget/tree/master
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"