【IOS自动化解放双手系列一】unity3D导出xcode 工程并配置各种权限

本文介绍了一个程序员如何通过自动化将Unity3D项目导出为Xcode工程,并配置各种权限,包括命令行打包、上传蒲公英和Bugly的流程。首先,详细讲述了在Unity3D中导出Xcode工程的步骤,然后讨论了Xcode的配置和SDK设置,特别是权限配置。最后,预告了后续的自动化系列内容。
摘要由CSDN通过智能技术生成

打包是程序员必经之路。如何实现自动化是一个程序员的基本素质。(都是因为我懒,哈哈哈)。
使用环境 :unity3D 2017.4.7 Mac Pro
打包分一下几个部分 :
1、unity3D导出xcode 工程
2、设置xcode配置及各种sdk配置
3、命令行打包
4、上传蒲公英
5、上传bugly
【IOS自动化解放双手系列一】unity3D导出xcode 工程并配置各种权限
【IOS自动化解放双手系列二】命令行打IPA包和上传蒲公英
【IOS自动化解放双手系列三】上传bugly
接下来开始正式看代码

1、unity3D导出xcode 工程
我们使用assetbundle打包所以需要先打ab包 让配置相关服务器文件,在进行导出 代码如下

   public enum BUILDTYPE {
        QA,
        PREFE,
        REALSE
    }
    private static BUILDTYPE currenBulidType = BUILDTYPE.REALSE;
    public static void ExportIOSProject(BUILDTYPE uILDTYPE) {
        currenBulidType = uILDTYPE;
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS);
        AssetDatabase.Refresh();
        MoveGameConfig(uILDTYPE);
        string shellPath = Application.dataPath.Replace("Assets", "Build/iOS/");
        //step1.打包资源。通过AssetBundleGraph 生成Build AssetsBundles
        BuildAssetsBundles();
        UnityEngine.Debug.Log("step1 Finished!!!");
        //Step2.移除无关文件,为Export IOS 工程做准备,调用shell脚本
        RunShell(shellPath + "RemoveFromUnity.sh");
        AssetDatabase.Refresh();
        UnityEngine.Debug.Log("step2 Finished!!!");
        //Step3.导出Apple 真机工程
        ExportAppleProject(iOSSdkVersion.DeviceSDK);
        UnityEngine.Debug.Log("step3 Finished!!!");
        //Step4.删除临时文件,调用shell脚本
        RunShell(shellPath + "RecoverUnity.sh");
        UnityEngine.Debug.Log("step4 Finished!!!");

        PlayerSettings.applicationIdentifier = "com.XXXX.XXX";
        AssetDatabase.Refresh();
    }

    public static void ExportAppleProject(iOSSdkVersion sdk) {
        List<string> scenes = new List<string>();
        foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes) {
            if (!scene.enabled)
                continue;
            scenes.Add(scene.path);
        }
        bool isQA = false;
        switch (currenBulidType) {
            case BUILDTYPE.QA:
            case BUILDTYPE.PREFE:
                isQA = true;
                PlayerSettings.applicationIdentifier = "com.XXXX.XXX";
                break;
            case BUILDTYPE.REALSE:
                PlayerSettings.applicationIdentifier = "com.XXXX.XXX";
                isQA = false;
                break;
        }
        EditorUserBuildSettings.development = isQA;

        PlayerSettings.iOS.sdkVersion = sdk;
        PlayerSettings.iOS.buildNumber = GetVersion().ToString();
        //EditorUserBuildSettings.target
        BuildOptions buildOption = BuildOptions.None;
        string res = BuildPipeline.BuildPlayer(scenes.ToArray(), PathUtils.CombinePath("Build", ToolsFunctions.GetPlatformDefines(), "Project", sdk.ToString()), BuildTarget.iOS, buildOption);
        if (res.Length > 0) {
            throw new Exception("BuildPlayer failure : " + res);
        }
    }


 //=====================================公共函数=======================================
    private static void BuildAssetsBundles() {
        UnityEngine.AssetBundles.GraphTool.BatchBuildWindow.Open();
        UnityEngine.AssetBundles.GraphTool.BatchBuildWindow.BuildFromMenu();
    }

    private static void RunShell(string shellFile) {
        //      Thread thread = new Thread(new )
        //为了可以重试多线程所以加了一层
        UnityRunShell(shellFile);
    }

    private static void UnityRunShell(string shellFile) {
        Process process = new Process();
        process.StartInfo.FileName = shellFile;
        //      process.StartInfo.Arguments = "";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.ErrorDialog = true;
        process.StartInfo.CreateNoWindow = false;
        process.Start();
        process.WaitForExit();
        process.Close();
    }

    private static int GetVersion(){
        return ClientVersion.GetIncrementBundleVersion();
    }

    private static void MoveGameConfig(BUILDTYPE uILDTYPE ){
        string path = PathUtils.CombinePath(Application.dataPath,"../GameConfig/gameRealse.xml");

        switch(uILDTYPE){
            case BUILDTYPE.QA:
                path = PathUtils.CombinePath(Application.dataPath,"../GameConfig/gameQA.xml");
                break;
            case BUILDTYPE.PREFE:
                path = PathUtils.CombinePath(Application.dataPath,"../GameConfig/gamePrefe.xml");
                break;
            case BUILDTYPE.REALSE:
                path = PathUtils.CombinePath(Application.dataPath,"../GameConfig/gameRealse.xml");
                break;
        }

        CopyConfig(path);
    }

    private static void CopyConfig(string path) {
        string targePath = PathUtils.CombinePath(PathUtils.GameConfigWWWPath, "game.xml");
        string configStr = FileUtils.ReadAllText(path);
        if (string.IsNullOrEmpty(configStr)) {
            Client.LogManager.LogError("配置信息有误请查看后重新写入");
        }
        FileUtils.WriteAllText(targePath, configStr);
        Client.LogManager.Log("copy GameConfig finish");
    }

2、设置xcode配置及各种sdk配置
分一下几部分:
添加类库
框架的搜索追加设置
设置推送权限配置XXXXX.entitlements文件
unity修改oc代码

#if (UNITY_IOS || UNITY_IPHONE)
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using System.Linq;
using System.Diagnostics;
using CDBG
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值