示例#1
0
        public static void OnPostprocessiOSBuild(BuildTarget target, string iBuiltProjectPath)
        {
            UtilsLog.Info("PostProcessor",
                          "OnPostprocessiOSBuild()::Target:{0} ProPath:{1}", target.ToString(), iBuiltProjectPath);
#if UNITY_EDITOR
            if (target != BuildTarget.iOS)
            {
                return;
            }

            const string funcBlock = "PostProcessor.OnPostprocessiOSBuild()";
            BuildLogger.OpenBlock(funcBlock);

            const string  TargetProjectName = "Unity-iPhone";
            BuildSettings _buildSetting     = BuildSettings.GetInstance(BuildSettings.AssetFileDir);
            if (null == _buildSetting)
            {
                return;
            }
            // 取得设定情报列表
            XCSettingItem[] settings = _buildSetting.GetXCSettingInfo(TargetProjectName);
            if ((settings == null) || (settings.Length <= 0))
            {
                BuildLogger.CloseBlock();
                return;
            }

            string     pbxprojPath = PBXProject.GetPBXProjectPath(iBuiltProjectPath);
            PBXProject project     = new PBXProject();
            project.ReadFromString(File.ReadAllText(pbxprojPath));
            string targetGUID = project.TargetGuidByName(TargetProjectName);

            // BuildMode(debug/release/store)
            string debugConfigGUID   = project.BuildConfigByName(targetGUID, "Debug");
            string releaseConfigGUID = project.BuildConfigByName(targetGUID, "Release");

            foreach (XCSettingItem item in settings)
            {
                switch (item.Type)
                {
                case TXCSettingInfoType.ReplaceSource:
                {
                    foreach (string value in item.Value.LValue)
                    {
                        ReplaceSource(iBuiltProjectPath, value);
                        BuildLogger.LogMessage("Replace Source {0} -> {1}", value, iBuiltProjectPath);
                    }
                }
                break;

                case TXCSettingInfoType.FrameWorks:
                {
                    foreach (string frameWork in item.Value.LValue)
                    {
#if UNITY_2017_1_OR_NEWER
                        if (project.ContainsFramework(targetGUID, frameWork) == false)
                        {
#else
                        if (project.HasFramework(frameWork) == false)
                        {
#endif
                            project.AddFrameworkToProject(targetGUID, frameWork, false);
                            BuildLogger.LogMessage("Add FrameWork -> {0}", frameWork);
                        }
                    }
                }
                break;

                case TXCSettingInfoType.Libraries:
                {
                    foreach (string library in item.Value.LValue)
                    {
                        string fileGuid = project.AddFile("usr/lib/" + library, "Frameworks/" + library, PBXSourceTree.Sdk);
                        project.AddFileToBuild(targetGUID, fileGuid);
                        BuildLogger.LogMessage("Add Library -> {0}", library);
                    }
                }
                break;

                case TXCSettingInfoType.IncludeFiles:
                {
                    foreach (string file in item.Value.LValue)
                    {
                        string addFilePath = null;
                        PreSetFileToProject(iBuiltProjectPath, file, ref addFilePath);

                        if (string.IsNullOrEmpty(addFilePath) == false)
                        {
                            string fileGUID = project.AddFile(addFilePath, addFilePath, PBXSourceTree.Source);
                            project.AddFileToBuild(targetGUID, fileGUID);

                            BuildLogger.LogMessage("Add File -> {0}", file);
                        }
                    }
                }
                break;

                case TXCSettingInfoType.IncludeFolders:
                {
                    foreach (string folder in item.Value.LValue)
                    {
                        string copyTo          = null;
                        string addDirReference = null;

                        PreSetFolderToProject(iBuiltProjectPath, folder, ref copyTo, ref addDirReference);
                        if ((string.IsNullOrEmpty(copyTo) == false) &&
                            (string.IsNullOrEmpty(addDirReference) == false))
                        {
                            project.AddFolderReference(copyTo, addDirReference, PBXSourceTree.Source);
                            BuildLogger.LogMessage("Add Folder -> {0}", folder);
                        }
                    }
                }
                break;

                case TXCSettingInfoType.Bool:
                {
                    // Debug
                    if (TXCBool.Yes == item.Debug.BValue)
                    {
                        project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "YES");
                    }
                    else
                    {
                        project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "NO");
                    }

                    BuildLogger.LogMessage("Add Bool(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.BValue.ToString());

                    // Release
                    if (TXCBool.Yes == item.Release.BValue)
                    {
                        project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "YES");
                    }
                    else
                    {
                        project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "NO");
                    }

                    BuildLogger.LogMessage("Add Bool(Release) -> Key:{0} Value:{1}", item.Key, item.Release.BValue.ToString());
                }
                break;

                case TXCSettingInfoType.String:
                {
                    // Debug
                    project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, item.Debug.SValue);

                    BuildLogger.LogMessage("Add String(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.SValue);

                    // Release
                    project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, item.Release.SValue);

                    BuildLogger.LogMessage("Add String(Release) -> Key:{0} Value:{1}", item.Key, item.Release.SValue);
                }
                break;

                case TXCSettingInfoType.List:
                {
                    // Debug
                    foreach (string value in item.Debug.LValue)
                    {
                        project.AddBuildPropertyForConfig(debugConfigGUID, item.Key, value);

                        BuildLogger.LogMessage("Add List(Debug) -> Key:{0} Item:{1}", item.Key, value);
                    }
                    // Release
                    foreach (string value in item.Release.LValue)
                    {
                        project.AddBuildPropertyForConfig(releaseConfigGUID, item.Key, value);

                        BuildLogger.LogMessage("Add List(Release) -> Key:{0} Item:{1}", item.Key, value);
                    }
                }
                break;

                default:
                    break;
                }
            }

            File.WriteAllText(pbxprojPath, project.WriteToString());
            BuildLogger.CloseBlock();
#endif
        }