flutter_unity 0.3.0 flutter_unity: ^0.3.0 copied to clipboard
A Flutter plugin for embedding Unity projects in Flutter projects.
import 'package:flutter/material.dart';
import 'package:flutter_unity/flutter_unity.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => UnityViewPage()));
},
child: Text('Test'),
),
),
);
}
}
class UnityViewPage extends StatefulWidget {
@override
_UnityViewPageState createState() => _UnityViewPageState();
}
class _UnityViewPageState extends State<UnityViewPage> {
UnityViewController? unityViewController;
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: UnityView(
onCreated: onUnityViewCreated,
onReattached: onUnityViewReattached,
onMessage: onUnityViewMessage,
),
);
}
void onUnityViewCreated(UnityViewController? controller) {
print('onUnityViewCreated');
unityViewController = controller;
controller?.send(
'Cube',
'SetRotationSpeed',
'30',
);
}
void onUnityViewReattached(UnityViewController controller) {
print('onUnityViewReattached');
}
void onUnityViewMessage(UnityViewController controller, String? message) {
print('onUnityViewMessage');
print(message);
}
}