Skip to content

Instantly share code, notes, and snippets.

@ftvs
Created March 7, 2013 13:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftvs/5107958 to your computer and use it in GitHub Desktop.
Save ftvs/5107958 to your computer and use it in GitHub Desktop.
Alpha tween for 2D toolkit sprites. Inherits NGUI's UITweener.
// Alpha tween for 2D toolkit sprites. Uses same method signatures as NGUI's
// TweenAlpha.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(tk2dBaseSprite))]
public class tk2dTweenAlpha : UITweener
{
public float from = 0f;
public float to = 1f;
tk2dBaseSprite _sprite;
tk2dBaseSprite Sprite
{
get
{
if (_sprite == null)
{
_sprite = GetComponent<tk2dBaseSprite>();
}
return _sprite;
}
}
float alpha
{
get { return Sprite.color.a; }
set { Sprite.color = new Color(Sprite.color.r, Sprite.color.g, Sprite.color.b, value); }
}
protected override void OnUpdate(float factor, bool isFinished)
{
alpha = Mathf.Lerp(from, to, factor);
}
public static tk2dTweenAlpha Begin (GameObject go, float duration, float alpha)
{
tk2dTweenAlpha comp = UITweener.Begin<tk2dTweenAlpha>(go, duration);
comp.from = comp.alpha;
comp.to = alpha;
return comp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment