Exemplo n.º 1
0
        public override void OnBuild()
        {
            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.None);

                //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);
            }
        }
Exemplo n.º 2
0
        //build Eclipse Project
        public override void OnBuild()
        {
            string solutionPath = global["android.project"];

            // Build Android Project
            if (ShouldDoTask(TaskList.BuildAndroidProject))
            {
                Process(5, "Build Android Project", "");


                //mod file path
                var task_buildAndroidProject = new ReportableTask();
                task_buildAndroidProject.name            = "Build Android Studio Project";
                task_buildAndroidProject.processHandller = OnExportReport;
                task_buildAndroidProject.action          = (process) => {
                    //check parent dir
                    process(0.1f, "Export Android Studio Project", "ensure dirs...");
                    {
                        var di = new DirectoryInfo(solutionPath).Parent;
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                    }

                    //if target Path exits, delete it!
                    if (Directory.Exists(solutionPath))
                    {
                        DirectoryInfo dir = new DirectoryInfo(solutionPath);
                        dir.Delete(true);
                    }

                    if (!this.UseBackup)
                    {
                        // build eclipse project
                        process(0.15f, "Export Android Project", "call unity to export android project...");
                        UnityEngine.Debug.Log("Unity building eclipse project...");
                        NativeBuilderUtility.Build(solutionPath, UnityEditor.BuildTarget.Android, UnityEditor.BuildOptions.AcceptExternalModificationsToPlayer);

                        // change project name

                        /*
                         *                      DirectoryInfo projectDir = new DirectoryInfo(EclipsePath);
                         *                      DirectoryInfo[] childrenDir = projectDir.GetDirectories();
                         *                      if(childrenDir.Length != 1)
                         *                      {
                         *                              throw new Exception("multi child directories be found under the project!");
                         *                      }
                         *                      string oldGameName = childrenDir[0].Name;
                         */
                        // rename project dir
                        string oldGameName = PlayerSettings.productName;
                        string newGamename = "Game";
                        string source      = Path.Combine(solutionPath, oldGameName);
                        string dest        = Path.Combine(solutionPath, newGamename);
                        Directory.Move(source, dest);

                        // rename obb
                        string ObbPath = solutionPath + "/" + PlayerSettings.productName + ".main.obb";
                        if (File.Exists(ObbPath))
                        {
                            string targetObbPath = solutionPath + "/" + "main." + PlayerSettings.Android.bundleVersionCode + "." + PlayerSettings.applicationIdentifier + ".obb";
                            File.Move(ObbPath, targetObbPath);
                        }

                        // write info
                        EclipseProject project = new EclipseProject(solutionPath + "/Game");
                        project.BuildTime = this.startTime.ToString();


                        // backup pure eclips project
                        PShellUtil.CopyTo(solutionPath, Configuration.Gloable.Eclipse_Project_Backup_Home + "/autosave", PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Override);
                    }
                    else if (this.UseBackup)
                    {
                        PShellUtil.CopyTo(Path.Combine(Configuration.Gloable.Eclipse_Project_Backup_Home, this.BackupName), solutionPath, PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Override);
                    }
                };
                task_buildAndroidProject.Run();

                UnityEngine.Debug.Log("Build AndroidStudio Project success, Release At [" + solutionPath + "].");
            }

            /*
             *          // Apply NativeBuilder
             *          if(ShouldDoTask(TaskList.ApplyNativeBuilder))
             *          {
             *                  Process(0.8f, "Apply NativeBuilder Conf", "apply eupe...");
             *                  ELProject project = new ELProject (solutionPath + "/Game");
             *                  EUPE.ModEclipseProject(project, mod);
             *          }
             *
             *          // Build Apk
             *          if(ShouldDoTask(TaskList.BuildApk))
             *          {
             *                  Process(15, "Build APK", "");
             *                  this.apkPath = NativeBuilderUtility.BuildAPK(solutionPath + "/Game", OnApkBuildReport);
             *                  string target_dir = solutionPath + "/../TargetAndroid";
             *                  string appName = PlayerSettings.productName +"_"+PlayerSettings.bundleVersion+"_"+System.DateTime.Now.ToString("MMdd_HHmm")+".apk";
             *                  string target_path = target_dir+"/"+ appName;
             *                  if (Directory.Exists(target_dir))
             *                  {
             *                          Directory.Delete(target_dir,true);
             *                  }
             *                  Directory.CreateDirectory(target_dir);
             *                  File.Move(this.apkPath,target_path);
             *                  this.apkPath = target_path;
             *                  //main.42.tw.mobage.g22000016.obb
             *                  string thisObbPath = solutionPath+"/"+PlayerSettings.productName+".main.obb";
             *                  if(File.Exists(thisObbPath))
             *                  {
             *
             *                          string targetObbPath = target_dir+"/"+"main."+PlayerSettings.Android.bundleVersionCode+"."+PlayerSettings.applicationIdentifier+".obb";
             *                          File.Move(thisObbPath,targetObbPath);
             *                  }
             *
             *                  UnityEngine.Debug.Log("Build Apk success, Release At [" + apkPath + "].");
             *          }
             *
             *          // Run Apk
             *          if(ShouldDoTask(TaskList.RunApk))
             *          {
             *                  NativeBuilderUtility.RunAPK(this.apkPath, PlayerSettings.applicationIdentifier);
             *          }
             */
        }
Exemplo n.º 3
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"] + "].");
            }
        }