@@ -53,6 +53,9 @@ - (instancetype)initWithFrame:(CGRect)frame
5353 if ([super init ]) {
5454 _viewId = viewId;
5555
56+ NSLog (@" *********************************************" );
57+ NSLog (@" super init" );
58+ NSLog (@" *********************************************" );
5659 NSString * channelName = [NSString stringWithFormat: @" plugins.xraph.com/unity_view_%lld " , viewId];
5760 _channel = [FlutterMethodChannel methodChannelWithName: channelName binaryMessenger: registrar.messenger];
5861 __weak __typeof__ (self) weakSelf = self;
@@ -87,7 +90,7 @@ - (instancetype)initWithFrame:(CGRect)frame
8790
8891- (void )initView {
8992 _uView = [[FLTUnityView alloc ] init ];
90- if ([UnityUtils isUnityReady ] && IsUnityLoaded () ) {
93+ if ([UnityUtils isUnityReady ]) {
9194 [_uView setUnityView: (UIView*)[GetAppController () unityView ]];
9295 } else {
9396 [UnityUtils createPlayer: ^{
@@ -119,7 +122,7 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
119122 NSNumber * res = @(IsUnityLoaded ());
120123 result (res);
121124 } else if ([call.method isEqualToString: @" createUnity" ]) {
122- [self createPlayer: call ];
125+ [self initView ];
123126 result (nil );
124127 } else if ([call.method isEqualToString: @" isPaused" ]) {
125128 NSNumber * res = @(IsUnityPaused ());
@@ -169,11 +172,8 @@ - (void)resumePlayer:(FlutterMethodCall*)call result:(FlutterResult)result {
169172}
170173
171174- (void )unloadPlayer : (FlutterMethodCall*)call result : (FlutterResult)result {
172- if (_disableUnload) {
173- UnityPauseCommand ();
174- } else {
175- UnityUnloadCommand ();
176- }
175+ [UnityUtils unloadUnity ];
176+ [_uView setUnityView: nil ];
177177 result (nil );
178178}
179179
@@ -204,31 +204,7 @@ - (void)setAREnabled:(BOOL)enabled {
204204
205205
206206- (void )createPlayer : ()call {
207- if (_uView) {
208- if (!IsUnityLoaded ()) {
209- [UnityUtils resetUnityReady ];
210- }
211- [UnityUtils recreatePlayer: ^{
212- [_uView setUnityView: (UIView*)[GetAppController () unityView ]];
213- }];
214- [GetAppController () setUnityMessageHandler: ^(const char * message)
215- {
216- [_channel invokeMethod: @" onUnityMessage" arguments: [NSString stringWithUTF8String: message]];
217- }];
218- [GetAppController () setUnitySceneLoadedHandler: ^(const char *name, const int *buildIndex, const bool *isLoaded, const bool *IsValid)
219- {
220- NSDictionary *addObject = @{
221- @" name" : [NSString stringWithUTF8String: name],
222- @" buildIndex" : [NSNumber numberWithInt: buildIndex],
223- @" isLoaded" : [NSNumber numberWithBool: isLoaded],
224- @" FourthKey" : [NSNumber numberWithBool: IsValid]
225- };
226-
227- [_channel invokeMethod: @" onUnitySceneLoaded" arguments: addObject];
228- }];
229- } else {
230- [self initView ];
231- }
207+ [self initView ];
232208}
233209
234210- (UIView*)view {
0 commit comments