Ejemplo n.º 1
0
    private static bool ProcessGradleProject()
    {
        DateTime syncStartTime = System.DateTime.Now;
        DateTime syncEndTime   = System.DateTime.MinValue;

        try
        {
            var ps = System.Text.RegularExpressions.Regex.Escape("" + Path.DirectorySeparatorChar);
            // ignore files .gradle/** build/** foo/.gradle/** and bar/build/**
            var ignorePattern = string.Format("^([^{0}]+{0})?(\\.gradle|build){0}", ps);

            var syncer = new Pvr_DirectorySyncer(gradleTempExport,
                                                 gradleExport, ignorePattern);

            syncCancelToken = new Pvr_DirectorySyncer.CancellationTokenSource();
            var syncResult = syncer.Synchronize(syncCancelToken.Token);
            syncEndTime = System.DateTime.Now;
        }
        catch (Exception e)
        {
            UnityEngine.Debug.Log("PvrBuild: Processing gradle project failed with exception: " +
                                  e.Message);
            return(false);
        }

        if (syncCancelToken.IsCancellationRequested)
        {
            return(false);
        }

        // Record time it takes to sync gradle projects only if the sync was successful
        double syncTime = (syncEndTime - syncStartTime).TotalSeconds;

        if (syncTime > 0)
        {
            totalBuildTime += syncTime;
        }

        return(true);
    }
Ejemplo n.º 2
0
    static void BuildAndRun()
    {
        GetWindow(typeof(Pvr_BuildTools));
        showCancel     = false;
        buildFailed    = false;
        totalBuildTime = 0;

        InitializeProgressBar(NUM_BUILD_AND_RUN_STEPS);
        IncrementProgressBar("Exporting Unity Project . . .");

        if (!CheckADBDevices())
        {
            buildFailed = true;
            return;
        }

        apkOutputSuccessful = null;
        syncCancelToken     = null;
        gradleBuildProcess  = null;

        UnityEngine.Debug.Log("PvrBuild: Starting Unity build ...");

        SetupDirectories();

        // 1. Get scenes to build in Unity, and export gradle project
        var buildResult = UnityBuildPlayer();

        if (buildResult.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
        {
            totalBuildTime += buildResult.summary.totalTime.TotalSeconds;

            // Set static variables so build thread has updated data
            showCancel            = true;
            gradlePath            = Pvr_ADBTool.GetGradlePath();
            jdkPath               = Pvr_ADBTool.GetJDKPath();
            androidSdkPath        = Pvr_ADBTool.GetAndroidSDKPath();
            applicationIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
#if UNITY_2019_3_OR_NEWER
            productName = "launcher";
#else
            productName = Application.productName;
#endif
            dataPath = Application.dataPath;

            buildThread = new Thread(delegate()
            {
                BuildRun();
            });
            buildThread.Start();
            return;
        }
        else if (buildResult.summary.result == UnityEditor.Build.Reporting.BuildResult.Cancelled)
        {
            UnityEngine.Debug.Log("Build canceled.");
        }
        else
        {
            UnityEngine.Debug.Log("Build failed.");
        }
        buildFailed = true;
    }