【m】1111
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the Image fill.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(Image))]
|
||||
[AddComponentMenu("Tween/Tween Fill")]
|
||||
public class TweenFill : UITweener
|
||||
{
|
||||
[Range(0f, 1f)] public float from = 1f;
|
||||
[Range(0f, 1f)] public float to = 1f;
|
||||
|
||||
bool mCached = false;
|
||||
Image mSprite;
|
||||
|
||||
void Cache ()
|
||||
{
|
||||
mCached = true;
|
||||
mSprite = GetComponent<Image>();
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
Reference in New Issue
Block a user