@@ -14,7 +14,9 @@ class MobileUnityWidgetController extends UnityWidgetController {
14
14
/// used for cancel the subscription
15
15
StreamSubscription ? _onUnityMessageSub,
16
16
_onUnitySceneLoadedSub,
17
- _onUnityUnloadedSub;
17
+ _onUnityUnloadedSub,
18
+ _onUnityAttachedSub,
19
+ _onUnityDetachedSub;
18
20
19
21
MobileUnityWidgetController ._(
20
22
this .unityWidgetState, {
@@ -34,6 +36,8 @@ class MobileUnityWidgetController extends UnityWidgetController {
34
36
unityWidgetState,
35
37
unityId: id,
36
38
);
39
+ await UnityWidgetPlatform .instance.init (id);
40
+ return controller;
37
41
}
38
42
39
43
void _connectStreams (int unityId) {
@@ -63,6 +67,22 @@ class MobileUnityWidgetController extends UnityWidgetController {
63
67
unityWidgetState.widget.onUnityUnloaded !();
64
68
});
65
69
}
70
+
71
+ if (_unityWidgetState.widget.onUnityAttached != null ) {
72
+ _onUnityAttachedSub = UnityWidgetPlatform .instance
73
+ .onUnityAttached (unityId: unityId)
74
+ .listen ((_) {
75
+ _unityWidgetState.widget.onUnityAttached !();
76
+ });
77
+ }
78
+
79
+ if (_unityWidgetState.widget.onUnityDetached != null ) {
80
+ _onUnityDetachedSub = UnityWidgetPlatform .instance
81
+ .onUnityDetached (unityId: unityId)
82
+ .listen ((_) {
83
+ _unityWidgetState.widget.onUnityDetached !();
84
+ });
85
+ }
66
86
}
67
87
68
88
/// Checks to see if unity player is ready to be used
@@ -200,10 +220,14 @@ class MobileUnityWidgetController extends UnityWidgetController {
200
220
_onUnityMessageSub? .cancel ();
201
221
_onUnitySceneLoadedSub? .cancel ();
202
222
_onUnityUnloadedSub? .cancel ();
223
+ _onUnityAttachedSub? .cancel ();
224
+ _onUnityDetachedSub? .cancel ();
203
225
204
226
_onUnityMessageSub = null ;
205
227
_onUnitySceneLoadedSub = null ;
206
228
_onUnityUnloadedSub = null ;
229
+ _onUnityAttachedSub = null ;
230
+ _onUnityDetachedSub = null ;
207
231
}
208
232
209
233
void dispose () {
0 commit comments