123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Tween/Tween Color")]
- public class TweenColor : UITweener
- {
- private void Cache()
- {
- this.mCached = true;
- this.mWidget = base.GetComponent<UIWidget>();
- if (this.mWidget != null)
- {
- return;
- }
- this.mSr = base.GetComponent<SpriteRenderer>();
- if (this.mSr != null)
- {
- return;
- }
- Renderer component = base.GetComponent<Renderer>();
- if (component != null)
- {
- this.mMat = component.material;
- return;
- }
- this.mLight = base.GetComponent<Light>();
- if (this.mLight == null)
- {
- this.mWidget = base.GetComponentInChildren<UIWidget>();
- }
- }
- [Obsolete("Use 'value' instead")]
- public Color color
- {
- get
- {
- return this.value;
- }
- set
- {
- this.value = value;
- }
- }
- public Color value
- {
- get
- {
- if (!this.mCached)
- {
- this.Cache();
- }
- if (this.mWidget != null)
- {
- return this.mWidget.color;
- }
- if (this.mMat != null)
- {
- return this.mMat.color;
- }
- if (this.mSr != null)
- {
- return this.mSr.color;
- }
- if (this.mLight != null)
- {
- return this.mLight.color;
- }
- return Color.black;
- }
- set
- {
- if (!this.mCached)
- {
- this.Cache();
- }
- if (this.mWidget != null)
- {
- this.mWidget.color = value;
- }
- else if (this.mMat != null)
- {
- this.mMat.color = value;
- }
- else if (this.mSr != null)
- {
- this.mSr.color = value;
- }
- else if (this.mLight != null)
- {
- this.mLight.color = value;
- this.mLight.enabled = (value.r + value.g + value.b > 0.01f);
- }
- }
- }
- protected override void OnUpdate(float factor, bool isFinished)
- {
- this.value = Color.Lerp(this.from, this.to, factor);
- }
- public static TweenColor Begin(GameObject go, float duration, Color color)
- {
- TweenColor tweenColor = UITweener.Begin<TweenColor>(go, duration);
- tweenColor.from = tweenColor.value;
- tweenColor.to = color;
- if (duration <= 0f)
- {
- tweenColor.Sample(1f, true);
- tweenColor.enabled = false;
- }
- return tweenColor;
- }
- [ContextMenu("Set 'From' to current value")]
- public override void SetStartToCurrentValue()
- {
- this.from = this.value;
- }
- [ContextMenu("Set 'To' to current value")]
- public override void SetEndToCurrentValue()
- {
- this.to = this.value;
- }
- [ContextMenu("Assume value of 'From'")]
- private void SetCurrentValueToStart()
- {
- this.value = this.from;
- }
- [ContextMenu("Assume value of 'To'")]
- private void SetCurrentValueToEnd()
- {
- this.value = this.to;
- }
- public Color from = Color.white;
- public Color to = Color.white;
- private bool mCached;
- private UIWidget mWidget;
- private Material mMat;
- private Light mLight;
- private SpriteRenderer mSr;
- }
|