Closed GoogleCodeExporter closed 9 years ago
Hi,
I really don't want to tie tweens to gameObjects, because I like that the API
makes it clear that tweens are based on the given target (which might not be
related to a gameObject at all) instead than strictly to Unity elements.
That said, tell me more about your implementation, and I'll help making your
custom code more efficient. Why is SetEase a problem? Can't you check if a
target/Component is null immediately after creation, before setting the
parameters?
Original comment by daniele....@gmail.com
on 11 Mar 2015 at 10:31
Here is what I'm doing now. Where I return the suicideTweener I use to
return null, which is where the problem with SetEase came up. I could check
for a null tweener before trying to call SetEase on it, but I kind of just
want it to work without having to worrier about checking for nulls. I
coming from iTween and that was one thing I like about it was that it just
worked. Any advice you could give would be appreciated.
public static Tweener DOColor(this GameObject gameObject, Color to,
float duration)
{
if (gameObject)
{
if (gameObject.GetComponent<Camera>())
return gameObject.GetComponent<Camera>().DOColor(to,
duration);
if (gameObject.GetComponent<Light>())
return gameObject.GetComponent<Light>().DOColor(to,
duration);
if (gameObject.GetComponent<SpriteRenderer>())
return
gameObject.GetComponent<SpriteRenderer>().DOColor(to, duration);
if (gameObject.GetComponent<Renderer>())
return
gameObject.GetComponent<Renderer>().material.DOColor(to, duration);
if (gameObject.GetComponent<Graphic>())
return gameObject.GetComponent<Graphic>().DOColor(to,
duration);
}
return MakeSuicideTweener();
}
public static Tweener MakeSuicideTweener()
{
float nothing;
Tweener t = DOTween.To(() => 0, x => nothing = x, 0, 0);
t.OnStepComplete(() => t.Kill());
return t;
}
-William Craven
Original comment by wcraven501@gmail.com
on 12 Mar 2015 at 12:24
Sorry for the late answer. If your only problem is ease, why don't you add it
as a parameter to the DOColor method? That way you wouldn't need
MakeSuicideTweener, and you could do something like this:
public static Tweener DOColor(this GameObject gameObject, Color to,
float duration, Ease ease = Ease.OutQuad)
{
if (gameObject)
{
if (gameObject.GetComponent<Camera>())
return gameObject.GetComponent<Camera>().DOColor(to, duration).SetEase(ease);
if (gameObject.GetComponent<Light>())
return gameObject.GetComponent<Light>().DOColor(to, duration).SetEase(ease);
if (gameObject.GetComponent<SpriteRenderer>())
return gameObject.GetComponent<SpriteRenderer>().DOColor(to, duration).SetEase(ease);
if (gameObject.GetComponent<Renderer>())
return gameObject.GetComponent<Renderer>().material.DOColor(to, duration).SetEase(ease);
if (gameObject.GetComponent<Graphic>())
return gameObject.GetComponent<Graphic>().DOColor(to, duration).SetEase(ease);
}
return null;
}
Original comment by daniele....@gmail.com
on 13 Mar 2015 at 11:19
Original issue reported on code.google.com by
wcraven501@gmail.com
on 10 Mar 2015 at 9:38