FFDTimeline.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class FFDTimeline : CurveTimeline
  6. {
  7. public FFDTimeline(int frameCount) : base(frameCount)
  8. {
  9. this.frames = new float[frameCount];
  10. this.frameVertices = new float[frameCount][];
  11. }
  12. public int SlotIndex
  13. {
  14. get
  15. {
  16. return this.slotIndex;
  17. }
  18. set
  19. {
  20. this.slotIndex = value;
  21. }
  22. }
  23. public float[] Frames
  24. {
  25. get
  26. {
  27. return this.frames;
  28. }
  29. set
  30. {
  31. this.frames = value;
  32. }
  33. }
  34. public float[][] Vertices
  35. {
  36. get
  37. {
  38. return this.frameVertices;
  39. }
  40. set
  41. {
  42. this.frameVertices = value;
  43. }
  44. }
  45. public Attachment Attachment
  46. {
  47. get
  48. {
  49. return this.attachment;
  50. }
  51. set
  52. {
  53. this.attachment = value;
  54. }
  55. }
  56. public void SetFrame(int frameIndex, float time, float[] vertices)
  57. {
  58. this.frames[frameIndex] = time;
  59. this.frameVertices[frameIndex] = vertices;
  60. }
  61. public override void Apply(Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha)
  62. {
  63. Slot slot = skeleton.slots[this.slotIndex];
  64. if (slot.attachment != this.attachment)
  65. {
  66. return;
  67. }
  68. float[] array = this.frames;
  69. if (time < array[0])
  70. {
  71. return;
  72. }
  73. float[][] array2 = this.frameVertices;
  74. int num = array2[0].Length;
  75. float[] array3 = slot.attachmentVertices;
  76. if (array3.Length < num)
  77. {
  78. array3 = new float[num];
  79. slot.attachmentVertices = array3;
  80. }
  81. if (array3.Length != num)
  82. {
  83. alpha = 1f;
  84. }
  85. slot.attachmentVerticesCount = num;
  86. if (time >= array[array.Length - 1])
  87. {
  88. float[] array4 = array2[array.Length - 1];
  89. if (alpha < 1f)
  90. {
  91. for (int i = 0; i < num; i++)
  92. {
  93. float num2 = array3[i];
  94. array3[i] = num2 + (array4[i] - num2) * alpha;
  95. }
  96. }
  97. else
  98. {
  99. Array.Copy(array4, 0, array3, 0, num);
  100. }
  101. return;
  102. }
  103. int num3 = Animation.binarySearch(array, time);
  104. float num4 = array[num3];
  105. float num5 = 1f - (time - num4) / (array[num3 - 1] - num4);
  106. num5 = base.GetCurvePercent(num3 - 1, (num5 >= 0f) ? ((num5 <= 1f) ? num5 : 1f) : 0f);
  107. float[] array5 = array2[num3 - 1];
  108. float[] array6 = array2[num3];
  109. if (alpha < 1f)
  110. {
  111. for (int j = 0; j < num; j++)
  112. {
  113. float num6 = array5[j];
  114. float num7 = array3[j];
  115. array3[j] = num7 + (num6 + (array6[j] - num6) * num5 - num7) * alpha;
  116. }
  117. }
  118. else
  119. {
  120. for (int k = 0; k < num; k++)
  121. {
  122. float num8 = array5[k];
  123. array3[k] = num8 + (array6[k] - num8) * num5;
  124. }
  125. }
  126. }
  127. internal int slotIndex;
  128. internal float[] frames;
  129. private float[][] frameVertices;
  130. internal Attachment attachment;
  131. }
  132. }