Animation.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class Animation
  6. {
  7. public Animation(string name, List<Timeline> timelines, float duration)
  8. {
  9. if (name == null)
  10. {
  11. throw new ArgumentNullException("name cannot be null.");
  12. }
  13. if (timelines == null)
  14. {
  15. throw new ArgumentNullException("timelines cannot be null.");
  16. }
  17. this.name = name;
  18. this.timelines = timelines;
  19. this.duration = duration;
  20. }
  21. public string Name
  22. {
  23. get
  24. {
  25. return this.name;
  26. }
  27. }
  28. public List<Timeline> Timelines
  29. {
  30. get
  31. {
  32. return this.timelines;
  33. }
  34. set
  35. {
  36. this.timelines = value;
  37. }
  38. }
  39. public float Duration
  40. {
  41. get
  42. {
  43. return this.duration;
  44. }
  45. set
  46. {
  47. this.duration = value;
  48. }
  49. }
  50. public void Apply(Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events)
  51. {
  52. if (skeleton == null)
  53. {
  54. throw new ArgumentNullException("skeleton cannot be null.");
  55. }
  56. if (loop && this.duration != 0f)
  57. {
  58. time %= this.duration;
  59. lastTime %= this.duration;
  60. }
  61. List<Timeline> list = this.timelines;
  62. int i = 0;
  63. int count = list.Count;
  64. while (i < count)
  65. {
  66. list[i].Apply(skeleton, lastTime, time, events, 1f);
  67. i++;
  68. }
  69. }
  70. public void Mix(Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events, float alpha)
  71. {
  72. if (skeleton == null)
  73. {
  74. throw new ArgumentNullException("skeleton cannot be null.");
  75. }
  76. if (loop && this.duration != 0f)
  77. {
  78. time %= this.duration;
  79. lastTime %= this.duration;
  80. }
  81. List<Timeline> list = this.timelines;
  82. int i = 0;
  83. int count = list.Count;
  84. while (i < count)
  85. {
  86. list[i].Apply(skeleton, lastTime, time, events, alpha);
  87. i++;
  88. }
  89. }
  90. internal static int binarySearch(float[] values, float target, int step)
  91. {
  92. int num = 0;
  93. int num2 = values.Length / step - 2;
  94. if (num2 == 0)
  95. {
  96. return step;
  97. }
  98. int num3 = (int)((uint)num2 >> 1);
  99. for (;;)
  100. {
  101. if (values[(num3 + 1) * step] <= target)
  102. {
  103. num = num3 + 1;
  104. }
  105. else
  106. {
  107. num2 = num3;
  108. }
  109. if (num == num2)
  110. {
  111. break;
  112. }
  113. num3 = (int)((uint)(num + num2) >> 1);
  114. }
  115. return (num + 1) * step;
  116. }
  117. internal static int binarySearch(float[] values, float target)
  118. {
  119. int num = 0;
  120. int num2 = values.Length - 2;
  121. if (num2 == 0)
  122. {
  123. return 1;
  124. }
  125. int num3 = (int)((uint)num2 >> 1);
  126. for (;;)
  127. {
  128. if (values[num3 + 1] <= target)
  129. {
  130. num = num3 + 1;
  131. }
  132. else
  133. {
  134. num2 = num3;
  135. }
  136. if (num == num2)
  137. {
  138. break;
  139. }
  140. num3 = (int)((uint)(num + num2) >> 1);
  141. }
  142. return num + 1;
  143. }
  144. internal static int linearSearch(float[] values, float target, int step)
  145. {
  146. int i = 0;
  147. int num = values.Length - step;
  148. while (i <= num)
  149. {
  150. if (values[i] > target)
  151. {
  152. return i;
  153. }
  154. i += step;
  155. }
  156. return -1;
  157. }
  158. internal List<Timeline> timelines;
  159. internal float duration;
  160. internal string name;
  161. }
  162. }