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;
|
||||
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
|
||||
EditCodeFile(path, line =>
|
||||
{
|
||||
|
@ -171,8 +198,6 @@ public static class XcodePostBuild
|
|||
"",
|
||||
"// Added by " + TouchedMarker,
|
||||
"+ (UnityAppController*)GetAppController;",
|
||||
"+ (void)addUnityEventListenerInternal:(id<UnityEventListener>)listener;",
|
||||
"+ (void)removeUnityEventListenerInternal:(id<UnityEventListener>)listener;",
|
||||
""
|
||||
};
|
||||
}
|
||||
|
@ -206,17 +231,7 @@ public static class XcodePostBuild
|
|||
" 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,
|
||||
"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)",
|
||||
"{",
|
||||
" for (id<UnityEventListener> listener in mUnityEventListeners) {",
|
||||
" [listener onMessage:[NSString stringWithUTF8String:message]];",
|
||||
" if (GetAppController().unityMessageHandler) {",
|
||||
" GetAppController().unityMessageHandler(message);",
|
||||
" }",
|
||||
"}",
|
||||
line,
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -330,6 +334,33 @@ public static class XcodePostBuild
|
|||
|
||||
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>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -63,7 +63,6 @@
|
|||
[_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
|
||||
[weakSelf onMethodCall:call result:result];
|
||||
}];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -94,6 +93,10 @@
|
|||
[UnityUtils createPlayer:^{
|
||||
[_uView setUnityView: (UIView*)[GetAppController() unityView]];
|
||||
}];
|
||||
[GetAppController() setUnityMessageHandler: ^(const char* message)
|
||||
{
|
||||
[_channel invokeMethod:@"onUnityMessage" arguments:[NSString stringWithUTF8String:message]];
|
||||
}];
|
||||
}
|
||||
return _uView;
|
||||
}
|
||||
|
|
|
@ -23,16 +23,10 @@ extern "C" {
|
|||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@protocol UnityEventListener <NSObject>
|
||||
- (void)onMessage:(NSString *)message;
|
||||
@end
|
||||
|
||||
@interface UnityUtils : NSObject
|
||||
|
||||
+ (BOOL)isUnityReady;
|
||||
+ (void)createPlayer:(void (^)(void))completed;
|
||||
+ (void)addUnityEventListener:(id<UnityEventListener>)listener;
|
||||
+ (void)removeUnityEventListener:(id<UnityEventListener>)listener;
|
||||
|
||||
@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
|
||||
|
|
Reference in New Issue