RectTransformRotationMixer.cs 881 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. namespace UnityUIPlayables
  3. {
  4. public class RectTransformRotationMixer
  5. {
  6. private Vector3 _blendedValue;
  7. private float _totalWeight;
  8. public void SetupFrame()
  9. {
  10. _blendedValue = Vector3.zero;
  11. _totalWeight = 0.0f;
  12. }
  13. public void Blend(Vector3 startValue, Vector3 endValue, float inputWeight, float progress)
  14. {
  15. _blendedValue += Vector3.Lerp(startValue, endValue, progress) * inputWeight;
  16. _totalWeight += inputWeight;
  17. }
  18. public void ApplyFrame(RectTransform binding)
  19. {
  20. if (_totalWeight == 0)
  21. {
  22. return;
  23. }
  24. _blendedValue += binding.localRotation.eulerAngles * (1f - _totalWeight);
  25. binding.localRotation = Quaternion.Euler(_blendedValue);
  26. }
  27. }
  28. }