Unity打包IOS時。自動化配置文件。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEditor.Callbacks;
using System.IO;

public class SSIOSBuildSetting : MonoBehaviour {

    [PostProcessBuild]
    static void OnPostprocessBuild(BuildTarget target, string pathToBuildProject)
    {
        string unityEditorAssetPath = Application.dataPath;
        if (target != BuildTarget.iOS)
        {
            Debug.LogWarning("Target is not iPhone. XcodePostProcess will not run");
            return;
        }
        ModifyProj(pathToBuildProject);
        SetPlist(pathToBuildProject);
    }

    public static void ModifyProj(string pathToBuildProject)
    {
        string _projPath = PBXProject.GetPBXProjectPath(pathToBuildProject);
        PBXProject _pbxProj = new PBXProject();

        _pbxProj.ReadFromString(File.ReadAllText(_projPath));
        string _targetGuid = _pbxProj.TargetGuidByName("Unity-iPhone");

        //*******************************添加framework*******************************//
        //_pbxProj.AddFrameworkToProject(_targetGuid, "StoreKit.framework", true);

        //*******************************添加tbd*******************************//
       // _pbxProj.AddFileToBuild(_targetGuid, _pbxProj.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk));

        //*******************************設置buildsetting*******************************//
        //_pbxProj.SetBuildProperty(_targetGuid, "CODE_SIGN_IDENTITY", code_sign_identity);
        _pbxProj.SetBuildProperty(_targetGuid, "ENABLE_BITCODE","YES");
        _pbxProj.SetBuildProperty(_targetGuid, "DEVELOPMENT_TEAM", "JK62X52E5W");
        _pbxProj.SetBuildProperty(_targetGuid, "ARCHS", "$(ARCHS_STANDARD)");

        File.WriteAllText(_projPath, _pbxProj.WriteToString());
    }

    static void SetPlist(string pathToBuildProject)
    {
        string _plistPath = pathToBuildProject + "/Info.plist";
        PlistDocument _plist = new PlistDocument();

        _plist.ReadFromString(File.ReadAllText(_plistPath));
        PlistElementDict _rootDic = _plist.root;

        //_rootDic.SetString("View controller-based status bar appearance", "NO");
        //_rootDic.SetString("CFBundleDisplayName", "StellarSails");

        //_rootDic.SetString("CFBundleLocalizations", "en");

        //string PlistAdd = @"  
        //    <key>CFBundleLocalizations</key>
        //    <array>
        //           <string>en</string>
        //           <string>zh_CN</string>
        //    </array>";
        //_rootDic.CreateArray("Localizations");
        _rootDic.SetString("CFBundleVersion", "1.0");
        _rootDic.SetBoolean("Application has localized display name", true);

        File.WriteAllText(_plistPath, _plist.WriteToString());
    }
}

這個腳本放到Unity裏的Editor文件夾裏面就可以了。剛學到了這個東西。因爲每次打包IOS需要配置好多東西。所以寫了點代碼去實現自動化配置。以上是我寫的簡單的代碼。</p><p>後來又看到了雨松大大的帖子雨松大大的關於自動化配置IOS設置的帖子。以及找到的Epps大哥的帖子。Epps關於自動化配置IOS設置。有想研究的同學建議看看
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章