Unity xcode配置(编辑器拓展)
Posted 时光不染
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity xcode配置(编辑器拓展)相关的知识,希望对你有一定的参考价值。
当接入ios的一些SDK时,经常要对xcode做一些配置,如下图
手动配置起来非常麻烦,我们可以通过UnityEditor做动态配置,每次打包,会自动将配置导入到xcode
以下示例,包括buildSetting设置,依赖库,及info.plist修改等
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
namespace Editor
{
public class XcodeSetting
{
[PostProcessBuild(999)]
public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
{
if(buildTarget == BuildTarget.iOS)
{
string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject pbxProject = new PBXProject();
pbxProject.ReadFromFile(projectPath);
//设置xcode buildSetting的属性
string target = pbxProject.TargetGuidByName("Unity-iPhone");
pbxProject.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
pbxProject.SetBuildProperty(target, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
pbxProject.SetBuildProperty(target, "GCC_C_LANGUAGE_STANDARD", "gnu99");
//设置依赖的framework
string targetGuid = pbxProject.GetUnityMainTargetGuid();
pbxProject.AddFrameworkToProject(targetGuid, "libz.dylib", false);
pbxProject.AddFrameworkToProject(targetGuid, "libsqlite3.tbd", false);
pbxProject.AddFrameworkToProject(targetGuid, "Security.framework", false);
pbxProject.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false);
pbxProject.AddFrameworkToProject(targetGuid, "Foundation.framework", false);
pbxProject.AddFrameworkToProject(targetGuid, "UIKit.framework", false);
pbxProject.AddFrameworkToProject(targetGuid, "javascriptCore.framework", false);
pbxProject.AddFrameworkToProject(targetGuid, "AdSupport.framework", false);
pbxProject.WriteToFile (projectPath);
//写入xcode info.plist
var plistPath = System.IO.Path.Combine(path, "Info.plist");
PlistDocument plist = new PlistDocument();
plist.ReadFromFile(plistPath);
plist.root.SetString("GADApplicationIdentifier", "ca-app-pub-9488501426181082/7319780494");
plist.root.SetBoolean("GADIsAdManagerApp", true);
plist.WriteToFile(plistPath);
}
}
}
}
以上是关于Unity xcode配置(编辑器拓展)的主要内容,如果未能解决你的问题,请参考以下文章
Unity编辑器拓展(GraphView制作对话系统编辑器)