CanvasGroupAlphaMixer.cs 812 B

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