SceneData.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. namespace AssetBank.Editor.Data
  7. {
  8. [Serializable]
  9. public class SceneData
  10. {
  11. // --- LEGEND ---
  12. // p: PrefabsInScene
  13. // h: Hierarchy
  14. [JsonProperty("p", NullValueHandling = NullValueHandling.Ignore)]
  15. public List<string> PrefabsInScene { get; set; } = new();
  16. [JsonProperty("h", NullValueHandling = NullValueHandling.Ignore)]
  17. public List<GameObjectData> Hierarchy { get; set; } = new();
  18. public bool ShouldSerializePrefabsInScene() => PrefabsInScene is { Count: > 0 };
  19. public bool ShouldSerializeHierarchy() => Hierarchy is { Count: > 0 };
  20. }
  21. [Serializable]
  22. public class GameObjectData
  23. {
  24. // --- LEGEND ---
  25. // e: Enabled
  26. // n: Name
  27. // t: Tag
  28. // l: Layer
  29. // a: AnchorId
  30. // pi: PrefabIndex
  31. // c: Components
  32. // ac: AddedComponents
  33. // rc: RemovedComponentAnchorIds
  34. // ch: Children
  35. [JsonProperty("e", DefaultValueHandling = DefaultValueHandling.Ignore)]
  36. [DefaultValue(true)]
  37. public bool Enabled { get; set; } = true;
  38. [JsonProperty("n")]
  39. public string Name { get; set;}
  40. [JsonProperty("t", DefaultValueHandling = DefaultValueHandling.Ignore)]
  41. [DefaultValue("Untagged")]
  42. public string Tag { get; set; } = "Untagged";
  43. [JsonProperty("l", DefaultValueHandling = DefaultValueHandling.Ignore)]
  44. [DefaultValue(0)]
  45. public int Layer { get; set; }
  46. [JsonProperty("a")]
  47. public string AnchorId { get; set;}
  48. [JsonProperty("pi", NullValueHandling = NullValueHandling.Ignore)]
  49. public int? PrefabIndex { get; set; }
  50. [JsonProperty("c", NullValueHandling = NullValueHandling.Ignore)]
  51. public List<ComponentData> Components { get; set; } = new();
  52. [JsonProperty("ac", NullValueHandling = NullValueHandling.Ignore)]
  53. public List<ComponentData> AddedComponents { get; set; } = new();
  54. [JsonProperty("rc", NullValueHandling = NullValueHandling.Ignore)]
  55. public List<string> RemovedComponentAnchorIds { get; set; } = new();
  56. [JsonProperty("ch", NullValueHandling = NullValueHandling.Ignore)]
  57. public List<GameObjectData> Children { get; set; } = new();
  58. public bool ShouldSerializeComponents() => Components is { Count: > 0 };
  59. public bool ShouldSerializeAddedComponents() => AddedComponents is { Count: > 0 };
  60. public bool ShouldSerializeRemovedComponentAnchorIds() => RemovedComponentAnchorIds is { Count: > 0 };
  61. public bool ShouldSerializeChildren() => Children is { Count: > 0 };
  62. }
  63. [Serializable]
  64. public class ComponentData
  65. {
  66. // --- LEGEND ---
  67. // t: Name (Type)
  68. // a: AnchorId
  69. // f: Fields (via JsonExtensionData)
  70. [JsonProperty("t")]
  71. public string Name { get; set; }
  72. [JsonProperty("a")]
  73. public string AnchorId { get; set; }
  74. [JsonProperty("f")]
  75. [JsonExtensionData]
  76. public IDictionary<string, JToken> Fields { get; set; } = new Dictionary<string, JToken>();
  77. public bool ShouldSerializeFields() => Fields is { Count: > 0 };
  78. }
  79. }