RectTransformAnimationMixer.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. namespace UnityUIPlayables
  3. {
  4. public class RectTransformAnimationMixer : AnimationMixer<RectTransform, RectTransformAnimationBehaviour>
  5. {
  6. private readonly RectTransformPositionMixer _positionMixer = new RectTransformPositionMixer();
  7. private readonly RectTransformRotationMixer _rotationMixer = new RectTransformRotationMixer();
  8. private readonly RectTransformScaleMixer _scaleMixer = new RectTransformScaleMixer();
  9. private readonly RectTransformSizeDeltaMixer _sizeDeltaMixer = new RectTransformSizeDeltaMixer();
  10. public override void SetupFrame(RectTransform binding)
  11. {
  12. base.SetupFrame(binding);
  13. _positionMixer.SetupFrame();
  14. _sizeDeltaMixer.SetupFrame();
  15. _rotationMixer.SetupFrame();
  16. _scaleMixer.SetupFrame();
  17. }
  18. public override void Blend(RectTransformAnimationBehaviour behaviour, float inputWeight, float progress)
  19. {
  20. if (behaviour.ControlPosition)
  21. {
  22. _positionMixer.Blend(behaviour.StartValue.AnchoredPosition, behaviour.EndValue.AnchoredPosition,
  23. inputWeight, progress);
  24. }
  25. if (behaviour.ControlSize)
  26. {
  27. _sizeDeltaMixer.Blend(behaviour.StartValue.SizeDelta, behaviour.EndValue.SizeDelta, inputWeight,
  28. progress);
  29. }
  30. if (behaviour.ControlRotation)
  31. {
  32. _rotationMixer.Blend(behaviour.StartValue.LocalRotation, behaviour.EndValue.LocalRotation, inputWeight,
  33. progress);
  34. }
  35. if (behaviour.ControlScale)
  36. {
  37. _scaleMixer.Blend(behaviour.StartValue.LocalScale, behaviour.EndValue.LocalScale, inputWeight,
  38. progress);
  39. }
  40. }
  41. public override void ApplyFrame()
  42. {
  43. _positionMixer.ApplyFrame(Binding);
  44. _sizeDeltaMixer.ApplyFrame(Binding);
  45. _rotationMixer.ApplyFrame(Binding);
  46. _scaleMixer.ApplyFrame(Binding);
  47. }
  48. }
  49. }