| | |
| | | _project.AddFileToBuild(_targetGUID, _project.AddFile("/usr/lib/libiconv.tbd", "Frameworks/libiconv.tbd", PBXSourceTree.Sdk)); |
| | | _project.AddFileToBuild(_targetGUID, _project.AddFile("/usr/lib/libresolv.tbd", "Frameworks/libresolv.tbd", PBXSourceTree.Sdk)); |
| | | |
| | | // mr_sdk |
| | | HandleMrSDK(_project, _targetGUID); |
| | | |
| | | // sp_sdk |
| | | HandleSpSDK(_project, _targetGUID); |
| | | |
| | | File.WriteAllText(_projectPath, _project.WriteToString()); |
| | | |
| | | var _capabilityMgr = new ProjectCapabilityManager(_projectPath, "game003.entitlements", PBXProject.GetUnityTargetName()); |
| | | _capabilityMgr.AddInAppPurchase(); |
| | | _capabilityMgr.AddPushNotifications(true); |
| | | _capabilityMgr.WriteToFile(); |
| | | //加推送 |
| | | //var _capabilityMgr = new ProjectCapabilityManager(_projectPath, "game003.entitlements", PBXProject.GetUnityTargetName()); |
| | | //_capabilityMgr.AddInAppPurchase(); |
| | | //_capabilityMgr.AddPushNotifications(true); |
| | | //_capabilityMgr.WriteToFile(); |
| | | |
| | | BuildPlist(path); |
| | | |
| | |
| | | |
| | | private static void ModifyFile(string projectPath) |
| | | { |
| | | bool _isMr = false; |
| | | string _mrPlistPath = Application.dataPath + "/Plugins/iOS/MyMRSDK/MRSDKInfo.plist"; |
| | | if (File.Exists(_mrPlistPath)) |
| | | { |
| | | _isMr = true; |
| | | } |
| | | |
| | | // -------------- UnityAppController.mm |
| | | //读取UnityAppController.mm文件 |
| | | //修改UnityAppController.mm 文件 |
| | | var _xclass = new XClass(projectPath + "/Classes/UnityAppController.mm"); |
| | | |
| | | //在指定代码后面增加一行代码 |
| | | _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"UniversalSDK.h\"\n#include \"JPushService.h\"\n"); |
| | | |
| | | if (_isMr) |
| | | { |
| | | _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"IAPManager.h\"\n"); |
| | | } |
| | | |
| | | //引入UniversalSDK |
| | | _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"UniversalSDK.h\""+ "\n#import <SMPCQuickSDK/SMPCQuickSDK.h>"); |
| | | //unity交互调用的方法 |
| | | string newCode = "\n" + |
| | | "extern \"C\" void IOSMessageHandle(const char* jsonString) {\n" + |
| | | " [GetAppController().universalSDK HandleUnityMessage:[NSString stringWithUTF8String:jsonString]];\n" + |
| | | "}"; |
| | | _xclass.WriteBelow("extern \"C\" ScreenOrientation UnityCurrentOrientation() { return GetAppController().unityView.contentOrientation; }", |
| | | newCode); |
| | | |
| | | _xclass.WriteBelow("extern \"C\" ScreenOrientation UnityCurrentOrientation() { return GetAppController().unityView.contentOrientation; }",newCode); |
| | | //初始化UniversalSDK |
| | | newCode = "\n" + |
| | | " _universalSDK = [[UniversalSDK alloc] init];\n" + |
| | | " [_universalSDK JPushInit:launchOptions];"; |
| | | |
| | | //在指定代码后面增加一大行代码 |
| | | " _universalSDK = [[UniversalSDK alloc] init];\n"; |
| | | _xclass.WriteBelow("[KeyboardDelegate Initialize];", newCode); |
| | | //quick sdk 生命周期 |
| | | _xclass.WriteBelow("supportedInterfaceOrientationsForWindow:(UIWindow*)window\n{", "[[SMPCQuickSDK defaultInstance] application:application supportedInterfaceOrientationsForWindow:window];"); |
| | | _xclass.WriteBelow("UnitySendRemoteNotification(userInfo);", "[[SMPCQuickSDK defaultInstance] application:application didReceiveRemoteNotification:userInfo];"); |
| | | _xclass.WriteBelow("UnitySendDeviceToken(deviceToken);", "[[SMPCQuickSDK defaultInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];"); |
| | | _xclass.WriteBelow("UnitySendRemoteNotificationError(error);", "[[SMPCQuickSDK defaultInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];"); |
| | | _xclass.WriteBelow("- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options\n{", "[[SMPCQuickSDK defaultInstance] openURL:url application:app options:options];"); |
| | | _xclass.WriteBelow("::printf(\"-> applicationDidEnterBackground()\\n\");", "[[SMPCQuickSDK defaultInstance] applicationDidEnterBackground:application];"); |
| | | _xclass.WriteBelow("::printf(\"-> applicationWillEnterForeground()\\n\");", "[[SMPCQuickSDK defaultInstance] applicationWillEnterForeground:application];"); |
| | | _xclass.WriteBelow("::printf(\"-> applicationDidBecomeActive()\\n\");", "[[SMPCQuickSDK defaultInstance] applicationDidBecomeActive:application];"); |
| | | _xclass.WriteBelow("::printf(\"-> applicationWillResignActive()\\n\");", "[[SMPCQuickSDK defaultInstance] applicationWillResignActive:application];"); |
| | | _xclass.WriteBelow("::printf(\"-> applicationWillTerminate()\\n\");", "[[SMPCQuickSDK defaultInstance] applicationWillTerminate:application];"); |
| | | |
| | | if (_isMr) |
| | | { |
| | | _xclass.WriteBelow("[KeyboardDelegate Initialize];", " [[IAPManager shared] startManager];\n"); |
| | | } |
| | | |
| | | _xclass.WriteBelow("UnitySendDeviceToken(deviceToken);", " [JPUSHService registerDeviceToken:deviceToken];"); |
| | | |
| | | if (_isMr) |
| | | { |
| | | _xclass.WriteBelow("SensorsCleanup();", " [[IAPManager shared] stopManager];"); |
| | | } |
| | | |
| | | newCode = "UnitySendRemoteNotification(userInfo);\n" + |
| | | " [JPUSHService handleRemoteNotification:userInfo];\n"; |
| | | |
| | | _xclass.Replace("UnitySendRemoteNotification(userInfo);", newCode); |
| | | |
| | | newCode = "[application setApplicationIconBadgeNumber:0];\n" + |
| | | " [application cancelAllLocalNotifications];\n"; |
| | | |
| | | _xclass.WriteBelow("::printf(\"-> applicationWillEnterForeground()\\n\");", newCode); |
| | | _xclass.WriteBelow("::printf(\"-> applicationDidEnterBackground()\\n\");", "[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];\n"); |
| | | |
| | | newCode = " CGRect _winSize = [UIScreen mainScreen].bounds;\n" + |
| | | " if(KIsiPhoneX){\n" + |
| | | " _winSize.origin.x = 40;\n" + |
| | | " _winSize.size.width -= 92;\n" + |
| | | " _winSize.size.height -= 15;\n" + |
| | | " }\n" + |
| | | " _window = [[UIWindow alloc] initWithFrame:_winSize];\n"; |
| | | |
| | | _xclass.Replace("_window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];", newCode); |
| | | // -------------- UnityAppController.h |
| | | |
| | | //修改UnityAppController.h 文件 |
| | | _xclass = new XClass(projectPath + "/Classes/UnityAppController.h"); |
| | | |
| | | _xclass.WriteBelow("@class DisplayConnection;", "@class UniversalSDK;"); |
| | | _xclass.WriteBelow("// auto-rotation view contoller goes to index=0", "UniversalSDK* _universalSDK;"); |
| | | _xclass.WriteBelow("DisplayConnection* _mainDisplay;", "UniversalSDK* _universalSDK;"); |
| | | _xclass.WriteBelow("@property (readonly, copy, nonatomic) DisplayConnection* mainDisplay;", |
| | | "@property (readonly, copy, nonatomic) UniversalSDK* universalSDK;"); |
| | | |
| | | _xclass = new XClass(projectPath + "/Classes/UI/UnityView.mm"); |
| | | |
| | | _xclass.WriteBelow("#include \"Unity/UnityMetalSupport.h\"", "#include \"UniversalSDK.h\""); |
| | | _xclass.WriteBelow("_curOrientation = OrientationAfterTransform(_curOrientation, TransformBetweenOrientations(from, to));", |
| | | @"if(KIsiPhoneX) { |
| | | CGRect _winSize = [UIScreen mainScreen].bounds; |
| | | if(to == landscapeLeft){ |
| | | _winSize.origin.x = 0; |
| | | _winSize.origin.y = 0; |
| | | _winSize.size.width = 720; |
| | | _winSize.size.height = 360; |
| | | }else if(to == landscapeRight){ |
| | | _winSize.origin.x = 0; |
| | | _winSize.origin.y = -15; |
| | | _winSize.size.width = 720; |
| | | _winSize.size.height = 360; |
| | | } |
| | | [self setFrame:_winSize]; |
| | | }"); |
| | | |
| | | |
| | | _xclass = new XClass(projectPath + "/Classes/UI/UnityViewControllerBaseiOS.mm"); |
| | | //适配iPhoneX 底部白条 |
| | | _xclass = new XClass(projectPath + "/Classes/UI/UnityViewControllerBase+iOS.mm"); |
| | | _xclass.Replace("return res;", "return UIRectEdgeAll;"); |
| | | |
| | | } |
| | | |
| | | private static string GetBuildPath() |
| | |
| | | _p.StartInfo.RedirectStandardOutput = false; |
| | | _p.Start(); |
| | | _p.WaitForExit(); |
| | | } |
| | | |
| | | private static void HandleMrSDK(PBXProject project, string targetGUID) |
| | | { |
| | | string _mrPlistPath = Application.dataPath + "/Plugins/iOS/MyMRSDK/MRSDKInfo.plist"; |
| | | if (File.Exists(_mrPlistPath)) |
| | | { |
| | | string _fileGUID = project.AddFile(_mrPlistPath, "Frameworks/Plugins/iOS/MyMRSDK/MRSDKInfo.plist"); |
| | | project.AddFileToBuild(targetGUID, _fileGUID); |
| | | } |
| | | } |
| | | |
| | | private static void HandleSpSDK(PBXProject project, string targetGUID) |
| | | { |
| | | string _filePath = Application.dataPath + "/Plugins/iOS/SPYOUSDK/GDTActionSDK.framework"; |
| | | if (Directory.Exists(_filePath)) |
| | | { |
| | | string _frameworkGUID = project.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/SPYOUSDK/GDTActionSDK.framework"); |
| | | PBXProjectExtensions.AddFileToEmbedFrameworks(project, targetGUID, _frameworkGUID); |
| | | } |
| | | } |
| | | |
| | | #endif |