少年修仙传客户端基础资源
allez
2021-03-05 800e5780b3dcfc36327c2f95ef69ea81b5294264
9527 ios打包配置

(cherry picked from commit 22ee2704a8dbacabd26a4a2bc7e63b78a59db4a8)
3个文件已修改
175 ■■■■■ 已修改文件
Assets/Editor/Tool/ClientPackage.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/XClass.cs 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/XCodeProjectMod.cs 147 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ClientPackage.cs
@@ -42,7 +42,7 @@
    static string THE_2TH_WORLD_SDK_PATH = Application.dataPath + "/Plugins/Android/bin";
    // static string MANIFEST_PATH = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
    static string iOS_PLUGIN_PATH = Application.dataPath + "/Plugins/iOS";
    static string iOS_PLUGIN_PATH = Application.dataPath + "/Plugins/iOS/Channel";
    /// <summary>
    /// 打包
@@ -504,7 +504,7 @@
        // if (!versionConfig.appId.Equals("test"))
        // {
        FileExtersion.DirectoryCopy(StringUtility.Contact(_sdkPath, "/ChannelDiff/iOS/", versionConfig.appId), iOS_PLUGIN_PATH);
        FileExtersion.DirectoryCopy(StringUtility.Contact(_sdkPath, "/Channel/iOS/", versionConfig.appId,"/Plugins"), iOS_PLUGIN_PATH);
        // }
        DateTime outTime;
Assets/Editor/XClass.cs
@@ -21,6 +21,30 @@
            }
        }
        //在指定代码上方插入
        //public void WriteAbove(string below,string text)
        //{
        //    StreamReader streamReader = new StreamReader(filePath);
        //    string text_all = streamReader.ReadToEnd();
        //    streamReader.Close();
        //    int beginIndex = text_all.IndexOf(below, System.StringComparison.CurrentCulture);
        //    if (beginIndex == -1)
        //    {
        //        Debug.LogError(filePath + "中没有找到标致" + below);
        //        return;
        //    }
        //    int endIndex = text_all.LastIndexOf("\n", beginIndex + below.Length, System.StringComparison.CurrentCulture);
        //    text_all = text_all.Substring(0, endIndex) + "\n" + text + "\n" + text_all.Substring(endIndex);
        //    StreamWriter streamWriter = new StreamWriter(filePath);
        //    streamWriter.Write(text_all);
        //    streamWriter.Close();
        //}
        //在指定代码下方插入
        public void WriteBelow(string below, string text)
        {
            StreamReader streamReader = new StreamReader(filePath);
Assets/Editor/XCodeProjectMod.cs
@@ -64,18 +64,13 @@
        _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);
@@ -111,104 +106,44 @@
    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);
                 "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);
        //初始化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("@class DisplayConnection;", "@class 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()
@@ -277,26 +212,6 @@
        _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