@@ -18,7 +18,9 @@ class MobileUnityWidgetController extends UnityWidgetController {
18
18
/// used for cancel the subscription
19
19
StreamSubscription ? _onUnityMessageSub,
20
20
_onUnitySceneLoadedSub,
21
- _onUnityUnloadedSub;
21
+ _onUnityUnloadedSub,
22
+ _onUnityAttachedSub,
23
+ _onUnityDetachedSub;
22
24
23
25
MobileUnityWidgetController ._(this ._unityWidgetState,
24
26
{required this .unityId}) {
@@ -30,11 +32,12 @@ class MobileUnityWidgetController extends UnityWidgetController {
30
32
/// in [UnityWidget.onUnityCreated] callback.
31
33
static Future <MobileUnityWidgetController > init (
32
34
int id, MobileUnityWidgetState unityWidgetState) async {
33
- await UnityWidgetPlatform .instance.init (id);
34
- return MobileUnityWidgetController ._(
35
+ final controller = MobileUnityWidgetController ._(
35
36
unityWidgetState,
36
37
unityId: id,
37
38
);
39
+ await UnityWidgetPlatform .instance.init (id);
40
+ return controller;
38
41
}
39
42
40
43
@visibleForTesting
@@ -66,6 +69,22 @@ class MobileUnityWidgetController extends UnityWidgetController {
66
69
.onUnityUnloaded (unityId: unityId)
67
70
.listen ((_) => _unityWidgetState.widget.onUnityUnloaded !());
68
71
}
72
+
73
+ if (_unityWidgetState.widget.onUnityAttached != null ) {
74
+ _onUnityAttachedSub = UnityWidgetPlatform .instance
75
+ .onUnityAttached (unityId: unityId)
76
+ .listen ((_) {
77
+ _unityWidgetState.widget.onUnityAttached !();
78
+ });
79
+ }
80
+
81
+ if (_unityWidgetState.widget.onUnityDetached != null ) {
82
+ _onUnityDetachedSub = UnityWidgetPlatform .instance
83
+ .onUnityDetached (unityId: unityId)
84
+ .listen ((_) {
85
+ _unityWidgetState.widget.onUnityDetached !();
86
+ });
87
+ }
69
88
}
70
89
71
90
/// Checks to see if unity player is ready to be used
@@ -200,10 +219,14 @@ class MobileUnityWidgetController extends UnityWidgetController {
200
219
_onUnityMessageSub? .cancel ();
201
220
_onUnitySceneLoadedSub? .cancel ();
202
221
_onUnityUnloadedSub? .cancel ();
222
+ _onUnityAttachedSub? .cancel ();
223
+ _onUnityDetachedSub? .cancel ();
203
224
204
225
_onUnityMessageSub = null ;
205
226
_onUnitySceneLoadedSub = null ;
206
227
_onUnityUnloadedSub = null ;
228
+ _onUnityAttachedSub = null ;
229
+ _onUnityDetachedSub = null ;
207
230
}
208
231
209
232
void dispose () {
0 commit comments