TextFontSizeMixer.cs 836 B

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