FlipXTimeline.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class FlipXTimeline : Timeline
  6. {
  7. public FlipXTimeline(int 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 int FrameCount
  34. {
  35. get
  36. {
  37. return this.frames.Length >> 1;
  38. }
  39. }
  40. public void SetFrame(int frameIndex, float time, bool flip)
  41. {
  42. frameIndex *= 2;
  43. this.frames[frameIndex] = time;
  44. this.frames[frameIndex + 1] = (float)((!flip) ? 0 : 1);
  45. }
  46. public void Apply(Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha)
  47. {
  48. float[] array = this.frames;
  49. if (time < array[0])
  50. {
  51. if (lastTime > time)
  52. {
  53. this.Apply(skeleton, lastTime, 2.14748365E+09f, null, 0f);
  54. }
  55. return;
  56. }
  57. if (lastTime > time)
  58. {
  59. lastTime = -1f;
  60. }
  61. int num = ((time < array[array.Length - 2]) ? Animation.binarySearch(array, time, 2) : array.Length) - 2;
  62. if (array[num] < lastTime)
  63. {
  64. return;
  65. }
  66. this.SetFlip(skeleton.bones[this.boneIndex], array[num + 1] != 0f);
  67. }
  68. protected virtual void SetFlip(Bone bone, bool flip)
  69. {
  70. bone.flipX = flip;
  71. }
  72. internal int boneIndex;
  73. internal float[] frames;
  74. }
  75. }