Object-c 调用unity的 UIViewController和UnitySendMessage

.mm文件中实现

#import <UIKit/UIKit.h>

extern UIViewController *UnityGetGLViewController();
extern "C" void UnitySendMessage(const char *, const char *, const char *); @interface UniWebViewToolBar : NSObject @end @implementation UniWebViewToolBar @end

访问unityView

UIView *unityView = UnityGetGLViewController().view;
[unityView addSubview:webView];

发送消息

UnitySendMessage([webViewName UTF8String], "ClickBack", "");

C与Object-c字符串互转

NSString* MakeNSString (const char* string) {
if (string) {
return [NSString stringWithUTF8String: string];
} else {
return [NSString stringWithUTF8String: ""];
}
} char* MakeCString(NSString *str) {
const char* string = [str UTF8String];
if (string == NULL) {
return NULL;
} char* res = (char*)malloc(strlen(string) + );
strcpy(res, string);
return res;
}
上一篇:MaxScale:实现MySQL读写分离与负载均衡的中间件利器


下一篇:Linux学习一周初体验