SoundTrackManager.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Newtonsoft.Json;
  2. using NUnit.Framework;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class SoundTrackManager
  6. {
  7. public string name { set; get; }
  8. public string resource { set; get; }
  9. public string description { set; get; }
  10. public int speed { set; get; } = 100;
  11. public int length { set; get; } = 0;
  12. public List<SoundAction> soundAction { set; get; } = new List<SoundAction>();
  13. public void ImportFromJson(string json)
  14. {
  15. var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  16. speed = int.Parse(data["speed"].ToString());
  17. name = data["name"].ToString();
  18. resource = data["resource"].ToString();
  19. description = data["description"].ToString();
  20. length = int.Parse(data["length"].ToString());
  21. soundAction.Clear();
  22. SoundAction[] actions = JsonConvert.DeserializeObject<SoundAction[]>(data["action points"].ToString());
  23. foreach (var action in actions)
  24. {
  25. soundAction.Add(action);
  26. }
  27. }
  28. }
  29. public class SoundAction
  30. {
  31. public float time { set; get; } = 0f;
  32. public string action { set; get; } = "";
  33. public bool isTapped = false; // 表示当前这个音乐动作是否被播放过
  34. public bool isActive = false; // 表示当前这个音乐动作是否正在场景中激活
  35. }