Exemple #1
0
        public override void OnBuild()
        {
            if (this.ShouldDoTask(TaskList.BuildXCodeProject))
            {
                Debug.Log("Unity building xCode...");

                // check parent dir exsits
                DirectoryInfo directory = new DirectoryInfo(xCodePath);
                var           parent    = directory.Parent;
                if (!parent.Exists)
                {
                    parent.Create();
                }
                if (directory.Exists)
                {
                    directory.Delete(true);
                }


                if (!this.UseBackup)
                {
                    // build
                    //NativeBuilderUtility.Build(this.xCodePath, UnityEditor.BuildTarget.iOS, UnityEditor.BuildOptions.ConnectWithProfiler | UnityEditor.BuildOptions.Development);
                    NativeBuilderUtility.Build(this.xCodePath, UnityEditor.BuildTarget.iOS, UnityEditor.BuildOptions.None);


                    // write build time
                    XCProject project = new XCProject(this.xCodePath);
                    project.BuildTime = DateTime.Now.ToString();

                    //back up pure xCode Project
                    PShellUtil.CopyTo(this.xCodePath, this.global.XCode_Project_Backup_Home + "/autosave", PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Override);
                }
                else
                {
                    // use last version

                    PShellUtil.CopyTo(Path.Combine(this.global.XCode_Project_Backup_Home, this.BackupName), this.xCodePath, PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Override);
                }
            }

            if (this.ShouldDoTask(TaskList.ApplyNativeBuilder))
            {
                Debug.Log("Apply NativeBuilder...");
                XUPE.ModXCodeProject(this.xCodePath, this.modPath);
                UnityEngine.Debug.Log("[NativeBuilder]: generate xCode project success, xCode Project release at [" + xCodePath + "].");

                // 检查 Mod 根目录下是否包含shell脚本,如果包含就执行
                string shellPath = this.modPath + "/code.sh";
                if (File.Exists(shellPath))
                {
                    int ret = Exec.Run(shellPath, this.xCodePath);
                    if (ret != 0)
                    {
                        throw new UnityException("[NativeBuilder] Error in execute code.sh, returns: " + ret);
                    }
                }
            }

            if (this.ShouldDoTask(TaskList.BuildIpa))
            {
                DirectoryInfo tar_di = new DirectoryInfo(this.xCodePath + "/export");
                Debug.Log("Build IPA");
                DirectoryInfo assets = new DirectoryInfo(Application.dataPath);
                var           sh     = assets.GetFiles("build_xcode.sh", SearchOption.AllDirectories)[0];

                var ret = Exec.Run(sh.FullName, this.xCodePath);
                //var ret = Exec.Run("/bin/bash", sh.FullName + " " + this.xCodePath);
                if (ret != 0)
                {
                    throw new Exception("Error in Build IPA. return code: " + ret + ". xCode Project at [" + this.xCodePath + "].");
                }

                // copy to output path
                DirectoryInfo di = new DirectoryInfo(this.xCodePath + "/export");

                var ipa = di.GetFiles("*.ipa", SearchOption.AllDirectories)[0];
                ipa.CopyTo(this.global["ios.ipa"], true);

                UnityEngine.Debug.Log("[NativeBuilder]: Build success, ipa At [" + this.global["ios.ipa"] + "].");
            }
        }