从Unity到iOS,如何完美地自动化框架,设置和plist? [英] From Unity to iOS, how to perfectly automate frameworks, settings and plist?
问题描述
在构建到iOS Xcode项目时在Unity3D中
in Unity3D when building to an iOS Xcode project,
如何完美实现这三个过程的全部
how to perfectly automate all three of
- 框架,
- 设置
- 列出项目?
解决方案必须仅具有最现代的2019语法和变体,因为多年来Unity中的情况已略有变化.
Solution must have only the most modern 2019 syntax and variations, as this has changed slightly in Unity over the years.
推荐答案
对于2019 ...
文件名BuildPostProcessor.cs
Filename, BuildPostProcessor.cs
将其放在文件夹Assets/Editor/中. (如果文件夹"Editor/"不存在,请把它放在正确的位置.)
Put it in the folder Assets/Editor/ . (Just make the folder "Editor/" exactly there if it does not exist.)
这显示了如何完成所有三个框架,设置和plist.
This shows how to do all three of frameworks, settings and plist.
// filename BuildPostProcessor.cs
// put it in a folder Assets/Editor/
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class BuildPostProcessor {
[PostProcessBuild]
public static void ChangeXcodePlist(BuildTarget buildTarget, string path) {
if (buildTarget == BuildTarget.iOS) {
string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromFile(plistPath);
PlistElementDict rootDict = plist.root;
Debug.Log(">> Automation, plist ... <<");
// example of changing a value:
// rootDict.SetString("CFBundleVersion", "6.6.6");
// example of adding a boolean key...
// < key > ITSAppUsesNonExemptEncryption </ key > < false />
rootDict.SetBoolean("ITSAppUsesNonExemptEncryption", false);
File.WriteAllText(plistPath, plist.WriteToString());
}
}
[PostProcessBuildAttribute(1)]
public static void OnPostProcessBuild(BuildTarget target, string path) {
if (target == BuildTarget.iOS) {
PBXProject project = new PBXProject();
string sPath = PBXProject.GetPBXProjectPath(path);
project.ReadFromFile(sPath);
string tn = PBXProject.GetUnityTargetName();
string g = project.TargetGuidByName(tn);
ModifyFrameworksSettings(project, g);
// modify frameworks and settings as desired
File.WriteAllText(sPath, project.WriteToString());
}
}
static void ModifyFrameworksSettings(PBXProject project, string g) {
// add hella frameworks
Debug.Log(">> Automation, Frameworks... <<");
project.AddFrameworkToProject(g, "blah.framework", false);
project.AddFrameworkToProject(g, "libz.tbd", false);
// go insane with build settings
Debug.Log(">> Automation, Settings... <<");
project.AddBuildProperty(g,
"LIBRARY_SEARCH_PATHS",
"../blahblah/lib");
project.AddBuildProperty(g,
"OTHER_LDFLAGS",
"-lsblah -lbz2");
// note that, due to some Apple shoddyness, you usually need to turn this off
// to allow the project to ARCHIVE correctly (ie, when sending to testflight):
project.AddBuildProperty(g,
"ENABLE_BITCODE",
"false");
}
}
那样就可以了.
注意-难题的最后一部分是跨文件(也许是数据文件或文本文件)进行复制.实际上,最好只使用"StreamingAssets/"方法,请参见此质量检查中的完整说明.
Note - the final part of the puzzle is copying across files (perhaps data files or text files). In reality it's best to just use the "StreamingAssets/" approach, explained fully in this QA.
这篇关于从Unity到iOS,如何完美地自动化框架,设置和plist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!