From a46532d1164930dc2e66abb32e58735455ecdd99 Mon Sep 17 00:00:00 2001 From: Thomas Stockx Date: Thu, 17 Oct 2019 13:29:57 +0200 Subject: [PATCH] Updated README.md --- README.md | 109 +++++++++++++++++++++++++++++----------------- example/README.md | 3 +- 2 files changed, 70 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 20e7af9..4f720e6 100644 --- a/README.md +++ b/README.md @@ -208,68 +208,95 @@ class _UnityDemoScreenState extends State{ ```dart import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_unity_widget/flutter_unity_widget.dart'; -class UnityDemoScreen extends StatefulWidget { - - UnityDemoScreen({Key key}) : super(key: key); +void main() => runApp(MyApp()); +class MyApp extends StatefulWidget { @override - _UnityDemoScreenState createState() => _UnityDemoScreenState(); + _MyAppState createState() => _MyAppState(); } -class _UnityDemoScreenState extends State{ +class _MyAppState extends State { static final GlobalKey _scaffoldKey = GlobalKey(); UnityWidgetController _unityWidgetController; - bool paused = false; + double _sliderValue = 0.0; + @override + void initState() { + super.initState(); + } + @override Widget build(BuildContext context) { - - return Scaffold( - key: _scaffoldKey, - body: Scaffold( + return MaterialApp( + home: Scaffold( key: _scaffoldKey, appBar: AppBar( title: const Text('Unity Flutter Demo'), ), - body: Container( - child: Stack( - children: [ - UnityWidget( - onUnityViewCreated: onUnityCreated, - ), - Positioned( - bottom: 40.0, - left: 80.0, - right: 80.0, - child: MaterialButton( - onPressed: () { - - if(paused) { - _unityWidgetController.resume(); - setState(() { - paused = false; - }); - } else { - _unityWidgetController.pause(); - setState(() { - paused = true; - }); - } - }, - color: Colors.blue[500], - child: Text(paused ? 'Start Game' : 'Pause Game'), + body: Card( + margin: const EdgeInsets.all(8), + clipBehavior: Clip.antiAlias, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20.0), + ), + child: Stack( + children: [ + UnityWidget( + onUnityViewCreated: onUnityCreated, + isARScene: false, + onUnityMessage: onUnityMessage, ), - ), - ], - )), + Positioned( + bottom: 20, + left: 20, + right: 20, + child: Card( + elevation: 10, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.only(top: 20), + child: Text("Rotation speed:"), + ), + Slider( + onChanged: (value) { + setState(() { + _sliderValue = value; + }); + setRotationSpeed(value.toString()); + }, + value: _sliderValue, + min: 0, + max: 20, + ), + ], + ), + ), + ), + ], + ), + ), ), ); } + // Communcation from Flutter to Unity + void setRotationSpeed(String speed) { + _unityWidgetController.postMessage( + 'Cube', + 'SetRotationSpeed', + speed, + ); + } + + // Communication from Unity to Flutter + void onUnityMessage(controller, message) { + print('Received message from unity: ${message.toString()}'); + } + // Callback that connects the created controller to the unity controller void onUnityCreated(controller) { this._unityWidgetController = controller; diff --git a/example/README.md b/example/README.md index 442698c..277354d 100644 --- a/example/README.md +++ b/example/README.md @@ -5,7 +5,8 @@ Demonstrates how to use the flutter_unity_widget plugin. ## Run the sample on Android 1. Open the `unity` project and build it: Menu -> Flutter -> Export Android - 2. `flutter run` + 2. Copy `android/UnityExport/libs/unity-classes.jar` to `android/unity-classes/unity-classes.jar` and overwrite the existing file. You only need to do this each time you use a different Unity version. + 3. `flutter run` ## Run the sample on iOS 1. Open the `unity` project and build it: Menu -> Flutter -> Export iOS