updated read me

This commit is contained in:
Rex Raphael 2019-03-28 19:05:38 +01:00
parent 94b96aab10
commit 9f115431f4
4 changed files with 54 additions and 15 deletions

View File

@ -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)
<br />
## 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/<Your Unity Project>/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.
<img src="https://github.com/snowballdigital/flutter-unity-view-widget/blob/master/Screenshot%202019-03-27%2008.13.08.png?raw=true" width="400" />
Android will export unity project to `android/UnityExport`.
@ -236,7 +239,7 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
```
## 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

View File

@ -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')
}

View File

@ -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<bool> 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<void> _dispose() async {
await _channel.invokeMethod('dispose');
}
Future<dynamic> _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<UnityWidget> {
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<UnityWidget> {
'$defaultTargetPlatform is not yet supported by this plugin');
}
Future<void> 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));
}
}

View File

@ -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 <rex.raphael@outlook.com>
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"