SkinData.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using System.Collections.Generic;
  24. namespace DragonBones
  25. {
  26. /// <summary>
  27. /// - The skin data, typically a armature data instance contains at least one skinData.
  28. /// </summary>
  29. /// <version>DragonBones 3.0</version>
  30. /// <language>en_US</language>
  31. /// <summary>
  32. /// - 皮肤数据,通常一个骨架数据至少包含一个皮肤数据。
  33. /// </summary>
  34. /// <version>DragonBones 3.0</version>
  35. /// <language>zh_CN</language>
  36. public class SkinData : BaseObject
  37. {
  38. /// <summary>
  39. /// - The skin name.
  40. /// </summary>
  41. /// <version>DragonBones 3.0</version>
  42. /// <language>en_US</language>
  43. /// <summary>
  44. /// - 皮肤名称。
  45. /// </summary>
  46. /// <version>DragonBones 3.0</version>
  47. /// <language>zh_CN</language>
  48. public string name;
  49. /// <private/>
  50. public readonly Dictionary<string, List<DisplayData>> displays = new Dictionary<string, List<DisplayData>>();
  51. /// <private/>
  52. public ArmatureData parent;
  53. /// <inheritDoc/>
  54. protected override void _OnClear()
  55. {
  56. foreach (var list in this.displays.Values)
  57. {
  58. foreach (var display in list)
  59. {
  60. display.ReturnToPool();
  61. }
  62. }
  63. this.name = "";
  64. this.displays.Clear();
  65. this.parent = null;
  66. }
  67. /// <internal/>
  68. /// <private/>
  69. public void AddDisplay(string slotName, DisplayData value)
  70. {
  71. if (!string.IsNullOrEmpty(slotName) && value != null && !string.IsNullOrEmpty(value.name))
  72. {
  73. if (!this.displays.ContainsKey(slotName))
  74. {
  75. this.displays[slotName] = new List<DisplayData>();
  76. }
  77. if (value != null)
  78. {
  79. value.parent = this;
  80. }
  81. var slotDisplays = this.displays[slotName]; // TODO clear prev
  82. slotDisplays.Add(value);
  83. }
  84. }
  85. /// <private/>
  86. public DisplayData GetDisplay(string slotName, string displayName)
  87. {
  88. var slotDisplays = this.GetDisplays(slotName);
  89. if (slotDisplays != null)
  90. {
  91. foreach (var display in slotDisplays)
  92. {
  93. if (display != null && display.name == displayName)
  94. {
  95. return display;
  96. }
  97. }
  98. }
  99. return null;
  100. }
  101. /// <private/>
  102. public List<DisplayData> GetDisplays(string slotName)
  103. {
  104. if (string.IsNullOrEmpty(slotName) || !this.displays.ContainsKey(slotName))
  105. {
  106. return null;
  107. }
  108. return this.displays[slotName];
  109. }
  110. }
  111. }