예제 #1
0
    public static Exported.Tour GenerateTour(string folderPath, GenerateTourOptions generateTourOptions)
    {
        State firstState = Tour.Instance.firstState;
        if (firstState == null)
        {
            EditorUtility.DisplayDialog("Error", "First state is not selected!", "Ok");
            return null;
        }

        // Find all states
        State[] states = GameObject.FindObjectsOfType<State>();
        if (states.Length == 0)
        {
            EditorUtility.DisplayDialog("Error", "There is no states on this scene to export!", "Ok");
            return null;
        }

        Exported.Tour tour = PrepateTour(Tour.Instance);

        // Pre process states
        UpdateProcess(0, states.Length, "Exporting", "");

        for (int i = 0; i < states.Length; ++i)
        {
            var state = states[i];

            try
            {
                if (!TryHandleState(
                    state,
                    folderPath,
                    generateTourOptions.ResourceHandlePath,
                    generateTourOptions.ImageCroppingLevel,
                    out var exportedState))
                {
                    EditorUtility.DisplayDialog("Error", $"Error while exporting state {state.title}", "Ok");
                    return null;
                }

                tour.states.Add(exportedState);
            }
            catch (Exception ex)
            {
                EditorUtility.DisplayDialog("Error", $"Error while exporting state {state.title}\n{ex.Message}", "Ok");
                return null;
            }


            UpdateProcess(i + 1, states.Length, "Exporting", $"{i + 1}/{states.Length}: {state.title}");
        }
        PatchViewer(folderPath, tour);
        return tour;
    }
예제 #2
0
        public static IEnumerator OpenTour(Exported.Tour tour)
        {
            using (UnityWebRequest request = new UnityWebRequest(
                       "http://localhost:5000/api/interop/openTour", "POST"
                       ))
            {
                byte[] bodyRaw = Encoding.UTF8.GetBytes(JsonUtility.ToJson(tour));
                request.uploadHandler   = new UploadHandlerRaw(bodyRaw);
                request.downloadHandler = new DownloadHandlerBuffer();
                request.SetRequestHeader("Content-Type", "application/json");
                yield return(request.SendWebRequest());

                var row = request.downloadHandler.text;
            }
        }
예제 #3
0
    public static void ExportTour(ExportOptions exportOptions)
    {
        if (Tour.Instance == null)
        {
            EditorUtility.DisplayDialog("Error", "There is no tour object on this scene!", "Ok");
            return;
        }
        if (string.IsNullOrWhiteSpace(Tour.Instance.title))
        {
            EditorUtility.DisplayDialog("Error", "You must provide tour title", "Ok");
            return;
        }

        var excursionFolder = Path.Combine(exportOptions.FolderPath, Tour.Instance.title);
        Directory.CreateDirectory(excursionFolder);


        try
        {
            UnpackViewer(exportOptions.ViewerPack, excursionFolder);

            if (exportOptions.DesktopClientBuildPack != null)
            {
                UnpackDesktopClient(exportOptions.DesktopClientBuildPack, exportOptions.FolderPath);
            }

            if (!CopyLogo(excursionFolder, out var logoFileName))
            {
                return;
            }

            CreateConfigFile(excursionFolder, logoFileName);
            ProjectEditorPrefs.IncrementBuildNum();
            Exported.Tour tour = GenerateTour(excursionFolder, exportOptions);

            // Serialize and write
            File.WriteAllText(excursionFolder + "/tour.json", JsonUtility.ToJson(tour, true));
        }
        catch (Exception ex)
        {
            EditorUtility.DisplayDialog("Error", $"Error while exporting tour\n{ex.Message}\n{ex.StackTrace}", "Ok");
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
        // Finish
    }
예제 #4
0
    /// <summary>
    /// Apply tour title and hash
    /// </summary>
    /// <param name="folderPath">Folder of viewer with target files and viewer</param>
    /// <param name="title">Title of tour</param>
    private static void PatchViewer(string folderPath, Exported.Tour tour)
    {
        var indexFileName = "index.html";
        var titleTemplate = "%TITLE_TEMPLATE%";

        var indexFile = Path.Combine(folderPath, indexFileName);
        if (!File.Exists(indexFile))
        {
            Debug.LogWarning($"Can't find {indexFileName} at {folderPath} for patching");
            return;
        }
        var indexFileContent = File.ReadAllText(indexFile);
        if (indexFileContent.Contains(titleTemplate))
        {
            indexFileContent = indexFileContent.Replace(titleTemplate, tour.title);
        }
        else
        {
            Debug.LogWarning($"Can't find title template {titleTemplate} in index file. Please, use latest viewer.");
        }
        PatchJsFile(folderPath, $"{tour.id}-{tour.versionNum}", ref indexFileContent);
        File.WriteAllText(indexFile, indexFileContent);
    }
예제 #5
0
    public static void ExportTour(string viewerLocation, string folderPath)
    {
        try
        {
            UnpackViewer(viewerLocation, folderPath);
            if (!CopyLogo(folderPath, out var logoFileName))
            {
                return;
            }
            CreateConfigFile(folderPath, logoFileName);



            // Find first state
            if (Tour.Instance == null)
            {
                EditorUtility.DisplayDialog("Error", "There is no tour object on this scene!", "Ok");
                return;
            }

            State firstState = Tour.Instance.firstState;
            if (firstState == null)
            {
                EditorUtility.DisplayDialog("Error", "First state is not selected!", "Ok");
                return;
            }

            // Find all states
            State[] states = GameObject.FindObjectsOfType <State>();
            if (states.Length == 0)
            {
                EditorUtility.DisplayDialog("Error", "There is no states on this scene to export!", "Ok");
                return;
            }

            Exported.Tour tour = new Exported.Tour
            {
                firstStateId = firstState.GetExportedId(),
                colorSchemes = Tour.Instance.colorSchemes.Select(cs => cs.color).ToArray(),
                states       = new List <Exported.State>(),
            };


            Debug.Log($"Finded {states.Length} states");
            // Pre process states
            UpdateProcess(0, states.Length, "Exporting", "");

            for (int i = 0; i < states.Length; ++i)
            {
                var state = states[i];

                if (!TryHandleState(state, folderPath, out var exportedState))
                {
                    EditorUtility.DisplayDialog("Error", $"Error while exporting state {state.title}", "Ok");
                    return;
                }

                tour.states.Add(exportedState);

                UpdateProcess(i + 1, states.Length, "Exporting", $"{i + 1}/{states.Length}: {state.title}");
            }

            // Serialize and write
            File.WriteAllText(folderPath + "/tour.json", JsonUtility.ToJson(tour, true));
        }
        catch (Exception ex)
        {
            EditorUtility.DisplayDialog("Error", $"Error while exporting tour\n{ex.Message}\n{ex.StackTrace}", "Ok");
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
        // Finish
    }