TextMeshProUGUIOutlineWidthMixer.cs 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using TMPro;
  2. using UnityEngine;
  3. namespace UnityUIPlayables
  4. {
  5. public class TextMeshProUGUIOutlineWidthMixer
  6. {
  7. private float _blendedValue;
  8. private float _totalWeight;
  9. public void SetupFrame()
  10. {
  11. _blendedValue = 0;
  12. _totalWeight = 0.0f;
  13. }
  14. public void Blend(float startValue, float endValue, float inputWeight, float progress)
  15. {
  16. _blendedValue += Mathf.Lerp(startValue, endValue, progress) * inputWeight;
  17. _totalWeight += inputWeight;
  18. }
  19. public void ApplyFrame(TextMeshProUGUI binding)
  20. {
  21. // Only at runtime, as a material instance will be created.
  22. if (!Application.isPlaying)
  23. {
  24. return;
  25. }
  26. if (_totalWeight == 0)
  27. {
  28. return;
  29. }
  30. _blendedValue += binding.fontSize * (1f - _totalWeight);
  31. binding.outlineWidth = _blendedValue;
  32. }
  33. }
  34. }