Exemple #1
0
        internal static void RunStartupCode(TutorialProjectSettings projectSettings)
        {
            if (projectSettings.InitialScene != null)
            {
                EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(projectSettings.InitialScene));
            }

            TutorialManager.WriteAssetsToTutorialDefaultsFolder();

            // Ensure Editor is in predictable state
            EditorPrefs.SetString("ComponentSearchString", string.Empty);
            Tools.current = Tool.Move;

            if (TutorialEditorUtils.FindAssets <TutorialContainer>().Any())
            {
                var existingWindow = EditorWindowUtils.FindOpenInstance <TutorialWindow>();
                if (existingWindow)
                {
                    existingWindow.Close();
                }
                ShowTutorialWindow();
            }

            // NOTE camera settings can be applied successfully only after potential layout changes
            if (projectSettings.InitialCameraSettings != null && projectSettings.InitialCameraSettings.Enabled)
            {
                projectSettings.InitialCameraSettings.Apply();
            }

            if (projectSettings.WelcomePage)
            {
                TutorialModalWindow.Show(projectSettings.WelcomePage);
            }
        }
Exemple #2
0
        /// <summary>
        /// Shows Tutorials window using the currently specified behaviour.
        /// </summary>
        /// <remarks>
        /// Different behaviors:
        /// 1. If a single root tutorial container (TutorialContainer.ParentContainer is null) that has Project Layout specified exists,
        ///    the window is loaded and shown using the specified project window layout (old behaviour).
        ///    If the project layout does not contain Tutorials window, the window is shown an as a free-floating window.
        /// 2. If no root tutorial containers exist, or a root container's Project Layout is not specified, the window is shown
        ///     by anchoring and docking it next to the Inspector (new behaviour). If the Inspector is not available,
        ///     the window is shown an as a free-floating window.
        /// 3. If there is more than one root tutorial container with different Project Layout setting in the project,
        ///    one asset is chosen randomly to specify the behavior.
        /// 4. If Tutorials window is already created, it is simply brought to the foreground and focused.
        /// </remarks>
        /// <returns>The the created, or aleady existing, window instance.</returns>
        public static TutorialWindow ShowTutorialWindow()
        {
            var rootContainers = TutorialEditorUtils.FindAssets <TutorialContainer>()
                                 .Where(container => container.ParentContainer is null);
            var defaultContainer = rootContainers.FirstOrDefault();
            var projectLayout    = defaultContainer?.ProjectLayout;

            if (rootContainers.Any(container => container.ProjectLayout != projectLayout))
            {
                Debug.LogWarningFormat(
                    "There is more than one TutorialContainers asset with different Project Layout setting in the project. " +
                    "Using asset at path {0} for the window behavior settings.",
                    AssetDatabase.GetAssetPath(defaultContainer)
                    );
            }

            TutorialWindow window = null;

            if (!rootContainers.Any() || defaultContainer.ProjectLayout == null)
            {
                window = TutorialWindow.GetOrCreateWindowNextToInspector();
            }
            else if (defaultContainer.ProjectLayout != null)
            {
                window = TutorialWindow.GetOrCreateWindowAndLoadLayout(defaultContainer);
            }

            // If we have more than one root container, we show a selection view. Exactly one (or zero) container
            // is set active immediately without possibility to return to the the selection view.
            if (rootContainers.Count() > 1)
            {
                window.SetContainers(rootContainers);
            }
            else
            {
                window.ActiveContainer = defaultContainer;
            }

            return(window);
        }
        /// <summary>
        /// Shows Tutorials window using the currently specified behaviour.
        /// </summary>
        /// <remarks>
        /// Different behaviors:
        /// 1. If a single TutorialContainer asset that has TutorialContainer.ProjectLayout specified exists,
        ///    the window is loaded and shown using the specified project window layout (old behaviour).
        ///    If the project layout does not contain Tutorials window, the window is shown an as free-floating window.
        /// 2. If no TutorialContainer assets exist, or TutorialContainer.ProjectLayout is not specified, the window is shown
        ///     by anchoring and docking it next to the Inspector (new behaviour). If the Inspector is not available,
        ///     the window is shown an as free-floating window.
        /// 3. If there is more than one TutorialContainer asset with different Project Layout setting in the project,
        ///    one asset is chosen randomly to specify the behavior.
        /// 4. If Tutorials window is already created, it is simply brought to the foreground and focused.
        /// </remarks>
        /// <returns>The the created, or aleady existing, window instance.</returns>
        public static TutorialWindow ShowTutorialWindow()
        {
            var containers       = TutorialEditorUtils.FindAssets <TutorialContainer>();
            var defaultContainer = containers.FirstOrDefault();
            var projectLayout    = defaultContainer?.ProjectLayout;

            if (containers.Any(container => container.ProjectLayout != projectLayout))
            {
                Debug.LogWarningFormat(
                    "There is more than one TutorialContainers asset with different Project Layout setting in the project. " +
                    "Using asset at path {0} for the window behavior settings.",
                    AssetDatabase.GetAssetPath(defaultContainer)
                    );
            }

            TutorialWindow window = null;

            if (!containers.Any() || defaultContainer.ProjectLayout == null)
            {
                window = TutorialWindow.CreateNextToInspector();
            }
            else if (defaultContainer.ProjectLayout != null)
            {
                window = TutorialWindow.CreateWindowAndLoadLayout(defaultContainer);
            }

            window.SetContainers(containers);

            // If we have only one tutorial container, we set it active immediately
            if (containers.Count() == 1)
            {
                window.ActiveContainer = defaultContainer;
            }

            return(window);
        }