Merge pull request #64 from krispypen/master
Fix + Cleanup onUnityMessage on iOS
This commit is contained in:
commit
a1d1572cd0
|
@ -155,6 +155,33 @@ public static class XcodePostBuild
|
||||||
inScope = false;
|
inScope = false;
|
||||||
markerDetected = false;
|
markerDetected = false;
|
||||||
|
|
||||||
|
// Modify inline GetAppController
|
||||||
|
EditCodeFile(path, line =>
|
||||||
|
{
|
||||||
|
inScope |= line.Contains("quitHandler)");
|
||||||
|
|
||||||
|
if (inScope && !markerDetected)
|
||||||
|
{
|
||||||
|
if (line.Trim() == "")
|
||||||
|
{
|
||||||
|
inScope = false;
|
||||||
|
markerDetected = true;
|
||||||
|
|
||||||
|
return new string[]
|
||||||
|
{
|
||||||
|
"@property (nonatomic, copy) void(^unityMessageHandler)(const char* message);",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string[] { line };
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string[] { line };
|
||||||
|
});
|
||||||
|
|
||||||
|
inScope = false;
|
||||||
|
markerDetected = false;
|
||||||
|
|
||||||
// Add static GetAppController
|
// Add static GetAppController
|
||||||
EditCodeFile(path, line =>
|
EditCodeFile(path, line =>
|
||||||
{
|
{
|
||||||
|
@ -171,8 +198,6 @@ public static class XcodePostBuild
|
||||||
"",
|
"",
|
||||||
"// Added by " + TouchedMarker,
|
"// Added by " + TouchedMarker,
|
||||||
"+ (UnityAppController*)GetAppController;",
|
"+ (UnityAppController*)GetAppController;",
|
||||||
"+ (void)addUnityEventListenerInternal:(id<UnityEventListener>)listener;",
|
|
||||||
"+ (void)removeUnityEventListenerInternal:(id<UnityEventListener>)listener;",
|
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -206,17 +231,7 @@ public static class XcodePostBuild
|
||||||
" return [UnityAppController GetAppController];",
|
" return [UnityAppController GetAppController];",
|
||||||
"}",
|
"}",
|
||||||
"",
|
"",
|
||||||
"// Added by " + TouchedMarker,
|
|
||||||
"static inline void addUnityEventListenerInternal(id<UnityEventListener> listener)",
|
|
||||||
"{",
|
|
||||||
" [UnityAppController addUnityEventListenerInternal: listener];",
|
|
||||||
"}",
|
|
||||||
"",
|
|
||||||
"// Added by " + TouchedMarker,
|
|
||||||
"static inline void removeUnityEventListenerInternal(id<UnityEventListener> listener)",
|
|
||||||
"{",
|
|
||||||
" [UnityAppController removeUnityEventListenerInternal:listener];",
|
|
||||||
"}"
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,25 +272,14 @@ public static class XcodePostBuild
|
||||||
"}",
|
"}",
|
||||||
"",
|
"",
|
||||||
"// Added by " + TouchedMarker,
|
"// Added by " + TouchedMarker,
|
||||||
"static NSHashTable* mUnityEventListeners = [NSHashTable weakObjectsHashTable];",
|
|
||||||
"+ (void)addUnityEventListener2:(id<UnityEventListener>)listener",
|
|
||||||
"{",
|
|
||||||
" [mUnityEventListeners addObject: listener];",
|
|
||||||
"}",
|
|
||||||
"",
|
|
||||||
"// Added by " + TouchedMarker,
|
|
||||||
"+(void)removeUnityEventListener2:(id<UnityEventListener>)listener",
|
|
||||||
"{",
|
|
||||||
" [mUnityEventListeners removeObject: listener];",
|
|
||||||
"}",
|
|
||||||
line,
|
|
||||||
"// Added by " + TouchedMarker,
|
|
||||||
"extern \"C\" void onUnityMessage(const char* message)",
|
"extern \"C\" void onUnityMessage(const char* message)",
|
||||||
"{",
|
"{",
|
||||||
" for (id<UnityEventListener> listener in mUnityEventListeners) {",
|
" if (GetAppController().unityMessageHandler) {",
|
||||||
" [listener onMessage:[NSString stringWithUTF8String:message]];",
|
" GetAppController().unityMessageHandler(message);",
|
||||||
" }",
|
" }",
|
||||||
"}",
|
"}",
|
||||||
|
line,
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,6 +334,33 @@ public static class XcodePostBuild
|
||||||
|
|
||||||
return new string[] { line };
|
return new string[] { line };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
inScope = false;
|
||||||
|
markerDetected = false;
|
||||||
|
|
||||||
|
// Modify inline GetAppController
|
||||||
|
EditCodeFile(path, line =>
|
||||||
|
{
|
||||||
|
inScope |= line.Contains("@synthesize quitHandler");
|
||||||
|
|
||||||
|
if (inScope && !markerDetected)
|
||||||
|
{
|
||||||
|
if (line.Trim() == "")
|
||||||
|
{
|
||||||
|
inScope = false;
|
||||||
|
markerDetected = true;
|
||||||
|
|
||||||
|
return new string[]
|
||||||
|
{
|
||||||
|
"@synthesize unityMessageHandler = _unityMessageHandler;",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string[] { line };
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string[] { line };
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -63,7 +63,6 @@
|
||||||
[_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
[_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||||
[weakSelf onMethodCall:call result:result];
|
[weakSelf onMethodCall:call result:result];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -94,6 +93,10 @@
|
||||||
[UnityUtils createPlayer:^{
|
[UnityUtils createPlayer:^{
|
||||||
[_uView setUnityView: (UIView*)[GetAppController() unityView]];
|
[_uView setUnityView: (UIView*)[GetAppController() unityView]];
|
||||||
}];
|
}];
|
||||||
|
[GetAppController() setUnityMessageHandler: ^(const char* message)
|
||||||
|
{
|
||||||
|
[_channel invokeMethod:@"onUnityMessage" arguments:[NSString stringWithUTF8String:message]];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
return _uView;
|
return _uView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,10 @@ extern "C" {
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@protocol UnityEventListener <NSObject>
|
|
||||||
- (void)onMessage:(NSString *)message;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface UnityUtils : NSObject
|
@interface UnityUtils : NSObject
|
||||||
|
|
||||||
+ (BOOL)isUnityReady;
|
+ (BOOL)isUnityReady;
|
||||||
+ (void)createPlayer:(void (^)(void))completed;
|
+ (void)createPlayer:(void (^)(void))completed;
|
||||||
+ (void)addUnityEventListener:(id<UnityEventListener>)listener;
|
|
||||||
+ (void)removeUnityEventListener:(id<UnityEventListener>)listener;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -158,21 +158,4 @@ static BOOL _isUnityReady = NO;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void onUnityMessage(const char* message)
|
|
||||||
{
|
|
||||||
for (id<UnityEventListener> listener in mUnityEventListeners) {
|
|
||||||
[listener onMessage:[NSString stringWithUTF8String:message]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (void)addUnityEventListener:(id<UnityEventListener>)listener
|
|
||||||
{
|
|
||||||
[mUnityEventListeners addObject:listener];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (void)removeUnityEventListener:(id<UnityEventListener>)listener
|
|
||||||
{
|
|
||||||
[mUnityEventListeners removeObject:listener];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Reference in New Issue