@@ -14,7 +14,9 @@ class MobileUnityWidgetController extends UnityWidgetController {
1414 /// used for cancel the subscription
1515 StreamSubscription ? _onUnityMessageSub,
1616 _onUnitySceneLoadedSub,
17- _onUnityUnloadedSub;
17+ _onUnityUnloadedSub,
18+ _onUnityAttachedSub,
19+ _onUnityDetachedSub;
1820
1921 MobileUnityWidgetController ._(
2022 this .unityWidgetState, {
@@ -34,6 +36,8 @@ class MobileUnityWidgetController extends UnityWidgetController {
3436 unityWidgetState,
3537 unityId: id,
3638 );
39+ await UnityWidgetPlatform .instance.init (id);
40+ return controller;
3741 }
3842
3943 void _connectStreams (int unityId) {
@@ -63,6 +67,22 @@ class MobileUnityWidgetController extends UnityWidgetController {
6367 unityWidgetState.widget.onUnityUnloaded !();
6468 });
6569 }
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+ }
6686 }
6787
6888 /// Checks to see if unity player is ready to be used
@@ -200,10 +220,14 @@ class MobileUnityWidgetController extends UnityWidgetController {
200220 _onUnityMessageSub? .cancel ();
201221 _onUnitySceneLoadedSub? .cancel ();
202222 _onUnityUnloadedSub? .cancel ();
223+ _onUnityAttachedSub? .cancel ();
224+ _onUnityDetachedSub? .cancel ();
203225
204226 _onUnityMessageSub = null ;
205227 _onUnitySceneLoadedSub = null ;
206228 _onUnityUnloadedSub = null ;
229+ _onUnityAttachedSub = null ;
230+ _onUnityDetachedSub = null ;
207231 }
208232
209233 void dispose () {
0 commit comments