AnimatedFloat.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. using UnityEngine.Animations;
  3. using Unity.Collections;
  4. namespace Animancer
  5. {
  6. /// <summary>[Pro-Only]
  7. /// A wrapper which allows access to the value of <see cref="float"/> properties that are controlled by animations.
  8. /// </summary>
  9. ///
  10. /// <remarks>
  11. /// <strong>Documentation:</strong>
  12. /// <see href="https://kybernetik.com.au/animancer/docs/manual/ik#animated-properties">
  13. /// Animated Properties</see>
  14. /// </remarks>
  15. ///
  16. /// https://kybernetik.com.au/animancer/api/Animancer/AnimatedFloat
  17. ///
  18. public class AnimatedFloat : AnimatedProperty<AnimatedFloat.Job, float>
  19. {
  20. /************************************************************************************************************************/
  21. /// <summary>
  22. /// Allocates room for a specified number of properties to be filled by
  23. /// <see cref="InitializeProperty(int, Transform, Type, string)"/>.
  24. /// </summary>
  25. public AnimatedFloat(IAnimancerComponent animancer, int propertyCount,
  26. NativeArrayOptions options = NativeArrayOptions.ClearMemory)
  27. : base(animancer, propertyCount, options)
  28. { }
  29. /// <summary>Initializes a single property.</summary>
  30. public AnimatedFloat(IAnimancerComponent animancer, string propertyName)
  31. : base(animancer, propertyName)
  32. { }
  33. /// <summary>Initializes a group of properties.</summary>
  34. public AnimatedFloat(IAnimancerComponent animancer, params string[] propertyNames)
  35. : base(animancer, propertyNames)
  36. { }
  37. /************************************************************************************************************************/
  38. protected override void CreateJob()
  39. {
  40. _Job = new() { properties = _Properties, values = _Values };
  41. }
  42. /************************************************************************************************************************/
  43. /// <summary>An <see cref="IAnimationJob"/> which reads an array of <see cref="float"/> values.</summary>
  44. /// https://kybernetik.com.au/animancer/api/Animancer/Job
  45. ///
  46. public struct Job : IAnimationJob
  47. {
  48. public NativeArray<PropertyStreamHandle> properties;
  49. public NativeArray<float> values;
  50. public void ProcessRootMotion(AnimationStream stream) { }
  51. public void ProcessAnimation(AnimationStream stream)
  52. {
  53. for (int i = properties.Length - 1; i >= 0; i--)
  54. values[i] = properties[i].GetFloat(stream);
  55. }
  56. }
  57. /************************************************************************************************************************/
  58. }
  59. }