UserData.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 user custom data.
  28. /// </summary>
  29. /// <version>DragonBones 5.0</version>
  30. /// <language>en_US</language>
  31. /// <summary>
  32. /// - 用户自定义数据。
  33. /// </summary>
  34. /// <version>DragonBones 5.0</version>
  35. /// <language>zh_CN</language>
  36. public class UserData : BaseObject
  37. {
  38. /// <summary>
  39. /// - The custom int numbers.
  40. /// </summary>
  41. /// <version>DragonBones 5.0</version>
  42. /// <language>en_US</language>
  43. /// <summary>
  44. /// - 自定义整数。
  45. /// </summary>
  46. /// <version>DragonBones 5.0</version>
  47. /// <language>zh_CN</language>
  48. public readonly List<int> ints = new List<int>();
  49. /// <summary>
  50. /// - The custom float numbers.
  51. /// </summary>
  52. /// <version>DragonBones 5.0</version>
  53. /// <language>en_US</language>
  54. /// <summary>
  55. /// - 自定义浮点数。
  56. /// </summary>
  57. /// <version>DragonBones 5.0</version>
  58. /// <language>zh_CN</language>
  59. public readonly List<float> floats = new List<float>();
  60. /// <summary>
  61. /// - The custom strings.
  62. /// </summary>
  63. /// <version>DragonBones 5.0</version>
  64. /// <language>en_US</language>
  65. /// <summary>
  66. /// - 自定义字符串。
  67. /// </summary>
  68. /// <version>DragonBones 5.0</version>
  69. /// <language>zh_CN</language>
  70. public readonly List<string> strings = new List<string>();
  71. /// <inheritDoc/>
  72. protected override void _OnClear()
  73. {
  74. this.ints.Clear();
  75. this.floats.Clear();
  76. this.strings.Clear();
  77. }
  78. /// <internal/>
  79. /// <private/>
  80. internal void AddInt(int value)
  81. {
  82. this.ints.Add(value);
  83. }
  84. /// <internal/>
  85. /// <private/>
  86. internal void AddFloat(float value)
  87. {
  88. this.floats.Add(value);
  89. }
  90. /// <internal/>
  91. /// <private/>
  92. internal void AddString(string value)
  93. {
  94. this.strings.Add(value);
  95. }
  96. /// <summary>
  97. /// - Get the custom int number.
  98. /// </summary>
  99. /// <version>DragonBones 5.0</version>
  100. /// <language>en_US</language>
  101. /// <summary>
  102. /// - 获取自定义整数。
  103. /// </summary>
  104. /// <version>DragonBones 5.0</version>
  105. /// <language>zh_CN</language>
  106. public int GetInt(int index = 0)
  107. {
  108. return index >= 0 && index < this.ints.Count ? this.ints[index] : 0;
  109. }
  110. /// <summary>
  111. /// - Get the custom float number.
  112. /// </summary>
  113. /// <version>DragonBones 5.0</version>
  114. /// <language>en_US</language>
  115. /// <summary>
  116. /// - 获取自定义浮点数。
  117. /// </summary>
  118. /// <version>DragonBones 5.0</version>
  119. /// <language>zh_CN</language>
  120. public float GetFloat(int index = 0)
  121. {
  122. return index >= 0 && index < this.floats.Count ? this.floats[index] : 0.0f;
  123. }
  124. /// <summary>
  125. /// - Get the custom string.
  126. /// </summary>
  127. /// <version>DragonBones 5.0</version>
  128. /// <language>en_US</language>
  129. /// <summary>
  130. /// - 获取自定义字符串。
  131. /// </summary>
  132. /// <version>DragonBones 5.0</version>
  133. /// <language>zh_CN</language>
  134. public string GetString(int index = 0)
  135. {
  136. return index >= 0 && index < this.strings.Count ? this.strings[index] : string.Empty;
  137. }
  138. }
  139. /// <internal/>
  140. /// <private/>
  141. public class ActionData : BaseObject
  142. {
  143. public ActionType type;
  144. // Frame event name | Sound event name | Animation name
  145. public string name;
  146. public BoneData bone;
  147. public SlotData slot;
  148. public UserData data;
  149. protected override void _OnClear()
  150. {
  151. if (this.data != null)
  152. {
  153. this.data.ReturnToPool();
  154. }
  155. this.type = ActionType.Play;
  156. this.name = "";
  157. this.bone = null;
  158. this.slot = null;
  159. this.data = null;
  160. }
  161. }
  162. }