//***************************************************************************** @implementation MyIOSSdk //********************** //message tools + (void)sendU3dMessage:(NSString *)messageName param:(NSDictionary *)dict { NSString *param = @""; if ( nil != dict ) { for (NSString *key in dict) { if ([param length] == 0) { param = [param stringByAppendingFormat:@"%@=%@", key, [dict valueForKey:key]]; } else { param = [param stringByAppendingFormat:@"&%@=%@", key, [dict valueForKey:key]]; } } } UnitySendMessage("SDK_Object", [messageName UTF8String], [param UTF8String]); } //********************** //SDK fun //初始化SDK -(void)SDKInit { SDKcfg *cfg = [[[SDKcfg alloc] init] autorelease]; cfg.appid =123456; cfg.appKey =@"aoaoaoaoaoaoaoaoaoaoaoaoaaoaoaoaoaoaoao"; cfg.orientation = UIDeviceOrientationLandscapeLeft; //调用SDK的初始化函数 [[SDKPlatform defaultPlatform] SDKInit:cfg]; //添加回调监听 [[SDKPlatform defaultPlatform] addObserver:self selector:@selector(SNSInitResult:) name:(NSString *)kInitNotification object:nil]; } //获取用户ID -(NSString*)SDKGetUserID { [[SDKPlatform defaultPlatform] SDKGetUserID]; } //********************** //call back fun //初始化更新回调 - (void)SNSInitResult:(NSNotification *)notify { [MyIOSSdk sendU3dMessage:@"SDKMsgInit" param:nil]; } @end //***************************************************************************** #if defined(__cplusplus) extern "C"{ #endif //字符串转化的工具函数 NSString* _CreateNSString (const char* string) { if (string) return [NSString stringWithUTF8String: string]; else return [NSString stringWithUTF8String: ""]; } char* _MakeStringCopy( const char* string) { if (NULL == string) { return NULL; } char* res = (char*)malloc(strlen(string)+1); strcpy(res, string); return res; } static MyIOSSdk *mySDK; //供u3d调用的c函数 void _PlatformInit() { if(mySDK==NULL) { mySDK = [[MyIOSSdk alloc]init]; } [lsSDK SDKInit]; } //注意这个函数是返回字符串 const char* _PlatformGetUin() { if(lsSDK==NULL) { lsSDK = [[MyIOSSdk alloc]init]; } return _MakeStringCopy([[lsSDK SDKGetUserID] UTF8String]); } #if defined(__cplusplus) } #endif |