AnimationClip.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Animation
  8. * @{
  9. */
  10. /// <summary>
  11. /// Contains animation curves for translation/rotation/scale of scene object/skeleton bones, as well as curves for
  12. /// generic property animation.
  13. /// </summary>
  14. public class AnimationClip : Resource
  15. {
  16. // Constructor for runtime use only (dummy parameter to differentiate from the normal constructor)
  17. private AnimationClip(bool dummy)
  18. { }
  19. /// <summary>
  20. /// Creates a new animation clip with no curves or events.
  21. /// </summary>
  22. public AnimationClip()
  23. {
  24. Internal_CreateInstance(this);
  25. }
  26. /// <summary>
  27. /// Returns the length of the animation clip, in seconds.
  28. /// </summary>
  29. public float Length
  30. {
  31. get { return Internal_GetLength(mCachedPtr); }
  32. }
  33. /// <summary>
  34. /// Returns the number of samples per second the animation clip curves were sampled at. This value is not used by
  35. /// the animation clip or curves directly since unevenly spaced keyframes are supported. But it can be of value when
  36. /// determining the original sample rate of an imported animation or similar.
  37. /// </summary>
  38. public int SampleRate
  39. {
  40. get { return Internal_GetSampleRate(mCachedPtr); }
  41. set { Internal_SetSampleRate(mCachedPtr, value); }
  42. }
  43. /// <summary>
  44. /// A set of all curves stored in the animation clip.
  45. /// </summary>
  46. public AnimationCurves Curves
  47. {
  48. get { return Internal_GetAnimationCurves(mCachedPtr); }
  49. set { Internal_SetAnimationCurves(mCachedPtr, value); }
  50. }
  51. /// <summary>
  52. /// A set of all events stored in the animation clip.
  53. /// </summary>
  54. public AnimationEvent[] Events
  55. {
  56. get { return Internal_GetAnimationEvents(mCachedPtr); }
  57. set { Internal_SetAnimationEvents(mCachedPtr, value); }
  58. }
  59. [MethodImpl(MethodImplOptions.InternalCall)]
  60. private static extern void Internal_CreateInstance(AnimationClip instance);
  61. [MethodImpl(MethodImplOptions.InternalCall)]
  62. private static extern AnimationCurves Internal_GetAnimationCurves(IntPtr thisPtr);
  63. [MethodImpl(MethodImplOptions.InternalCall)]
  64. private static extern void Internal_SetAnimationCurves(IntPtr thisPtr, AnimationCurves curves);
  65. [MethodImpl(MethodImplOptions.InternalCall)]
  66. private static extern AnimationEvent[] Internal_GetAnimationEvents(IntPtr thisPtr);
  67. [MethodImpl(MethodImplOptions.InternalCall)]
  68. private static extern void Internal_SetAnimationEvents(IntPtr thisPtr, AnimationEvent[] events);
  69. [MethodImpl(MethodImplOptions.InternalCall)]
  70. private static extern float Internal_GetLength(IntPtr thisPtr);
  71. [MethodImpl(MethodImplOptions.InternalCall)]
  72. private static extern int Internal_GetSampleRate(IntPtr thisPtr);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern void Internal_SetSampleRate(IntPtr thisPtr, int sampleRate);
  75. }
  76. /// <summary>
  77. /// Event that is triggered when animation reaches a certain point.
  78. /// </summary>
  79. public class AnimationEvent
  80. {
  81. /// <summary>
  82. /// Constructs a new animation event.
  83. /// </summary>
  84. /// <param name="name">Name used to identify the event when it is triggered.</param>
  85. /// <param name="time">Time at which to trigger the event, in seconds.</param>
  86. public AnimationEvent(string name, float time)
  87. {
  88. Name = name;
  89. Time = time;
  90. }
  91. /// <summary>
  92. /// Name used to identify the event when it is triggered.
  93. /// </summary>
  94. public string Name;
  95. /// <summary>
  96. /// Time at which to trigger the event, in seconds.
  97. /// </summary>
  98. public float Time;
  99. }
  100. /** @} */
  101. }