private void UpdateAvailableCourses() { if (isDirty == false) { return; } List <string> courses = CourseAssetUtils.GetAllCourses().ToList(); // Create dummy entry if no files are present. if (courses.Any() == false) { trainingCourseDisplayNames.Clear(); trainingCourseDisplayNames.Add("<none>"); return; } trainingCourseDisplayNames = courses; trainingCourseDisplayNames.Sort(); if (string.IsNullOrEmpty(configurator.GetSelectedCourse())) { SetConfiguratorSelectedCourse(CourseAssetUtils.GetCourseStreamingAssetPath(trainingCourseDisplayNames[0])); GlobalEditorHandler.SetCurrentCourse(CourseAssetUtils.GetCourseAssetPath(configurator.GetSelectedCourse())); } }
public override void OnInspectorGUI() { serializedObject.Update(); // Courses can change without recompile so we have to check for them. UpdateAvailableCourses(); DrawRuntimeConfigurationDropDown(); EditorGUI.BeginDisabledGroup(IsCourseListEmpty()); { DrawCourseSelectionDropDown(); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Open Course in Workflow window")) { GlobalEditorHandler.SetCurrentCourse(CourseAssetUtils.GetCourseNameFromPath(configurator.GetSelectedCourse())); GlobalEditorHandler.StartEditingCourse(); } if (GUILayout.Button(new GUIContent("Show Course in Explorer..."))) { string absolutePath = $"{new FileInfo(CourseAssetUtils.GetCourseAssetPath(CourseAssetUtils.GetCourseNameFromPath(configurator.GetSelectedCourse())))}"; EditorUtility.RevealInFinder(absolutePath); } } GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Sets the course with given <paramref name="courseName"/> for the current scene. /// </summary> /// <param name="courseName">Name of the course.</param> public static void SetCourseInCurrentScene(string courseName) { RuntimeConfigurator.Instance.SetSelectedCourse(CourseAssetUtils.GetCourseStreamingAssetPath(courseName)); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); GlobalEditorHandler.SetCurrentCourse(courseName); GlobalEditorHandler.StartEditingCourse(); }
private void DrawCourseSelectionDropDown() { int index = 0; string courseName = CourseAssetUtils.GetCourseNameFromPath(configurator.GetSelectedCourse()); if (string.IsNullOrEmpty(courseName) == false) { index = trainingCourseDisplayNames.FindIndex(courseName.Equals); } index = EditorGUILayout.Popup("Selected Training Course", index, trainingCourseDisplayNames.ToArray()); if (index < 0) { index = 0; } string newCourseStreamingAssetsPath = CourseAssetUtils.GetCourseStreamingAssetPath(trainingCourseDisplayNames[index]); if (IsCourseListEmpty() == false && configurator.GetSelectedCourse() != newCourseStreamingAssetsPath) { SetConfiguratorSelectedCourse(newCourseStreamingAssetsPath); GlobalEditorHandler.SetCurrentCourse(trainingCourseDisplayNames[index]); } }
/// <summary> /// Sets up the current scene and creates a new training course for this scene. /// </summary> /// <param name="courseName">Name of the training course.</param> public static void SetupSceneAndTraining(string courseName) { TrainingSceneSetup.Run(); string errorMessage = null; if (CourseAssetUtils.DoesCourseAssetExist(courseName) || CourseAssetUtils.CanCreate(courseName, out errorMessage)) { if (CourseAssetUtils.DoesCourseAssetExist(courseName)) { CourseAssetManager.Load(courseName); } else { CourseAssetManager.Import(EntityFactory.CreateCourse(courseName)); AssetDatabase.Refresh(); } SetCourseInCurrentScene(courseName); } if (string.IsNullOrEmpty(errorMessage) == false) { Debug.LogError(errorMessage); } try { EditorSceneManager.SaveScene(SceneManager.GetActiveScene()); } catch (Exception ex) { Debug.LogError(ex); } }
/// <summary> /// Creates and saves a new simple example scene. /// </summary> /// <remarks>The new scene is meant to be used for step by step guides.</remarks> public static void CreateNewSimpleExampleScene() { string courseName = SimpleExampleName; int counter = 1; while (CourseAssetUtils.DoesCourseAssetExist(courseName) || CourseAssetUtils.CanCreate(courseName, out string errorMessage) == false) { courseName = $"{SimpleExampleName}_{counter}"; counter++; } CreateNewScene(courseName); GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.name = "Sphere"; sphere.transform.position = new Vector3(0f, 0.5f, 2f); GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane); plane.name = "Plane"; plane.transform.localScale = new Vector3(2f, 2f, 2f); SetupSceneAndTraining(courseName); }
private void OnGUI() { // Magic number. minSize = new Vector2(420f, 320f); titleContent = new GUIContent("Training Course Wizard"); GUIStyle labelStyle = new GUIStyle(EditorStyles.label); labelStyle.richText = true; labelStyle.wordWrap = true; EditorIcon logo = new EditorIcon("logo_creator"); Rect rect = GUILayoutUtility.GetRect(position.width, 150, GUI.skin.box); GUI.DrawTexture(rect, logo.Texture, ScaleMode.ScaleToFit); if (RuntimeConfigurator.Exists == false) { EditorGUILayout.HelpBox("The current scene is not a training scene. No course can be created. To automatically setup the scene, select \"Innoactive > Setup Training Scene\".", MessageType.Error); } EditorGUI.BeginDisabledGroup(RuntimeConfigurator.Exists == false); EditorGUILayout.LabelField("<b>Create a new training course.</b>", labelStyle); courseName = EditorGUILayout.TextField(new GUIContent("Training Course Name", "Set a file name for the new training course."), courseName); EditorGUILayout.LabelField("The new course will be set for the current scene."); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // ReSharper disable once InvertIf if (GUILayout.Button("Create", GUILayout.Width(128), GUILayout.Height(32))) { if (CourseAssetUtils.CanCreate(courseName, out errorMessage)) { CourseAssetManager.Import(EntityFactory.CreateCourse(courseName)); RuntimeConfigurator.Instance.SetSelectedCourse(CourseAssetUtils.GetCourseStreamingAssetPath(courseName)); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); GlobalEditorHandler.SetCurrentCourse(courseName); GlobalEditorHandler.StartEditingCourse(); Close(); } } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (string.IsNullOrEmpty(errorMessage) == false) { EditorGUILayout.HelpBox(errorMessage, MessageType.Error); } }
private void OnGUI() { if (course == null || focusedWindow != this) { Close(); instance.IsClosed = true; } GUI.SetNextControlName(textFieldIdentifier.ToString()); newName = EditorGUILayout.TextField(newName); newName = newName.Trim(); if (isFocusSet == false) { isFocusSet = true; EditorGUI.FocusTextInControl(textFieldIdentifier.ToString()); } if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)) { if (CourseAssetUtils.CanRename(course, newName, out string error) == false) { if (string.IsNullOrEmpty(error) == false && string.IsNullOrEmpty(error) == false) { TestableEditorElements.DisplayDialog("Cannot rename the course", error, "OK"); } } else { string oldName = course.Data.Name; RevertableChangesHandler.Do(new CourseCommand( () => { if (CourseAssetUtils.CanRename(course, newName, out string errorMessage) == false) { if (string.IsNullOrEmpty(errorMessage) == false) { TestableEditorElements.DisplayDialog("Cannot rename the course", errorMessage, "OK"); } RevertableChangesHandler.FlushStack(); } else { CourseAssetManager.RenameCourse(course, newName); } }, () => { if (CourseAssetUtils.CanRename(course, newName, out string errorMessage) == false) { if (string.IsNullOrEmpty(errorMessage) == false) { TestableEditorElements.DisplayDialog("Cannot rename the course", errorMessage, "OK"); } RevertableChangesHandler.FlushStack(); } else { CourseAssetManager.RenameCourse(course, oldName); } } )); } Close(); instance.IsClosed = true; Event.current.Use(); } else if (Event.current.keyCode == KeyCode.Escape) { Close(); instance.IsClosed = true; Event.current.Use(); } }
/// <inheritdoc /> public override void Draw(Rect window) { GUILayout.BeginArea(window); GUILayout.Label("Setup Training", CreatorEditorStyles.Title); GUI.enabled = loadSampleScene == false; GUILayout.Label("Name of your VR Training", CreatorEditorStyles.Header); courseName = CreatorGUILayout.DrawTextField(courseName, MaxCourseNameLength, GUILayout.Width(window.width * 0.7f)); GUI.enabled = true; if (CourseAssetUtils.CanCreate(courseName, out string errorMessage) == false && lastCreatedCourse != courseName) { GUIContent courseWarningContent = warningContent; courseWarningContent.text = errorMessage; GUILayout.Label(courseWarningContent, CreatorEditorStyles.Label, GUILayout.MinHeight(MinHeightOfInfoText)); CanProceed = false; } else { GUILayout.Space(MinHeightOfInfoText + CreatorEditorStyles.BaseIndent); CanProceed = true; } GUILayout.BeginHorizontal(); GUILayout.Space(CreatorEditorStyles.Indent); GUILayout.BeginVertical(); bool isUseCurrentScene = GUILayout.Toggle(useCurrentScene, "Take my current scene", CreatorEditorStyles.RadioButton); if (useCurrentScene == false && isUseCurrentScene) { useCurrentScene = true; createNewScene = false; loadSampleScene = false; } bool isCreateNewScene = GUILayout.Toggle(createNewScene, "Create a new scene", CreatorEditorStyles.RadioButton); if (createNewScene == false && isCreateNewScene) { createNewScene = true; useCurrentScene = false; loadSampleScene = false; } EditorGUILayout.Space(); loadSampleScene = GUILayout.Toggle(loadSampleScene, "Load Step by Step Guide Scene", CreatorEditorStyles.RadioButton); if (loadSampleScene) { createNewScene = false; useCurrentScene = false; CanProceed = true; GUILayout.BeginHorizontal(); { GUILayout.Space(CreatorEditorStyles.Indent); CreatorGUILayout.DrawLink("Hello Creator – a 5-step guide to a basic training application", "https://developers.innoactive.de/documentation/creator/latest/articles/step-by-step-guides/hello-creator.html"); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (createNewScene) { GUIContent helpContent; string sceneInfoText = "Scene will have the same name as the training course."; if (SceneSetupUtils.SceneExists(courseName)) { sceneInfoText += " Scene already exists"; CanProceed = false; helpContent = warningContent; } else { helpContent = infoContent; } helpContent.text = sceneInfoText; GUILayout.BeginHorizontal(); { GUILayout.Space(CreatorEditorStyles.Indent); EditorGUILayout.LabelField(helpContent, CreatorEditorStyles.Label, GUILayout.MinHeight(MinHeightOfInfoText)); } GUILayout.EndHorizontal(); } GUILayout.EndArea(); }