RawImageUVRectMixer.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace UnityUIPlayables
  4. {
  5. public class RawImageUVRectMixer
  6. {
  7. private Vector2 _blendedPosition;
  8. private Vector2 _blendedSize;
  9. private float _totalWeight;
  10. public void SetupFrame()
  11. {
  12. _blendedPosition = Vector2.zero;
  13. _blendedSize = Vector2.zero;
  14. _totalWeight = 0.0f;
  15. }
  16. public void Blend(Rect startValue, Rect endValue, float inputWeight, float progress)
  17. {
  18. _blendedPosition = Vector2.Lerp(startValue.position, endValue.position, progress) * inputWeight;
  19. _blendedSize = Vector2.Lerp(startValue.size, endValue.size, progress) * inputWeight;
  20. _totalWeight += inputWeight;
  21. }
  22. public void ApplyFrame(RawImage binding)
  23. {
  24. if (_totalWeight == 0)
  25. {
  26. return;
  27. }
  28. _blendedPosition += binding.uvRect.position * (1f - _totalWeight);
  29. _blendedSize += binding.uvRect.size * (1f - _totalWeight);
  30. binding.uvRect = new Rect(_blendedPosition, _blendedSize);
  31. }
  32. }
  33. }