Created
March 7, 2013 13:12
-
-
Save ftvs/5107958 to your computer and use it in GitHub Desktop.
Alpha tween for 2D toolkit sprites. Inherits NGUI's UITweener.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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