Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. public class ResourcesLoadingManager
  8. {
  9. public static List<Disease> LoadResources()
  10. {
  11. List<Disease> diseasesList = new List<Disease>();
  12. List<Exercise> exercisesList = new List<Exercise>();
  13. List<AnimationClip> loadedAnimations = Resources.LoadAll<AnimationClip>("Exercise").ToList();
  14.  
  15.  
  16. foreach (AnimationClip anim in loadedAnimations)
  17. {
  18. Debug.Log(anim.name);
  19. exercisesList.Add(LoadExerciseFile(anim.name));
  20. }
  21.  
  22. List<string> uniqueDiseasesNames = exercisesList.Select(x => x.diseaseName).Distinct().ToList();
  23.  
  24. foreach (string diseaseName in uniqueDiseasesNames)
  25. {
  26. diseasesList.Add(new Disease(diseaseName));
  27. }
  28.  
  29. for (int i = 0; i < diseasesList.Count; ++i)
  30. {
  31. diseasesList[i].exerciseList = exercisesList.Where(x => x.diseaseName == diseasesList[i].name).ToList();
  32. }
  33.  
  34. return diseasesList;
  35. }
  36.  
  37. private static Exercise LoadExerciseFile(string fileName)
  38. {
  39. TextAsset textAsset = Resources.Load<TextAsset>("Exercise\\" + fileName);
  40.  
  41. string[] fileData = textAsset.text.Split('\n');
  42. for (int i = 0; i < fileData.Length; i++)
  43. {
  44. fileData[i] = fileData[i].Replace("\r", "");
  45. }
  46. List<string> newList = new List<string>();
  47.  
  48. for (int i = 4; i < fileData.Length; ++i)
  49. {
  50. newList.Add(fileData[i]);
  51. }
  52.  
  53. Exercise exercise = new Exercise(fileData[0], fileName, fileData[1], Int32.Parse(fileData[3]), fileData[2], newList);
  54.  
  55. return exercise;
  56. }
  57.  
  58. public static AudioClip[] LoadAudioFiles()
  59. {
  60. return Resources.LoadAll<AudioClip>("Sounds/");
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement