123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Tween/Tween Alpha")]
- public class TweenAlpha : UITweener
- {
- [Obsolete("Use 'value' instead")]
- public float alpha
- {
- get
- {
- return this.value;
- }
- set
- {
- this.value = value;
- }
- }
- private void Cache()
- {
- this.mCached = true;
- this.mRect = base.GetComponent<UIRect>();
- this.mSr = base.GetComponent<SpriteRenderer>();
- if (this.mRect == null && this.mSr == null)
- {
- Renderer component = base.GetComponent<Renderer>();
- if (component != null)
- {
- this.mMat = component.material;
- }
- if (this.mMat == null)
- {
- this.mRect = base.GetComponentInChildren<UIRect>();
- }
- }
- }
- public float value
- {
- get
- {
- if (!this.mCached)
- {
- this.Cache();
- }
- if (this.mRect != null)
- {
- return this.mRect.alpha;
- }
- if (this.mSr != null)
- {
- return this.mSr.color.a;
- }
- return (!(this.mMat != null)) ? 1f : this.mMat.color.a;
- }
- set
- {
- if (!this.mCached)
- {
- this.Cache();
- }
- if (this.mRect != null)
- {
- this.mRect.alpha = value;
- }
- else if (this.mSr != null)
- {
- Color color = this.mSr.color;
- color.a = value;
- this.mSr.color = color;
- }
- else if (this.mMat != null)
- {
- Color color2 = this.mMat.color;
- color2.a = value;
- this.mMat.color = color2;
- }
- }
- }
- protected override void OnUpdate(float factor, bool isFinished)
- {
- this.value = Mathf.Lerp(this.from, this.to, factor);
- }
- public static TweenAlpha Begin(GameObject go, float duration, float alpha)
- {
- TweenAlpha tweenAlpha = UITweener.Begin<TweenAlpha>(go, duration);
- tweenAlpha.from = tweenAlpha.value;
- tweenAlpha.to = alpha;
- if (duration <= 0f)
- {
- tweenAlpha.Sample(1f, true);
- tweenAlpha.enabled = false;
- }
- return tweenAlpha;
- }
- public override void SetStartToCurrentValue()
- {
- this.from = this.value;
- }
- public override void SetEndToCurrentValue()
- {
- this.to = this.value;
- }
- [Range(0f, 1f)]
- public float from = 1f;
- [Range(0f, 1f)]
- public float to = 1f;
- private bool mCached;
- private UIRect mRect;
- private Material mMat;
- private SpriteRenderer mSr;
- }
|