-
Notifications
You must be signed in to change notification settings - Fork 591
Expand file tree
/
Copy pathno_interaction_screen.dart
More file actions
94 lines (83 loc) · 2.52 KB
/
no_interaction_screen.dart
File metadata and controls
94 lines (83 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
class NoInteractionScreen extends StatefulWidget {
const NoInteractionScreen({super.key});
@override
State<NoInteractionScreen> createState() => _NoInteractionScreenState();
}
class _NoInteractionScreenState extends State<NoInteractionScreen> {
UnityWidgetController? _unityWidgetController;
@override
void initState() {
super.initState();
}
@override
void dispose() {
_unityWidgetController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('No Interaction Screen'),
),
body: Card(
margin: const EdgeInsets.all(8),
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
child: Stack(
children: [
UnityWidget(
onUnityCreated: _onUnityCreated,
onUnityMessage: onUnityMessage,
onUnitySceneLoaded: onUnitySceneLoaded,
useAndroidViewSurface: true,
borderRadius: const BorderRadius.all(Radius.circular(70)),
),
Positioned(
bottom: 20,
left: 20,
right: 20,
child: PointerInterceptor(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pushNamed('/simple');
},
child: const Text('Switch Flutter Screen'),
),
),
),
],
),
),
);
}
void setRotationSpeed(String speed) {
_unityWidgetController?.postMessage(
'Cube',
'SetRotationSpeed',
speed,
);
}
void onUnityMessage(dynamic message) {
print('Received message from unity: ${message.toString()}');
}
void onUnitySceneLoaded(SceneLoaded? scene) {
if (scene != null) {
print('Received scene loaded from unity: ${scene.name}');
print('Received scene loaded from unity buildIndex: ${scene.buildIndex}');
} else {
print('Received scene loaded from unity: null');
}
}
// Callback that connects the created controller to the unity controller
void _onUnityCreated(UnityWidgetController controller) {
controller.resume();
_unityWidgetController = controller;
}
}