EventTimeline.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class EventTimeline : Timeline
  6. {
  7. public EventTimeline(int frameCount)
  8. {
  9. this.frames = new float[frameCount];
  10. this.events = new Event[frameCount];
  11. }
  12. public float[] Frames
  13. {
  14. get
  15. {
  16. return this.frames;
  17. }
  18. set
  19. {
  20. this.frames = value;
  21. }
  22. }
  23. public Event[] Events
  24. {
  25. get
  26. {
  27. return this.events;
  28. }
  29. set
  30. {
  31. this.events = value;
  32. }
  33. }
  34. public int FrameCount
  35. {
  36. get
  37. {
  38. return this.frames.Length;
  39. }
  40. }
  41. public void SetFrame(int frameIndex, float time, Event e)
  42. {
  43. this.frames[frameIndex] = time;
  44. this.events[frameIndex] = e;
  45. }
  46. public void Apply(Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha)
  47. {
  48. if (firedEvents == null)
  49. {
  50. return;
  51. }
  52. float[] array = this.frames;
  53. int num = array.Length;
  54. if (lastTime > time)
  55. {
  56. this.Apply(skeleton, lastTime, 2.14748365E+09f, firedEvents, alpha);
  57. lastTime = -1f;
  58. }
  59. else if (lastTime >= array[num - 1])
  60. {
  61. return;
  62. }
  63. if (time < array[0])
  64. {
  65. return;
  66. }
  67. int i;
  68. if (lastTime < array[0])
  69. {
  70. i = 0;
  71. }
  72. else
  73. {
  74. i = Animation.binarySearch(array, lastTime);
  75. float num2 = array[i];
  76. while (i > 0)
  77. {
  78. if (array[i - 1] != num2)
  79. {
  80. break;
  81. }
  82. i--;
  83. }
  84. }
  85. while (i < num && time >= array[i])
  86. {
  87. firedEvents.Add(this.events[i]);
  88. i++;
  89. }
  90. }
  91. internal float[] frames;
  92. private Event[] events;
  93. }
  94. }