Newer
Older
DungeonShooting / DungeonShooting_Godot / src / framework / map / serialize / tileSet / TileSetInfo.cs
@小李xl 小李xl on 8 Jan 2024 1 KB 生成Godot.TileSet, 开发中
  1.  
  2. using System.Collections.Generic;
  3. using System.Text.Json.Serialization;
  4.  
  5. /// <summary>
  6. /// 图块集数据
  7. /// </summary>
  8. public class TileSetInfo : IClone<TileSetInfo>, IDestroy
  9. {
  10. [JsonIgnore]
  11. public bool IsDestroyed { get; private set; }
  12. /// <summary>
  13. /// 图块集名称
  14. /// </summary>
  15. [JsonInclude]
  16. public string Name;
  17.  
  18. /// <summary>
  19. /// 资源集合
  20. /// </summary>
  21. [JsonInclude]
  22. public List<TileSetSourceInfo> Sources;
  23.  
  24. /// <summary>
  25. /// 初始化默认数据
  26. /// </summary>
  27. public void InitData()
  28. {
  29. Sources = new List<TileSetSourceInfo>();
  30. }
  31. public TileSetInfo Clone()
  32. {
  33. var tileSetInfo = new TileSetInfo();
  34. tileSetInfo.Name = Name;
  35. if (Sources != null)
  36. {
  37. tileSetInfo.Sources = new List<TileSetSourceInfo>();
  38. foreach (var source in Sources)
  39. {
  40. tileSetInfo.Sources.Add(source.Clone());
  41. }
  42. }
  43. return tileSetInfo;
  44. }
  45. public void Destroy()
  46. {
  47. if (IsDestroyed) return;
  48. IsDestroyed = true;
  49.  
  50. if (Sources != null)
  51. {
  52. foreach (var tileSetSourceInfo in Sources)
  53. {
  54. tileSetSourceInfo.Destroy();
  55. }
  56.  
  57. Sources = null;
  58. }
  59. }
  60. }