少年修仙传客户端基础资源
lwb
2020-11-20 523a8c5b8de799aeaeaa7287f0b4f9e2edf339ee
Assets/Editor/XCodeProjectMod.cs
@@ -2,18 +2,18 @@
using System.IO;
using UnityEditor;
using UnityEditor.iOS.Xcode.Custom;
using UnityEditor.iOS.Xcode.Custom.Extensions;
using UnityEngine;
public class XCodeProjectMod
{
#if UNITY_IOS
    private const string CODE_SIGN_DEVELOPER = "";
    private const string CODE_SIGN_DISTRIBUTION = "";
    private const string PROVISIONING_DEVELOPER = "";
    private const string PROVISIONING_DISTRIBUTION = "";
    private const string TEAM = "5X26T385YZ";
#if UNITY_IOS
    [UnityEditor.Callbacks.PostProcessBuild(999)]
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
@@ -21,8 +21,6 @@
        {
            return;
        }
        string _projectPath = PBXProject.GetPBXProjectPath(path);
@@ -66,8 +64,11 @@
        _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));
        // 针对猫儿sdk的处理
        HandleMrSDK(_project);
        // mr_sdk
        HandleMrSDK(_project, _targetGUID);
        // sp_sdk
        HandleSpSDK(_project, _targetGUID);
        File.WriteAllText(_projectPath, _project.WriteToString());
@@ -83,7 +84,6 @@
            ModifyFile(path);
        }
    }
#endif
    private static void BuildPlist(string path)
    {
@@ -111,12 +111,24 @@
    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文件
        var _xclass = new XClass(projectPath + "/Classes/UnityAppController.mm");
        //在指定代码后面增加一行代码
        _xclass.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#include \"UniversalSDK.h\"\n#include \"JPushService.h\"");
        _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");
        }
        string newCode = "\n" +
                         "extern \"C\" void IOSMessageHandle(const char* jsonString) {\n" +
@@ -132,7 +144,17 @@
        //在指定代码后面增加一大行代码
        _xclass.WriteBelow("[KeyboardDelegate Initialize];", newCode);
        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";
@@ -241,7 +263,6 @@
        BuildPipeline.BuildPlayer(ClientPackage.baseLevels, GetBuildPath(), BuildTarget.iOS, BuildOptions.Il2CPP);
    }
#if UNITY_IOS
    [MenuItem("Build/ipa")]
    public static void BuildIPA()
    {
@@ -256,16 +277,27 @@
        _p.Start();
        _p.WaitForExit();
    }
#endif
    private static void HandleMrSDK(PBXProject project)
    private static void HandleMrSDK(PBXProject project, string targetGUID)
    {
        string _mrPlistPath = Application.dataPath + "/Plugins/iOS/MyMRSDK/MRSDKInfo.plist";
        if (File.Exists(_mrPlistPath))
        {
            string _targetGUID = project.TargetGuidByName(UnityEditor.iOS.Xcode.PBXProject.GetUnityTargetName());
            string _fileGUID = project.AddFile(_mrPlistPath, "Frameworks/Plugins/iOS/MyMRSDK/MRSDKInfo.plist");
            project.AddFileToBuild(_targetGUID, _fileGUID);
            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
}