Simple solution building on other ideas from this thread.
This solves our issue by extending LeanTween's functionality, allowing the chaining of operations (which is a must for LT) and setting up a system to be easily reusable as opposed to building a dedicated function for each TMP game object you want to target.
Paste into LeanTween.cs (carefully, there are multiple class definitions within the file):
public static LTDescr LeanTMPAlpha(TextMeshProUGUI txt, float to, float time)
{
var color = txt.color;
var fadeoutcolor = new Color(color.r,color.g,color.b,to);
return LeanTween.value(txt.gameObject, color, fadeoutcolor, time).setOnUpdate(co => txt.color = co);
}
public static LTDescr LeanTMPColor(TextMeshProUGUI txt, Color to, float time)
{
var color = txt.color;
var fadeoutcolor = to;
return LeanTween.value(txt.gameObject, color, fadeoutcolor, time).setOnUpdate(co => txt.color = co);
}
Paste into LeanTweenExt.cs:
public static LTDescr LeanTMPAlpha(this TextMeshProUGUI txt, float to, float time) { return LeanTween.LeanTMPAlpha(txt, to, time); }
public static LTDescr LeanTMPColor(this TextMeshProUGUI txt, Color to, float time) { return LeanTween.LeanTMPColor(txt, to, time); }
Example demonstrates calling function from extension class helper function (tmp.LeanTMPAlpha(...)) and chaining with standard LeanTween call (LeanTween.LeanTMPAlpha(tmp,....):
void Start()
{
TextMeshProUGUI tmp = GetComponent<TextMeshProUGUI>();
tmp.LeanTweenAlpha(0f, 2f).setOnComplete(() => LeanTween.LeanTMPAlpha(tmp, 1f, 4f).setEaseOutExpo());
}