/// <summary> /// Deletes the course with <paramref name="courseName"/>. /// </summary> internal static void Delete(string courseName) { if (CourseAssetUtils.DoesCourseAssetExist(courseName)) { Directory.Delete(CourseAssetUtils.GetCourseAssetDirectory(courseName), true); AssetDatabase.Refresh(); } }
/// <summary> /// Loads the course with the given <paramref name="courseName"/> from the file system and converts it into the <seealso cref="ICourse"/> instance. /// </summary> internal static ICourse Load(string courseName) { if (CourseAssetUtils.DoesCourseAssetExist(courseName)) { string courseAssetPath = CourseAssetUtils.GetCourseAssetPath(courseName); byte[] courseBytes = File.ReadAllBytes(courseAssetPath); try { return(EditorConfigurator.Instance.Serializer.CourseFromByteArray(courseBytes)); } catch (Exception ex) { Debug.LogError($"Failed to load the course '{courseName}' from '{courseAssetPath}' because of: \n{ex.Message}"); Debug.LogError(ex); } } return(null); }
/// <summary> /// Imports the given <paramref name="course"/> by saving it to the proper directory. If there is a name collision, this course will be renamed. /// </summary> internal static void Import(ICourse course) { int counter = 0; string oldName = course.Data.Name; while (CourseAssetUtils.DoesCourseAssetExist(course.Data.Name)) { if (counter > 0) { course.Data.Name = course.Data.Name.Substring(0, course.Data.Name.Length - 2); } counter++; course.Data.Name += " " + counter; } if (oldName != course.Data.Name) { Debug.LogWarning($"We detected a name collision while importing course \"{oldName}\". We have renamed it to \"{course.Data.Name}\" before importing."); } Save(course); }