RotateTimeline.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class RotateTimeline : CurveTimeline
  6. {
  7. public RotateTimeline(int frameCount) : base(frameCount)
  8. {
  9. this.frames = new float[frameCount << 1];
  10. }
  11. public int BoneIndex
  12. {
  13. get
  14. {
  15. return this.boneIndex;
  16. }
  17. set
  18. {
  19. this.boneIndex = value;
  20. }
  21. }
  22. public float[] Frames
  23. {
  24. get
  25. {
  26. return this.frames;
  27. }
  28. set
  29. {
  30. this.frames = value;
  31. }
  32. }
  33. public void SetFrame(int frameIndex, float time, float angle)
  34. {
  35. frameIndex *= 2;
  36. this.frames[frameIndex] = time;
  37. this.frames[frameIndex + 1] = angle;
  38. }
  39. public override void Apply(Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha)
  40. {
  41. float[] array = this.frames;
  42. if (time < array[0])
  43. {
  44. return;
  45. }
  46. Bone bone = skeleton.bones[this.boneIndex];
  47. float num;
  48. if (time >= array[array.Length - 2])
  49. {
  50. for (num = bone.data.rotation + array[array.Length - 1] - bone.rotation; num > 180f; num -= 360f)
  51. {
  52. }
  53. while (num < -180f)
  54. {
  55. num += 360f;
  56. }
  57. bone.rotation += num * alpha;
  58. return;
  59. }
  60. int num2 = Animation.binarySearch(array, time, 2);
  61. float num3 = array[num2 - 1];
  62. float num4 = array[num2];
  63. float num5 = 1f - (time - num4) / (array[num2 + -2] - num4);
  64. num5 = base.GetCurvePercent((num2 >> 1) - 1, (num5 >= 0f) ? ((num5 <= 1f) ? num5 : 1f) : 0f);
  65. for (num = array[num2 + 1] - num3; num > 180f; num -= 360f)
  66. {
  67. }
  68. while (num < -180f)
  69. {
  70. num += 360f;
  71. }
  72. for (num = bone.data.rotation + (num3 + num * num5) - bone.rotation; num > 180f; num -= 360f)
  73. {
  74. }
  75. while (num < -180f)
  76. {
  77. num += 360f;
  78. }
  79. bone.rotation += num * alpha;
  80. }
  81. protected const int PREV_FRAME_TIME = -2;
  82. protected const int FRAME_VALUE = 1;
  83. internal int boneIndex;
  84. internal float[] frames;
  85. }
  86. }