AnimationStateData.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Spine
  4. {
  5. public class AnimationStateData
  6. {
  7. public AnimationStateData(SkeletonData skeletonData)
  8. {
  9. this.skeletonData = skeletonData;
  10. }
  11. public SkeletonData SkeletonData
  12. {
  13. get
  14. {
  15. return this.skeletonData;
  16. }
  17. }
  18. public float DefaultMix
  19. {
  20. get
  21. {
  22. return this.defaultMix;
  23. }
  24. set
  25. {
  26. this.defaultMix = value;
  27. }
  28. }
  29. public void SetMix(string fromName, string toName, float duration)
  30. {
  31. Animation animation = this.skeletonData.FindAnimation(fromName);
  32. if (animation == null)
  33. {
  34. throw new ArgumentException("Animation not found: " + fromName);
  35. }
  36. Animation animation2 = this.skeletonData.FindAnimation(toName);
  37. if (animation2 == null)
  38. {
  39. throw new ArgumentException("Animation not found: " + toName);
  40. }
  41. this.SetMix(animation, animation2, duration);
  42. }
  43. public void SetMix(Animation from, Animation to, float duration)
  44. {
  45. if (from == null)
  46. {
  47. throw new ArgumentNullException("from cannot be null.");
  48. }
  49. if (to == null)
  50. {
  51. throw new ArgumentNullException("to cannot be null.");
  52. }
  53. KeyValuePair<Animation, Animation> key = new KeyValuePair<Animation, Animation>(from, to);
  54. this.animationToMixTime.Remove(key);
  55. this.animationToMixTime.Add(key, duration);
  56. }
  57. public float GetMix(Animation from, Animation to)
  58. {
  59. KeyValuePair<Animation, Animation> key = new KeyValuePair<Animation, Animation>(from, to);
  60. float result;
  61. if (this.animationToMixTime.TryGetValue(key, out result))
  62. {
  63. return result;
  64. }
  65. return this.defaultMix;
  66. }
  67. internal SkeletonData skeletonData;
  68. private Dictionary<KeyValuePair<Animation, Animation>, float> animationToMixTime = new Dictionary<KeyValuePair<Animation, Animation>, float>();
  69. internal float defaultMix;
  70. }
  71. }