@@ -2,9 +2,6 @@ part of flutter_unity_widget;
2
2
3
3
typedef void UnityCreatedCallback (UnityWidgetController controller);
4
4
5
- final UnityViewFlutterPlatform _unityViewFlutterPlatform =
6
- UnityViewFlutterPlatform .instance;
7
-
8
5
class UnityWidgetController {
9
6
final _UnityWidgetState _unityWidgetState;
10
7
@@ -25,7 +22,7 @@ class UnityWidgetController {
25
22
/// in [UnityWidget.onUnityCreated] callback.
26
23
static Future <UnityWidgetController > init (
27
24
int id, _UnityWidgetState unityWidgetState) async {
28
- await _unityViewFlutterPlatform .init (id);
25
+ await UnityViewFlutterPlatform .instance .init (id);
29
26
return UnityWidgetController ._(
30
27
unityWidgetState,
31
28
unityId: id,
@@ -34,30 +31,31 @@ class UnityWidgetController {
34
31
35
32
@visibleForTesting
36
33
MethodChannel ? get channel {
37
- if (_unityViewFlutterPlatform is MethodChannelUnityViewFlutter ) {
38
- return (_unityViewFlutterPlatform as MethodChannelUnityViewFlutter )
34
+ if (UnityViewFlutterPlatform .instance is MethodChannelUnityViewFlutter ) {
35
+ return (UnityViewFlutterPlatform .instance
36
+ as MethodChannelUnityViewFlutter )
39
37
.channel (unityId);
40
38
}
41
39
return null ;
42
40
}
43
41
44
42
void _connectStreams (int unityId) {
45
43
if (_unityWidgetState.widget.onUnityMessage != null ) {
46
- _onUnityMessageSub = _unityViewFlutterPlatform
44
+ _onUnityMessageSub = UnityViewFlutterPlatform .instance
47
45
.onUnityMessage (unityId: unityId)
48
46
.listen ((UnityMessageEvent e) =>
49
47
_unityWidgetState.widget.onUnityMessage !(e.value));
50
48
}
51
49
52
50
if (_unityWidgetState.widget.onUnitySceneLoaded != null ) {
53
- _onUnitySceneLoadedSub = _unityViewFlutterPlatform
51
+ _onUnitySceneLoadedSub = UnityViewFlutterPlatform .instance
54
52
.onUnitySceneLoaded (unityId: unityId)
55
53
.listen ((UnitySceneLoadedEvent e) =>
56
54
_unityWidgetState.widget.onUnitySceneLoaded !(e.value));
57
55
}
58
56
59
57
if (_unityWidgetState.widget.onUnityUnloaded != null ) {
60
- _onUnityUnloadedSub = _unityViewFlutterPlatform
58
+ _onUnityUnloadedSub = UnityViewFlutterPlatform .instance
61
59
.onUnityUnloaded (unityId: unityId)
62
60
.listen ((_) => _unityWidgetState.widget.onUnityUnloaded !());
63
61
}
@@ -67,7 +65,7 @@ class UnityWidgetController {
67
65
/// Returns `true` if unity player is ready.
68
66
Future <bool ?>? isReady () {
69
67
if (! _unityWidgetState.widget.enablePlaceholder) {
70
- return _unityViewFlutterPlatform .isReady (unityId: unityId);
68
+ return UnityViewFlutterPlatform .instance .isReady (unityId: unityId);
71
69
}
72
70
return null ;
73
71
}
@@ -76,7 +74,7 @@ class UnityWidgetController {
76
74
/// Returns `true` if unity player is paused.
77
75
Future <bool ?>? isPaused () {
78
76
if (! _unityWidgetState.widget.enablePlaceholder) {
79
- return _unityViewFlutterPlatform .isPaused (unityId: unityId);
77
+ return UnityViewFlutterPlatform .instance .isPaused (unityId: unityId);
80
78
}
81
79
return null ;
82
80
}
@@ -85,7 +83,7 @@ class UnityWidgetController {
85
83
/// Returns `true` if unity player is loaded.
86
84
Future <bool ?>? isLoaded () {
87
85
if (! _unityWidgetState.widget.enablePlaceholder) {
88
- return _unityViewFlutterPlatform .isLoaded (unityId: unityId);
86
+ return UnityViewFlutterPlatform .instance .isLoaded (unityId: unityId);
89
87
}
90
88
return null ;
91
89
}
@@ -94,7 +92,7 @@ class UnityWidgetController {
94
92
/// Returns `true` if unity player is in background.
95
93
Future <bool ?>? inBackground () {
96
94
if (! _unityWidgetState.widget.enablePlaceholder) {
97
- return _unityViewFlutterPlatform .inBackground (unityId: unityId);
95
+ return UnityViewFlutterPlatform .instance .inBackground (unityId: unityId);
98
96
}
99
97
return null ;
100
98
}
@@ -104,7 +102,8 @@ class UnityWidgetController {
104
102
/// Returns `true` if unity player was created succesfully.
105
103
Future <bool ?>? create () {
106
104
if (! _unityWidgetState.widget.enablePlaceholder) {
107
- return _unityViewFlutterPlatform.createUnityPlayer (unityId: unityId);
105
+ return UnityViewFlutterPlatform .instance
106
+ .createUnityPlayer (unityId: unityId);
108
107
}
109
108
return null ;
110
109
}
@@ -118,7 +117,7 @@ class UnityWidgetController {
118
117
/// ```
119
118
Future <void >? postMessage (String gameObject, methodName, message) {
120
119
if (! _unityWidgetState.widget.enablePlaceholder) {
121
- return _unityViewFlutterPlatform .postMessage (
120
+ return UnityViewFlutterPlatform .instance .postMessage (
122
121
unityId: unityId,
123
122
gameObject: gameObject,
124
123
methodName: methodName,
@@ -138,7 +137,7 @@ class UnityWidgetController {
138
137
Future <void >? postJsonMessage (
139
138
String gameObject, String methodName, Map <String , dynamic > message) {
140
139
if (! _unityWidgetState.widget.enablePlaceholder) {
141
- return _unityViewFlutterPlatform .postJsonMessage (
140
+ return UnityViewFlutterPlatform .instance .postJsonMessage (
142
141
unityId: unityId,
143
142
gameObject: gameObject,
144
143
methodName: methodName,
@@ -151,15 +150,15 @@ class UnityWidgetController {
151
150
/// Pause the unity in-game player with this method
152
151
Future <void >? pause () {
153
152
if (! _unityWidgetState.widget.enablePlaceholder) {
154
- return _unityViewFlutterPlatform .pausePlayer (unityId: unityId);
153
+ return UnityViewFlutterPlatform .instance .pausePlayer (unityId: unityId);
155
154
}
156
155
return null ;
157
156
}
158
157
159
158
/// Resume the unity in-game player with this method idf it is in a paused state
160
159
Future <void >? resume () {
161
160
if (! _unityWidgetState.widget.enablePlaceholder) {
162
- return _unityViewFlutterPlatform .resumePlayer (unityId: unityId);
161
+ return UnityViewFlutterPlatform .instance .resumePlayer (unityId: unityId);
163
162
}
164
163
return null ;
165
164
}
@@ -168,7 +167,8 @@ class UnityWidgetController {
168
167
/// It works for Android and iOS is WIP
169
168
Future <void >? openInNativeProcess () {
170
169
if (! _unityWidgetState.widget.enablePlaceholder) {
171
- return _unityViewFlutterPlatform.openInNativeProcess (unityId: unityId);
170
+ return UnityViewFlutterPlatform .instance
171
+ .openInNativeProcess (unityId: unityId);
172
172
}
173
173
return null ;
174
174
}
@@ -177,15 +177,15 @@ class UnityWidgetController {
177
177
/// iOS is WIP. For more information please read [Unity Docs] (https://docs.unity3d.com/2020.2/Documentation/Manual/UnityasaLibrary.html)
178
178
Future <void >? unload () {
179
179
if (! _unityWidgetState.widget.enablePlaceholder) {
180
- return _unityViewFlutterPlatform .unloadPlayer (unityId: unityId);
180
+ return UnityViewFlutterPlatform .instance .unloadPlayer (unityId: unityId);
181
181
}
182
182
return null ;
183
183
}
184
184
185
185
/// Quits unity player. Note that this kills the current flutter process, thus quiting the app
186
186
Future <void >? quit () {
187
187
if (! _unityWidgetState.widget.enablePlaceholder) {
188
- return _unityViewFlutterPlatform .quitPlayer (unityId: unityId);
188
+ return UnityViewFlutterPlatform .instance .quitPlayer (unityId: unityId);
189
189
}
190
190
return null ;
191
191
}
@@ -203,7 +203,7 @@ class UnityWidgetController {
203
203
204
204
void dispose () {
205
205
_cancelSubscriptions ();
206
- _unityViewFlutterPlatform .dispose (unityId: unityId);
206
+ UnityViewFlutterPlatform .instance .dispose (unityId: unityId);
207
207
}
208
208
}
209
209
0 commit comments