TextMeshProUGUIAnimationMixer.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using TMPro;
  2. namespace UnityUIPlayables
  3. {
  4. public class TextMeshProUGUIAnimationMixer : AnimationMixer<TextMeshProUGUI, TextMeshProUGUIAnimationBehaviour>
  5. {
  6. private readonly TextMeshProUGUIColorMixer _colorMixer = new TextMeshProUGUIColorMixer();
  7. private readonly TextMeshProUGUIFaceColorMixer _faceColorMixer = new TextMeshProUGUIFaceColorMixer();
  8. private readonly TextMeshProUGUIFontSizeMixer _fontSizeMixer = new TextMeshProUGUIFontSizeMixer();
  9. private readonly TextMeshProUGUIOutlineColorMixer _outlineColorMixer = new TextMeshProUGUIOutlineColorMixer();
  10. private readonly TextMeshProUGUIOutlineWidthMixer _outlineWidthMixer = new TextMeshProUGUIOutlineWidthMixer();
  11. private readonly TextMeshProUGUISpacingMixer _spacingMixer = new TextMeshProUGUISpacingMixer();
  12. private readonly TextMeshProUGUIVertexGradientMixer _vertexGradientMixer =
  13. new TextMeshProUGUIVertexGradientMixer();
  14. public override void SetupFrame(TextMeshProUGUI binding)
  15. {
  16. base.SetupFrame(binding);
  17. _fontSizeMixer.SetupFrame();
  18. _colorMixer.SetupFrame();
  19. _vertexGradientMixer.SetupFrame();
  20. _spacingMixer.SetupFrame();
  21. _faceColorMixer.SetupFrame();
  22. _outlineColorMixer.SetupFrame();
  23. _outlineWidthMixer.SetupFrame();
  24. }
  25. public override void Blend(TextMeshProUGUIAnimationBehaviour behaviour, float inputWeight, float progress)
  26. {
  27. if (behaviour.ControlFontSize)
  28. {
  29. _fontSizeMixer.Blend(behaviour.StartValue.FontSize, behaviour.EndValue.FontSize, inputWeight, progress);
  30. }
  31. if (behaviour.ControlColor)
  32. {
  33. _colorMixer.Blend(behaviour.StartValue.Color, behaviour.EndValue.Color, inputWeight, progress);
  34. }
  35. if (behaviour.ControlVertexGradient)
  36. {
  37. _vertexGradientMixer.Blend(behaviour.StartValue.VertexGradient, behaviour.EndValue.VertexGradient,
  38. inputWeight, progress);
  39. }
  40. if (behaviour.ControlSpacing)
  41. {
  42. _spacingMixer.Blend(behaviour.StartValue.Spacing, behaviour.EndValue.Spacing, inputWeight, progress);
  43. }
  44. if (behaviour.ControlRuntimeFaceColor)
  45. {
  46. _faceColorMixer.Blend(behaviour.StartValue.FaceColor, behaviour.EndValue.FaceColor, inputWeight,
  47. progress);
  48. }
  49. if (behaviour.ControlRuntimeOutlineColor)
  50. {
  51. _outlineColorMixer.Blend(behaviour.StartValue.OutlineColor, behaviour.EndValue.OutlineColor,
  52. inputWeight, progress);
  53. }
  54. if (behaviour.ControlRuntimeOutlineWidth)
  55. {
  56. _outlineWidthMixer.Blend(behaviour.StartValue.OutlineWidth, behaviour.EndValue.OutlineWidth,
  57. inputWeight, progress);
  58. }
  59. }
  60. public override void ApplyFrame()
  61. {
  62. _fontSizeMixer.ApplyFrame(Binding);
  63. _colorMixer.ApplyFrame(Binding);
  64. _vertexGradientMixer.ApplyFrame(Binding);
  65. _spacingMixer.ApplyFrame(Binding);
  66. _faceColorMixer.ApplyFrame(Binding);
  67. _outlineColorMixer.ApplyFrame(Binding);
  68. _outlineWidthMixer.ApplyFrame(Binding);
  69. }
  70. }
  71. }