private static void ImportTraining() { string path = EditorUtility.OpenFilePanel("Select your training", ".", String.Empty); if (string.IsNullOrEmpty(path) || Directory.Exists(path)) { return; } string format = Path.GetExtension(path).Replace(".", ""); List <ICourseSerializer> result = GetFittingSerializer(format); if (result.Count == 0) { Debug.LogError("Tried to import, but no Serializer found."); return; } if (result.Count == 1) { CourseAssetManager.Import(path, result.First()); } else { ChooseSerializerPopup.Show(result, (serializer) => { CourseAssetManager.Import(path, serializer); }); } }
/// <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); } }
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); } }
protected override void AdditionalTeardown() { base.AdditionalTeardown(); foreach (CourseCreationWizard window in Resources.FindObjectsOfTypeAll <CourseCreationWizard>()) { window.Close(); } CourseAssetManager.Delete(courseName); GlobalEditorHandler.SetDefaultStrategy(); }
protected override CourseCreationWizard Given() { GlobalEditorHandler.SetStrategy(new EmptyTestStrategy()); CourseAssetManager.Delete(courseName); foreach (CourseCreationWizard window in Resources.FindObjectsOfTypeAll <CourseCreationWizard>()) { window.Close(); } CourseCreationWizard wizard = ScriptableObject.CreateInstance <CourseCreationWizard>(); wizard.ShowUtility(); wizard.maxSize = wizard.minSize; wizard.position = new Rect(Vector2.zero, wizard.minSize); return(wizard); }
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(); } }