private static bool ProcessGradleProject()
    {
        try
        {
            var ps = System.Text.RegularExpressions.Regex.Escape("" + Path.DirectorySeparatorChar);

            var ignorePattern = string.Format("^([^{0}]+{0})?(\\.gradle|build){0}", ps);

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

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

        if (syncCancelToken.IsCancellationRequested)
        {
            return(false);
        }
        return(true);
    }
Пример #2
0
    private static void InstallAPP()
    {
        PXR_SceneQuickPreviewEW.PrintLog("installing APP  . . .", PXR_SceneQuickPreviewEW.LogType.Normal);

        PXR_DirectorySyncer.CreateDirectory(SQP_BUNDLE_PATH);

        PrebuildProjectSettingUpdate();

        if (string.IsNullOrEmpty(previewIndexPath) || !File.Exists(previewIndexPath))
        {
            string[] editorScenePaths = Directory.GetFiles(PXR_PathHelper.GetPXRPluginPath(), SQP_INDEX_NAME, SearchOption.AllDirectories);

            if (editorScenePaths.Length == 0 || editorScenePaths.Length > 1)
            {
                PXR_SceneQuickPreviewEW.PrintLog(editorScenePaths.Length + " " + SQP_INDEX_NAME + " has been found, please double check your PicoXR Plugin import.", PXR_SceneQuickPreviewEW.LogType.Error);
                return;
            }
            previewIndexPath = Path.Combine(Application.dataPath, SQP_INDEX_NAME);
            if (File.Exists(previewIndexPath))
            {
                File.Delete(previewIndexPath);
            }
            File.Copy(editorScenePaths[0], previewIndexPath);
        }

        string[] buildScenes = new string[1] {
            previewIndexPath
        };
        string apkOutputPath = Path.Combine(SQP_BUNDLE_PATH, SQP_APK_NAME);

        if (File.Exists(apkOutputPath))
        {
            File.Delete(apkOutputPath);
        }

        var buildPlayerOptions = new BuildPlayerOptions
        {
            scenes           = buildScenes,
            locationPathName = apkOutputPath,
            target           = BuildTarget.Android,
            options          = BuildOptions.Development |
                               BuildOptions.AutoRunPlayer
        };

        BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);

        if (report.summary.result == BuildResult.Succeeded)
        {
            PXR_SceneQuickPreviewEW.PrintLog("App is installed.", PXR_SceneQuickPreviewEW.LogType.Success);
        }
        else if (report.summary.result == BuildResult.Failed)
        {
            PXR_SceneQuickPreviewEW.PrintLog("Failed", PXR_SceneQuickPreviewEW.LogType.Error);
        }
        PostbuildProjectSettingUpdate();
    }
    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 PXR_DirectorySyncer(gradleTempExport,
                                                 gradleExport, ignorePattern);

            syncCancelToken = new PXR_DirectorySyncer.CancellationTokenSource();
            var syncResult = syncer.Synchronize(syncCancelToken.Token);
            syncEndTime = System.DateTime.Now;
        }
        catch (Exception e)
        {
            UnityEngine.Debug.Log("PXRBuild: 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);
    }
Пример #4
0
    public static void BuildScenes(bool forceRestart)
    {
        if (!PXR_ADBTool.GetInstance().IsReady())
        {
            return;
        }

        GetScenesEnabled();

        remoteSceneCache = EXTERNAL_STORAGE_PATH + "/" + PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android)
                           + "/cache/scenes";

        Dictionary <string, string>         assetInSceneBundle = new Dictionary <string, string>();
        List <AssetBundleBuild>             assetBundleBuilds  = new List <AssetBundleBuild>();
        Dictionary <string, List <string> > extToAssetList     = new Dictionary <string, List <string> >();

        string[] resDirectories = Directory.GetDirectories("Assets", "Resources", SearchOption.AllDirectories).ToArray();

        if (resDirectories.Length > 0)
        {
            string[] resAssetPaths = AssetDatabase.FindAssets("", resDirectories).Select(x => AssetDatabase.GUIDToAssetPath(x)).ToArray();
            ProcessAssets(resAssetPaths, "resources", ref assetInSceneBundle, ref extToAssetList);

            AssetBundleBuild resBundle = new AssetBundleBuild();
            resBundle.assetNames      = assetInSceneBundle.Keys.ToArray();
            resBundle.assetBundleName = PXR_SQPLoader.RESOURCE_BUNDLE_NAME;
            assetBundleBuilds.Add(resBundle);
        }

        foreach (var scene in buildSceneInfoList)
        {
            string[] assetDependencies = AssetDatabase.GetDependencies(scene.scenePath);
            ProcessAssets(assetDependencies, scene.sceneName, ref assetInSceneBundle, ref extToAssetList);

            string[] sceneAsset = new string[1] {
                scene.scenePath
            };
            AssetBundleBuild sceneBuild = new AssetBundleBuild();
            sceneBuild.assetBundleName = "scene_" + scene.sceneName;
            sceneBuild.assetNames      = sceneAsset;
            assetBundleBuilds.Add(sceneBuild);
        }

        foreach (string ext in extToAssetList.Keys)
        {
            int assetCount = extToAssetList[ext].Count;
            int numChunks  = (assetCount + BUNDLE_CHUNK_SIZE - 1) / BUNDLE_CHUNK_SIZE;
            for (int i = 0; i < numChunks; i++)
            {
                List <string> assetChunkList;
                if (i == numChunks - 1)
                {
                    int size = BUNDLE_CHUNK_SIZE - (numChunks * BUNDLE_CHUNK_SIZE - assetCount);
                    assetChunkList = extToAssetList[ext].GetRange(i * BUNDLE_CHUNK_SIZE, size);
                }
                else
                {
                    assetChunkList = extToAssetList[ext].GetRange(i * BUNDLE_CHUNK_SIZE, BUNDLE_CHUNK_SIZE);
                }
                AssetBundleBuild build = new AssetBundleBuild();
                build.assetBundleName = "asset_" + ext + i;
                build.assetNames      = assetChunkList.ToArray();
                assetBundleBuilds.Add(build);
            }
        }

        // Build asset bundles
        BuildPipeline.BuildAssetBundles(PXR_DirectorySyncer.CreateDirectory(SQP_BUNDLE_PATH, SQP_SCENE_BUNDLE), assetBundleBuilds.ToArray(),
                                        BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android);

        string tempDirectory = PXR_DirectorySyncer.CreateDirectory(SQP_BUNDLE_PATH, "Temp");

        string absoluteTempPath = Path.Combine(Path.Combine(Application.dataPath, ".."), tempDirectory);

        if (!PullSceneBundles(absoluteTempPath, remoteSceneCache))
        {
            return;
        }

        string sceneLoadDataPath = Path.Combine(tempDirectory, SCENE_LOAD_DATA_NAME);

        if (File.Exists(sceneLoadDataPath))
        {
            File.Delete(sceneLoadDataPath);
        }

        StreamWriter writer = new StreamWriter(sceneLoadDataPath, true);

        long unixTime = (int)(DateTimeOffset.UtcNow.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

        writer.WriteLine(unixTime.ToString());
        for (int i = 0; i < buildSceneInfoList.Count; i++)
        {
            writer.WriteLine(Path.GetFileNameWithoutExtension(buildSceneInfoList[i].scenePath));
        }

        writer.Close();

        string absoluteSceneLoadDataPath = Path.Combine(absoluteTempPath, SCENE_LOAD_DATA_NAME);

        string[] pushCommand = { "-d push", "\"" + absoluteSceneLoadDataPath + "\"", "\"" + remoteSceneCache + "\"" };
        string   output, error;

        if (PXR_ADBTool.GetInstance().RunCommand(pushCommand, null, out output, out error) != 0)
        {
            PXR_SceneQuickPreviewEW.PrintLog(string.IsNullOrEmpty(error) ? output : error, PXR_SceneQuickPreviewEW.LogType.Error);
            return;
        }

        if (!IsInstalledAPP())
        {
            InstallAPP();
        }


        if (forceRestart)
        {
            RestartApp();
            return;
        }

        PXR_SceneQuickPreviewEW.PrintLog("Build Scenes.", PXR_SceneQuickPreviewEW.LogType.Success);
    }