CharTweener
CharTweener copied to clipboard
Only works first run (Domain reload off?)
It works great, but only the first time after compilation. If i stop and start the game, the effect doesn't show. I have the Project settings > Reload Domain disabled. Does this use any static variables that needs resetting?
I seem to have fixed it with the tips from https://docs.unity3d.com/Manual/DomainReloading.html
using System.Collections.Generic;
using TMPro;
using UnityEngine;
namespace CharTween
{
public static class CharTweenerUtility
{
private static Dictionary<TMP_Text, CharTweener> Tweeners = new Dictionary<TMP_Text, CharTweener>();
/// <summary>
/// Returns a <see cref="CharTweener"/> guaranteeing the same instance is used for the same text.
/// </summary>
public static CharTweener GetCharTweener(this TMP_Text text)
{
CharTweener tweener;
if (Tweeners.TryGetValue(text, out tweener))
return tweener;
tweener = text.gameObject.AddComponent<CharTweener>();
tweener.Initialize(text);
Tweeners.Add(text, tweener);
return tweener;
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init()
{
Tweeners = new Dictionary<TMP_Text, CharTweener>();
}
}
}