Project_WL/Assets/ThirdParty/NGUI/Scripts/Tweening/TweenFill.cs

74 lines
1.5 KiB
C#

//-------------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2019 Tasharen Entertainment Inc
//-------------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the sprite's fill.
/// </summary>
[RequireComponent(typeof(UIBasicSprite))]
[AddComponentMenu("NGUI/Tween/Tween Fill")]
public class TweenFill : UITweener
{
[Range(0f, 1f)] public float from = 1f;
[Range(0f, 1f)] public float to = 1f;
bool mCached = false;
UIBasicSprite mSprite;
void Cache ()
{
mCached = true;
mSprite = GetComponent<UISprite>();
}
/// <summary>
/// Tween's current value.
/// </summary>
public float value
{
get
{
if (!mCached) Cache();
if (mSprite != null) return mSprite.fillAmount;
return 0f;
}
set
{
if (!mCached) Cache();
if (mSprite != null) mSprite.fillAmount = value;
}
}
/// <summary>
/// Tween the value.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished) { value = Mathf.Lerp(from, to, factor); }
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenFill Begin (GameObject go, float duration, float fill)
{
TweenFill comp = UITweener.Begin<TweenFill>(go, duration);
comp.from = comp.value;
comp.to = fill;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
public override void SetStartToCurrentValue () { from = value; }
public override void SetEndToCurrentValue () { to = value; }
}