TextMeshProUGUIColorMixer.cs 840 B

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