Updated README.md
This commit is contained in:
parent
80b95b2abd
commit
a46532d116
87
README.md
87
README.md
|
@ -208,68 +208,95 @@ class _UnityDemoScreenState extends State<UnityDemoScreen>{
|
|||
|
||||
```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<UnityDemoScreen>{
|
||||
class _MyAppState extends State<MyApp> {
|
||||
static final GlobalKey<ScaffoldState> _scaffoldKey =
|
||||
GlobalKey<ScaffoldState>();
|
||||
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(
|
||||
body: Card(
|
||||
margin: const EdgeInsets.all(8),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
UnityWidget(
|
||||
onUnityViewCreated: onUnityCreated,
|
||||
isARScene: false,
|
||||
onUnityMessage: onUnityMessage,
|
||||
),
|
||||
Positioned(
|
||||
bottom: 40.0,
|
||||
left: 80.0,
|
||||
right: 80.0,
|
||||
child: MaterialButton(
|
||||
onPressed: () {
|
||||
|
||||
if(paused) {
|
||||
_unityWidgetController.resume();
|
||||
bottom: 20,
|
||||
left: 20,
|
||||
right: 20,
|
||||
child: Card(
|
||||
elevation: 10,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: Text("Rotation speed:"),
|
||||
),
|
||||
Slider(
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
paused = false;
|
||||
_sliderValue = value;
|
||||
});
|
||||
} else {
|
||||
_unityWidgetController.pause();
|
||||
setState(() {
|
||||
paused = true;
|
||||
});
|
||||
}
|
||||
setRotationSpeed(value.toString());
|
||||
},
|
||||
color: Colors.blue[500],
|
||||
child: Text(paused ? 'Start Game' : 'Pause Game'),
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue