.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) + 1); strcpy(res, string); return res; }