Hi,
your example is almost exactly what I've done and yeah it works in that specific case. But what we want to do was more template tween helper functions. Like:
public static Tweener FadeGraphic(Graphic graphic, bool fadeIn, float duration){
return graphic.DoFade(fadeIn ? 0f : 1f, duration)
.OnBegin(() => { if(!fadeIn) graphic.gameObject.SetActive(true); })
.OnComplete(() => { if(fadeIn) graphic.gameObject.SetActive(false); })
.SetUpdate(true)
.SetAutoKill(false);
}
or
public static Tweener CrossFade(AudioSource source, AudioClip clip, duration){
return ...;
}
So the programmer will have the possibility to cache the "template" tween in any specific script without having to care about setting the callbacks:
Tweener cachedTween = TweenHelper.FadeGraphic(specificGraphic, true, 4f);
...
...
cachedTween.Restart();
Anyway, not sure if I'm explaining well my point
and why I can't see another way to achieve this without having a OnBegin callback that will be sure to be called on each Start. That was only a suggestion
, and we will live with the way DOTween works without a problem
Another suggestion (and do whatever you want with it). The obstacle here is the 4B, and I understand it very well. So I though about something you could implement. I don't know exactly how DOTween works behind the scene so it could be impossible, but maybe implementing a setting to choose which callbacks you need in your project. This way developers could save some memory:
OnPlay -> On/Off
OnStart -> On/Off
OnComplete -> On/Off
and in your DOTween manager having some C# Preprocessor Directives:
#if OnPlay
public TweenCallback OnPlayCallback = null;
#endif
#if OnPlay
public Tweener OnPlay(this Tweener tweener, TweenCallback callback)
{
OnPlayCallback = callback;
return this;
}
#endif
#if OnPlay
if(OnPlayCallback != null)
OnPlayCallback .Invoke();
#endif
Yeah, that will be a lot of job! That is just some ideas
For you warning question. No i don't get any warning while I'm using nested tween more than once inside a sequence unfortunately
.
Here's a small script to test if it was working
:
public class TestCachedTween : MonoBehaviour
{
private Sequence _sequence;
private Tweener _cachedTween;
public float TestedFloat = 10f;
private void Start()
{
_cachedTween = DOTween.To(() => TestedFloat, x => TestedFloat = x, 0f, 5f).SetUpdate(true).SetAutoKill(false).OnComplete(() => {Debug.Log("COMPLETE CACHED TWEEN");});
_sequence = DOTween.Sequence().SetUpdate(true).SetAutoKill(false);
_sequence.Append(_cachedTween); //Is called
_sequence.Append(_cachedTween); //Is not called
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
_sequence.Restart();
}
}
}
Ok I finish to write by book! Hope you didn't fall asleep while reading it
Thanks a lot for your time!
David