【m】
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6bdd27938945f0449bc8fe7947f2bf2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
@@ -0,0 +1,135 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the object's alpha. Works with both UI widgets as well as renderers.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("Tween/Tween Alpha")]
|
||||
public class TweenAlpha : UITweener
|
||||
{
|
||||
[Range(0f, 1f)] public float from = 1f;
|
||||
[Range(0f, 1f)] public float to = 1f;
|
||||
|
||||
[Tooltip("If used on a renderer, the material should probably be cleaned up after this script gets destroyed...")]
|
||||
public bool autoCleanup = false;
|
||||
|
||||
[Tooltip("Color to adjust")]
|
||||
public string colorProperty;
|
||||
|
||||
[System.NonSerialized] bool mCached = false;
|
||||
[System.NonSerialized] CanvasGroup mRect;
|
||||
[System.NonSerialized] Material mShared;
|
||||
[System.NonSerialized] Material mMat;
|
||||
[System.NonSerialized] Light mLight;
|
||||
[System.NonSerialized] SpriteRenderer mSr;
|
||||
[System.NonSerialized] float mBaseIntensity = 1f;
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public float alpha { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
void OnDestroy () { if (autoCleanup && mMat != null && mShared != mMat) { Destroy(mMat); mMat = null; } }
|
||||
|
||||
void Cache ()
|
||||
{
|
||||
mCached = true;
|
||||
mRect = GetComponent<CanvasGroup>();
|
||||
mSr = GetComponent<SpriteRenderer>();
|
||||
|
||||
if (mRect == null && mSr == null)
|
||||
{
|
||||
mLight = GetComponent<Light>();
|
||||
|
||||
if (mLight == null)
|
||||
{
|
||||
var ren = GetComponent<Renderer>();
|
||||
|
||||
if (ren != null)
|
||||
{
|
||||
mShared = ren.sharedMaterial;
|
||||
mMat = ren.material;
|
||||
}
|
||||
|
||||
if (mMat == null) mRect = GetComponentInChildren<CanvasGroup>();
|
||||
}
|
||||
else mBaseIntensity = mLight.intensity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public float value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!mCached) Cache();
|
||||
if (mRect != null) return mRect.alpha;
|
||||
if (mSr != null) return mSr.color.a;
|
||||
if (mMat == null) return 1f;
|
||||
if (string.IsNullOrEmpty(colorProperty)) return mMat.color.a;
|
||||
return mMat.GetColor(colorProperty).a;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!mCached) Cache();
|
||||
|
||||
if (mRect != null)
|
||||
{
|
||||
mRect.alpha = value;
|
||||
}
|
||||
else if (mSr != null)
|
||||
{
|
||||
var c = mSr.color;
|
||||
c.a = value;
|
||||
mSr.color = c;
|
||||
}
|
||||
else if (mMat != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(colorProperty))
|
||||
{
|
||||
var c = mMat.color;
|
||||
c.a = value;
|
||||
mMat.color = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
var c = mMat.GetColor(colorProperty);
|
||||
c.a = value;
|
||||
mMat.SetColor(colorProperty, c);
|
||||
}
|
||||
}
|
||||
else if (mLight != null)
|
||||
{
|
||||
mLight.intensity = mBaseIntensity * 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 TweenAlpha Begin (GameObject go, float duration, float alpha, float delay = 0f)
|
||||
{
|
||||
var comp = UITweener.Begin<TweenAlpha>(go, duration, delay);
|
||||
comp.from = comp.value;
|
||||
comp.to = alpha;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e2747e3775af504da1a4d5a46c5a1ce
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,118 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the object's color.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("Tween/Tween Color")]
|
||||
public class TweenColor : UITweener
|
||||
{
|
||||
public Color from = Color.white;
|
||||
public Color to = Color.white;
|
||||
|
||||
bool mCached = false;
|
||||
Graphic mGraphic;
|
||||
Material mMat;
|
||||
Light mLight;
|
||||
SpriteRenderer mSr;
|
||||
|
||||
void Cache ()
|
||||
{
|
||||
mCached = true;
|
||||
mGraphic = GetComponent<Graphic>();
|
||||
if (mGraphic != null) return;
|
||||
|
||||
mSr = GetComponent<SpriteRenderer>();
|
||||
if (mSr != null) return;
|
||||
|
||||
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
Renderer ren = renderer;
|
||||
#else
|
||||
Renderer ren = GetComponent<Renderer>();
|
||||
#endif
|
||||
if (ren != null)
|
||||
{
|
||||
mMat = ren.material;
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
mLight = light;
|
||||
#else
|
||||
mLight = GetComponent<Light>();
|
||||
#endif
|
||||
if (mLight == null) mGraphic = GetComponentInChildren<Graphic>();
|
||||
}
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public Color color { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public Color value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!mCached) Cache();
|
||||
if (mGraphic != null) return mGraphic.color;
|
||||
if (mMat != null) return mMat.color;
|
||||
if (mSr != null) return mSr.color;
|
||||
if (mLight != null) return mLight.color;
|
||||
return Color.black;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!mCached) Cache();
|
||||
if (mGraphic != null) mGraphic.color = value;
|
||||
else if (mMat != null) mMat.color = value;
|
||||
else if (mSr != null) mSr.color = value;
|
||||
else if (mLight != null)
|
||||
{
|
||||
mLight.color = value;
|
||||
mLight.enabled = (value.r + value.g + value.b) > 0.01f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished) { value = Color.Lerp(from, to, factor); }
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenColor Begin (GameObject go, float duration, Color color)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) return null;
|
||||
#endif
|
||||
TweenColor comp = UITweener.Begin<TweenColor>(go, duration);
|
||||
comp.from = comp.value;
|
||||
comp.to = color;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = from; }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = to; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfa4a4a103e4fed43a7e9e9df4a6915c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the camera's field of view.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(Camera))]
|
||||
[AddComponentMenu("Tween/Tween Field of View")]
|
||||
public class TweenFOV : UITweener
|
||||
{
|
||||
public float from = 45f;
|
||||
public float to = 45f;
|
||||
|
||||
Camera mCam;
|
||||
|
||||
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
public Camera cachedCamera { get { if (mCam == null) mCam = camera; return mCam; } }
|
||||
#else
|
||||
public Camera cachedCamera { get { if (mCam == null) mCam = GetComponent<Camera>(); return mCam; } }
|
||||
#endif
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public float fov { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public float value { get { return cachedCamera.fieldOfView; } set { cachedCamera.fieldOfView = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenFOV Begin (GameObject go, float duration, float to)
|
||||
{
|
||||
TweenFOV comp = UITweener.Begin<TweenFOV>(go, duration);
|
||||
comp.from = comp.value;
|
||||
comp.to = to;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = from; }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = to; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0153adb55685cee4d97c4ee2d52124e5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ba7f59a1f412544f85ac3e66f0b5227
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the widget's size.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[AddComponentMenu("Tween/Tween Height")]
|
||||
public class TweenHeight : UITweener
|
||||
{
|
||||
public float from = 100;
|
||||
public float to = 100;
|
||||
|
||||
[Tooltip("If set, 'from' value will be set to match the specified rectangle")]
|
||||
public RectTransform fromTarget;
|
||||
|
||||
[Tooltip("If set, 'to' value will be set to match the specified rectangle")]
|
||||
public RectTransform toTarget;
|
||||
|
||||
RectTransform mWidget;
|
||||
|
||||
public RectTransform cachedWidget { get { if (mWidget == null) mWidget = GetComponent<RectTransform>(); return mWidget; } }
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public float height { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public float value { get { return cachedWidget.rect.height; } set { cachedWidget.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished)
|
||||
{
|
||||
if (fromTarget) from = fromTarget.rect.width;
|
||||
if (toTarget) to = toTarget.rect.width;
|
||||
|
||||
value = Mathf.RoundToInt(from * (1f - factor) + to * factor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenHeight Begin (RectTransform widget, float duration, int height)
|
||||
{
|
||||
TweenHeight comp = UITweener.Begin<TweenHeight>(widget.gameObject, duration);
|
||||
comp.from = widget.rect.height;
|
||||
comp.to = height;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = from; }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = to; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66a6ab21c5f860946ade65b47cc0270b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -92
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the camera's orthographic size.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(Camera))]
|
||||
[AddComponentMenu("Tween/Tween Orthographic Size")]
|
||||
public class TweenOrthoSize : UITweener
|
||||
{
|
||||
public float from = 1f;
|
||||
public float to = 1f;
|
||||
|
||||
Camera mCam;
|
||||
|
||||
/// <summary>
|
||||
/// Camera that's being tweened.
|
||||
/// </summary>
|
||||
|
||||
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
|
||||
public Camera cachedCamera { get { if (mCam == null) mCam = camera; return mCam; } }
|
||||
#else
|
||||
public Camera cachedCamera { get { if (mCam == null) mCam = GetComponent<Camera>(); return mCam; } }
|
||||
#endif
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public float orthoSize { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public float value
|
||||
{
|
||||
get { return cachedCamera.orthographicSize; }
|
||||
set { cachedCamera.orthographicSize = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenOrthoSize Begin (GameObject go, float duration, float to)
|
||||
{
|
||||
TweenOrthoSize comp = UITweener.Begin<TweenOrthoSize>(go, duration);
|
||||
comp.from = comp.value;
|
||||
comp.to = to;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 365827806a6dd8b4583deeefe6e483c9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,94 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the object's position.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("Tween/Tween Position")]
|
||||
public class TweenPosition : UITweener
|
||||
{
|
||||
public Vector3 from;
|
||||
public Vector3 to;
|
||||
|
||||
[HideInInspector]
|
||||
public bool worldSpace = false;
|
||||
|
||||
Transform mTrans;
|
||||
|
||||
public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public Vector3 position { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public Vector3 value
|
||||
{
|
||||
get
|
||||
{
|
||||
return worldSpace ? cachedTransform.position : cachedTransform.localPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (worldSpace) cachedTransform.position = value;
|
||||
else cachedTransform.localPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenPosition Begin (GameObject go, float duration, Vector3 pos)
|
||||
{
|
||||
TweenPosition comp = UITweener.Begin<TweenPosition>(go, duration);
|
||||
comp.from = comp.value;
|
||||
comp.to = pos;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenPosition Begin (GameObject go, float duration, Vector3 pos, bool worldSpace)
|
||||
{
|
||||
TweenPosition comp = UITweener.Begin<TweenPosition>(go, duration);
|
||||
comp.worldSpace = worldSpace;
|
||||
comp.from = comp.value;
|
||||
comp.to = pos;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = from; }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = to; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d166255cacf07b4292b8402b3ddefc5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -98
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the object's rotation.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("Tween/Tween Rotation")]
|
||||
public class TweenRotation : UITweener
|
||||
{
|
||||
public Vector3 from;
|
||||
public Vector3 to;
|
||||
public bool quaternionLerp = false;
|
||||
|
||||
Transform mTrans;
|
||||
|
||||
public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public Quaternion rotation { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public Quaternion value { get { return cachedTransform.localRotation; } set { cachedTransform.localRotation = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished)
|
||||
{
|
||||
value = quaternionLerp ? Quaternion.Slerp(Quaternion.Euler(from), Quaternion.Euler(to), factor) :
|
||||
Quaternion.Euler(new Vector3(
|
||||
Mathf.Lerp(from.x, to.x, factor),
|
||||
Mathf.Lerp(from.y, to.y, factor),
|
||||
Mathf.Lerp(from.z, to.z, factor)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenRotation Begin (GameObject go, float duration, Quaternion rot)
|
||||
{
|
||||
TweenRotation comp = UITweener.Begin<TweenRotation>(go, duration);
|
||||
comp.from = comp.value.eulerAngles;
|
||||
comp.to = rot.eulerAngles;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value.eulerAngles; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value.eulerAngles; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = Quaternion.Euler(from); }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = Quaternion.Euler(to); }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04d1b7c9e9a19a24ab67123a43c6544b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -95
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the object's local scale.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("Tween/Tween Scale")]
|
||||
public class TweenScale : UITweener
|
||||
{
|
||||
public Vector3 from = Vector3.one;
|
||||
public Vector3 to = Vector3.one;
|
||||
|
||||
Transform mTrans;
|
||||
|
||||
public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
|
||||
|
||||
public Vector3 value { get { return cachedTransform.localScale; } set { cachedTransform.localScale = value; } }
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public Vector3 scale { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished)
|
||||
{
|
||||
value = from * (1f - factor) + to * factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenScale Begin (GameObject go, float duration, Vector3 scale)
|
||||
{
|
||||
TweenScale comp = UITweener.Begin<TweenScale>(go, duration);
|
||||
comp.from = comp.value;
|
||||
comp.to = scale;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = from; }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = to; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75e7459110b9666449485c40f25362a5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -94
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,76 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the object's position, rotation and scale.
|
||||
/// </summary>
|
||||
|
||||
[AddComponentMenu("Tween/Tween Transform")]
|
||||
public class TweenTransform : UITweener
|
||||
{
|
||||
public Transform from;
|
||||
public Transform to;
|
||||
public bool parentWhenFinished = false;
|
||||
|
||||
Transform mTrans;
|
||||
Vector3 mPos;
|
||||
Quaternion mRot;
|
||||
Vector3 mScale;
|
||||
|
||||
/// <summary>
|
||||
/// Interpolate the position, scale, and rotation.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished)
|
||||
{
|
||||
if (to != null)
|
||||
{
|
||||
if (mTrans == null)
|
||||
{
|
||||
mTrans = transform;
|
||||
mPos = mTrans.position;
|
||||
mRot = mTrans.rotation;
|
||||
mScale = mTrans.localScale;
|
||||
}
|
||||
|
||||
if (from != null)
|
||||
{
|
||||
mTrans.position = from.position * (1f - factor) + to.position * factor;
|
||||
mTrans.localScale = from.localScale * (1f - factor) + to.localScale * factor;
|
||||
mTrans.rotation = Quaternion.Slerp(from.rotation, to.rotation, factor);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTrans.position = mPos * (1f - factor) + to.position * factor;
|
||||
mTrans.localScale = mScale * (1f - factor) + to.localScale * factor;
|
||||
mTrans.rotation = Quaternion.Slerp(mRot, to.rotation, factor);
|
||||
}
|
||||
|
||||
// Change the parent when finished, if requested
|
||||
if (parentWhenFinished && isFinished) mTrans.parent = to;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation from the current position/rotation/scale to the target transform.
|
||||
/// </summary>
|
||||
|
||||
static public TweenTransform Begin (GameObject go, float duration, Transform to) { return Begin(go, duration, null, to); }
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenTransform Begin (GameObject go, float duration, Transform from, Transform to)
|
||||
{
|
||||
TweenTransform comp = UITweener.Begin<TweenTransform>(go, duration);
|
||||
comp.from = from;
|
||||
comp.to = to;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d805c79a1ab11643bfd9d91e10c195a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,89 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the audio source's volume.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
[AddComponentMenu("Tween/Tween Volume")]
|
||||
public class TweenVolume : UITweener
|
||||
{
|
||||
[Range(0f, 1f)] public float from = 1f;
|
||||
[Range(0f, 1f)] public float to = 1f;
|
||||
|
||||
AudioSource mSource;
|
||||
|
||||
/// <summary>
|
||||
/// Cached version of 'audio', as it's always faster to cache.
|
||||
/// </summary>
|
||||
|
||||
public AudioSource audioSource
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mSource == null)
|
||||
{
|
||||
mSource = GetComponent<AudioSource>();
|
||||
|
||||
if (mSource == null)
|
||||
{
|
||||
mSource = GetComponent<AudioSource>();
|
||||
|
||||
if (mSource == null)
|
||||
{
|
||||
Debug.LogError("TweenVolume needs an AudioSource to work with", this);
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mSource;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public float volume { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Audio source's current volume.
|
||||
/// </summary>
|
||||
|
||||
public float value
|
||||
{
|
||||
get
|
||||
{
|
||||
return audioSource != null ? mSource.volume : 0f;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (audioSource != null) mSource.volume = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished)
|
||||
{
|
||||
value = from * (1f - factor) + to * factor;
|
||||
mSource.enabled = (mSource.volume > 0.01f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenVolume Begin (GameObject go, float duration, float targetVolume)
|
||||
{
|
||||
TweenVolume comp = UITweener.Begin<TweenVolume>(go, duration);
|
||||
comp.from = comp.value;
|
||||
comp.to = targetVolume;
|
||||
|
||||
if (targetVolume > 0f)
|
||||
{
|
||||
var s = comp.audioSource;
|
||||
s.enabled = true;
|
||||
s.Play();
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17aeef7ce6c142344959e650cab20151
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Tween the widget's size.
|
||||
/// </summary>
|
||||
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[AddComponentMenu("Tween/Tween Width")]
|
||||
public class TweenWidth : UITweener
|
||||
{
|
||||
public float from = 100;
|
||||
public float to = 100;
|
||||
|
||||
[Tooltip("If set, 'from' value will be set to match the specified rectangle")]
|
||||
public RectTransform fromTarget;
|
||||
|
||||
[Tooltip("If set, 'to' value will be set to match the specified rectangle")]
|
||||
public RectTransform toTarget;
|
||||
|
||||
RectTransform mWidget;
|
||||
RectTransform mTable;
|
||||
|
||||
public RectTransform cachedWidget { get { if (mWidget == null) mWidget = GetComponent<RectTransform>(); return mWidget; } }
|
||||
|
||||
[System.Obsolete("Use 'value' instead")]
|
||||
public float width { get { return this.value; } set { this.value = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween's current value.
|
||||
/// </summary>
|
||||
|
||||
public float value { get { return cachedWidget.rect.width; } set { cachedWidget.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Tween the value.
|
||||
/// </summary>
|
||||
|
||||
protected override void OnUpdate (float factor, bool isFinished)
|
||||
{
|
||||
if (fromTarget) from = fromTarget.rect.width;
|
||||
if (toTarget) to = toTarget.rect.width;
|
||||
|
||||
value = Mathf.RoundToInt(from * (1f - factor) + to * factor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public TweenWidth Begin (RectTransform widget, float duration, int width)
|
||||
{
|
||||
var comp = UITweener.Begin<TweenWidth>(widget.gameObject, duration);
|
||||
comp.from = widget.rect.width;
|
||||
comp.to = width;
|
||||
|
||||
if (duration <= 0f)
|
||||
{
|
||||
comp.Sample(1f, true);
|
||||
comp.enabled = false;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
[ContextMenu("Set 'From' to current value")]
|
||||
public override void SetStartToCurrentValue () { from = value; }
|
||||
|
||||
[ContextMenu("Set 'To' to current value")]
|
||||
public override void SetEndToCurrentValue () { to = value; }
|
||||
|
||||
[ContextMenu("Assume value of 'From'")]
|
||||
void SetCurrentValueToStart () { value = from; }
|
||||
|
||||
[ContextMenu("Assume value of 'To'")]
|
||||
void SetCurrentValueToEnd () { value = to; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fe5d396737f89f4ea1534bc147cad2e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -93
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,531 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all tweening operations.
|
||||
/// </summary>
|
||||
|
||||
public abstract class UITweener : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Current tween that triggered the callback function.
|
||||
/// </summary>
|
||||
|
||||
static public UITweener current;
|
||||
|
||||
public enum Method
|
||||
{
|
||||
Linear,
|
||||
EaseIn,
|
||||
EaseOut,
|
||||
EaseInOut,
|
||||
BounceIn,
|
||||
BounceOut,
|
||||
}
|
||||
|
||||
public enum Style
|
||||
{
|
||||
Once,
|
||||
Loop,
|
||||
PingPong,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tweening method used.
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public Method method = Method.Linear;
|
||||
|
||||
/// <summary>
|
||||
/// Does it play once? Does it loop?
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public Style style = Style.Once;
|
||||
|
||||
/// <summary>
|
||||
/// Optional curve to apply to the tween's time factor value.
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
/// <summary>
|
||||
/// Whether the tween will ignore the timescale, making it work while the game is paused.
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public bool ignoreTimeScale = true;
|
||||
|
||||
/// <summary>
|
||||
/// How long will the tweener wait before starting the tween?
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public float delay = 0f;
|
||||
|
||||
public enum DelayAffects
|
||||
{
|
||||
Forward,
|
||||
Reverse,
|
||||
Both,
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public DelayAffects delayAffects = DelayAffects.Both;
|
||||
|
||||
/// <summary>
|
||||
/// How long is the duration of the tween?
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public float duration = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the tweener will use steeper curves for ease in / out style interpolation.
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public bool steeperCurves = false;
|
||||
|
||||
/// <summary>
|
||||
/// Used by buttons and tween sequences. Group of '0' means not in a sequence.
|
||||
/// </summary>
|
||||
|
||||
[HideInInspector]
|
||||
public int tweenGroup = 0;
|
||||
|
||||
[Tooltip("By default, Update() will be used for tweening. Setting this to 'true' will make the tween happen in FixedUpdate() insted.")]
|
||||
public bool useFixedUpdate = false;
|
||||
|
||||
/// <summary>
|
||||
/// Event delegates called when the animation finishes.
|
||||
/// </summary>
|
||||
|
||||
//[HideInInspector]
|
||||
//public List<EventDelegate> onFinished = new List<EventDelegate>();
|
||||
|
||||
// Deprecated functionality, kept for backwards compatibility
|
||||
[HideInInspector] public GameObject eventReceiver;
|
||||
[HideInInspector] public string callWhenFinished;
|
||||
|
||||
/// <summary>
|
||||
/// Custom time scale for this tween, if desired. Can be used to slow down or speed up the animation.
|
||||
/// </summary>
|
||||
|
||||
[System.NonSerialized] public float timeScale = 1f;
|
||||
|
||||
bool mStarted = false;
|
||||
float mStartTime = 0f;
|
||||
float mDuration = 0f;
|
||||
float mAmountPerDelta = 1000f;
|
||||
float mFactor = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Amount advanced per delta time.
|
||||
/// </summary>
|
||||
|
||||
public float amountPerDelta
|
||||
{
|
||||
get
|
||||
{
|
||||
if (duration == 0f) return 1000f;
|
||||
|
||||
if (mDuration != duration)
|
||||
{
|
||||
mDuration = duration;
|
||||
mAmountPerDelta = Mathf.Abs(1f / duration) * Mathf.Sign(mAmountPerDelta);
|
||||
}
|
||||
return mAmountPerDelta;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tween factor, 0-1 range.
|
||||
/// </summary>
|
||||
|
||||
public float tweenFactor { get { return mFactor; } set { mFactor = Mathf.Clamp01(value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Direction that the tween is currently playing in.
|
||||
/// </summary>
|
||||
|
||||
//public AnimationOrTween.Direction direction { get { return amountPerDelta < 0f ? AnimationOrTween.Direction.Reverse : AnimationOrTween.Direction.Forward; } }
|
||||
|
||||
/// <summary>
|
||||
/// This function is called by Unity when you add a component. Automatically set the starting values for convenience.
|
||||
/// </summary>
|
||||
|
||||
void Reset ()
|
||||
{
|
||||
if (!mStarted)
|
||||
{
|
||||
SetStartToCurrentValue();
|
||||
SetEndToCurrentValue();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update as soon as it's started so that there is no delay.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void Start () { DoUpdate(); }
|
||||
protected void Update () { if (!useFixedUpdate) DoUpdate(); }
|
||||
protected void FixedUpdate () { if (useFixedUpdate) DoUpdate(); }
|
||||
|
||||
/// <summary>
|
||||
/// Update the tweening factor and call the virtual update function.
|
||||
/// </summary>
|
||||
|
||||
protected void DoUpdate ()
|
||||
{
|
||||
float delta = ignoreTimeScale && !useFixedUpdate ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
float time = ignoreTimeScale && !useFixedUpdate ? Time.unscaledTime : Time.time;
|
||||
|
||||
if (!mStarted)
|
||||
{
|
||||
delta = 0;
|
||||
mStarted = true;
|
||||
mStartTime = time;
|
||||
if (mAmountPerDelta > 0f && (delayAffects == DelayAffects.Both || delayAffects == DelayAffects.Forward)) mStartTime += delay;
|
||||
else if (mAmountPerDelta < 0f && (delayAffects == DelayAffects.Both || delayAffects == DelayAffects.Reverse)) mStartTime += delay;
|
||||
}
|
||||
|
||||
if (time < mStartTime) return;
|
||||
|
||||
// Advance the sampling factor
|
||||
mFactor += (duration == 0f) ? 1f : amountPerDelta * delta * timeScale;
|
||||
|
||||
// Loop style simply resets the play factor after it exceeds 1.
|
||||
if (style == Style.Loop)
|
||||
{
|
||||
if (mFactor > 1f)
|
||||
{
|
||||
mFactor -= Mathf.Floor(mFactor);
|
||||
}
|
||||
}
|
||||
else if (style == Style.PingPong)
|
||||
{
|
||||
// Ping-pong style reverses the direction
|
||||
if (mFactor > 1f)
|
||||
{
|
||||
mFactor = 1f - (mFactor - Mathf.Floor(mFactor));
|
||||
mAmountPerDelta = -mAmountPerDelta;
|
||||
}
|
||||
else if (mFactor < 0f)
|
||||
{
|
||||
mFactor = -mFactor;
|
||||
mFactor -= Mathf.Floor(mFactor);
|
||||
mAmountPerDelta = -mAmountPerDelta;
|
||||
}
|
||||
}
|
||||
|
||||
// If the factor goes out of range and this is a one-time tweening operation, disable the script
|
||||
if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
|
||||
{
|
||||
mFactor = Mathf.Clamp01(mFactor);
|
||||
Sample(mFactor, true);
|
||||
enabled = false;
|
||||
|
||||
if (current != this)
|
||||
{
|
||||
UITweener before = current;
|
||||
current = this;
|
||||
|
||||
//if (onFinished != null)
|
||||
//{
|
||||
// mTemp = onFinished;
|
||||
// onFinished = new List<EventDelegate>();
|
||||
|
||||
// // Notify the listener delegates
|
||||
// EventDelegate.Execute(mTemp);
|
||||
|
||||
// // Re-add the previous persistent delegates
|
||||
// for (int i = 0; i < mTemp.Count; ++i)
|
||||
// {
|
||||
// EventDelegate ed = mTemp[i];
|
||||
// if (ed != null && !ed.oneShot) EventDelegate.Add(onFinished, ed, ed.oneShot);
|
||||
// }
|
||||
// mTemp = null;
|
||||
//}
|
||||
|
||||
// Deprecated legacy functionality support
|
||||
if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
|
||||
eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
|
||||
|
||||
current = before;
|
||||
}
|
||||
}
|
||||
else Sample(mFactor, false);
|
||||
}
|
||||
|
||||
//List<EventDelegate> mTemp = null;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
|
||||
/// </summary>
|
||||
|
||||
//public void SetOnFinished (EventDelegate.Callback del) { EventDelegate.Set(onFinished, del); }
|
||||
|
||||
///// <summary>
|
||||
///// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
|
||||
///// </summary>
|
||||
|
||||
//public void SetOnFinished (EventDelegate del) { EventDelegate.Set(onFinished, del); }
|
||||
|
||||
///// <summary>
|
||||
///// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
|
||||
///// </summary>
|
||||
|
||||
//public void AddOnFinished (EventDelegate.Callback del) { EventDelegate.Add(onFinished, del); }
|
||||
|
||||
///// <summary>
|
||||
///// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
|
||||
///// </summary>
|
||||
|
||||
//public void AddOnFinished (EventDelegate del) { EventDelegate.Add(onFinished, del); }
|
||||
|
||||
///// <summary>
|
||||
///// Remove an OnFinished delegate. Will work even while iterating through the list when the tweener has finished its operation.
|
||||
///// </summary>
|
||||
|
||||
//public void RemoveOnFinished (EventDelegate del)
|
||||
//{
|
||||
// if (onFinished != null) onFinished.Remove(del);
|
||||
// if (mTemp != null) mTemp.Remove(del);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Mark as not started when finished to enable delay on next play.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void OnDisable () { mStarted = false; }
|
||||
|
||||
/// <summary>
|
||||
/// Immediately finish the tween animation, if it's active.
|
||||
/// </summary>
|
||||
|
||||
public void Finish ()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
Sample(mAmountPerDelta > 0f ? 1f : 0f, true);
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sample the tween at the specified factor.
|
||||
/// </summary>
|
||||
|
||||
public void Sample (float factor, bool isFinished)
|
||||
{
|
||||
// Calculate the sampling value
|
||||
float val = Mathf.Clamp01(factor);
|
||||
|
||||
if (method == Method.EaseIn)
|
||||
{
|
||||
val = 1f - Mathf.Sin(0.5f * Mathf.PI * (1f - val));
|
||||
if (steeperCurves) val *= val;
|
||||
}
|
||||
else if (method == Method.EaseOut)
|
||||
{
|
||||
val = Mathf.Sin(0.5f * Mathf.PI * val);
|
||||
|
||||
if (steeperCurves)
|
||||
{
|
||||
val = 1f - val;
|
||||
val = 1f - val * val;
|
||||
}
|
||||
}
|
||||
else if (method == Method.EaseInOut)
|
||||
{
|
||||
const float pi2 = Mathf.PI * 2f;
|
||||
val = val - Mathf.Sin(val * pi2) / pi2;
|
||||
|
||||
if (steeperCurves)
|
||||
{
|
||||
val = val * 2f - 1f;
|
||||
float sign = Mathf.Sign(val);
|
||||
val = 1f - Mathf.Abs(val);
|
||||
val = 1f - val * val;
|
||||
val = sign * val * 0.5f + 0.5f;
|
||||
}
|
||||
}
|
||||
else if (method == Method.BounceIn)
|
||||
{
|
||||
val = BounceLogic(val);
|
||||
}
|
||||
else if (method == Method.BounceOut)
|
||||
{
|
||||
val = 1f - BounceLogic(1f - val);
|
||||
}
|
||||
|
||||
// Call the virtual update
|
||||
OnUpdate((animationCurve != null) ? animationCurve.Evaluate(val) : val, isFinished);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main Bounce logic to simplify the Sample function
|
||||
/// </summary>
|
||||
|
||||
float BounceLogic (float val)
|
||||
{
|
||||
if (val < 0.363636f) // 0.363636 = (1/ 2.75)
|
||||
{
|
||||
val = 7.5685f * val * val;
|
||||
}
|
||||
else if (val < 0.727272f) // 0.727272 = (2 / 2.75)
|
||||
{
|
||||
val = 7.5625f * (val -= 0.545454f) * val + 0.75f; // 0.545454f = (1.5 / 2.75)
|
||||
}
|
||||
else if (val < 0.909090f) // 0.909090 = (2.5 / 2.75)
|
||||
{
|
||||
val = 7.5625f * (val -= 0.818181f) * val + 0.9375f; // 0.818181 = (2.25 / 2.75)
|
||||
}
|
||||
else
|
||||
{
|
||||
val = 7.5625f * (val -= 0.9545454f) * val + 0.984375f; // 0.9545454 = (2.625 / 2.75)
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play the tween.
|
||||
/// </summary>
|
||||
|
||||
[System.Obsolete("Use PlayForward() instead")]
|
||||
public void Play () { Play(true); }
|
||||
|
||||
/// <summary>
|
||||
/// Play the tween forward.
|
||||
/// </summary>
|
||||
|
||||
[ContextMenu("Play forward")]
|
||||
public void PlayForward () { Play(true); }
|
||||
|
||||
/// <summary>
|
||||
/// Play the tween in reverse.
|
||||
/// </summary>
|
||||
|
||||
[ContextMenu("Play in reverse")]
|
||||
public void PlayReverse () { Play(false); }
|
||||
|
||||
/// <summary>
|
||||
/// Manually activate the tweening process, reversing it if necessary.
|
||||
/// </summary>
|
||||
|
||||
public virtual void Play (bool forward)
|
||||
{
|
||||
mAmountPerDelta = Mathf.Abs(amountPerDelta);
|
||||
if (!forward) mAmountPerDelta = -mAmountPerDelta;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
enabled = true;
|
||||
mStarted = false;
|
||||
}
|
||||
|
||||
DoUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually reset the tweener's state to the beginning.
|
||||
/// If the tween is playing forward, this means the tween's start.
|
||||
/// If the tween is playing in reverse, this means the tween's end.
|
||||
/// </summary>
|
||||
|
||||
public void ResetToBeginning ()
|
||||
{
|
||||
mStarted = false;
|
||||
mFactor = (amountPerDelta < 0f) ? 1f : 0f;
|
||||
Sample(mFactor, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually start the tweening process, reversing its direction.
|
||||
/// </summary>
|
||||
|
||||
public void Toggle ()
|
||||
{
|
||||
if (mFactor > 0f)
|
||||
{
|
||||
mAmountPerDelta = -amountPerDelta;
|
||||
}
|
||||
else
|
||||
{
|
||||
mAmountPerDelta = Mathf.Abs(amountPerDelta);
|
||||
}
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actual tweening logic should go here.
|
||||
/// </summary>
|
||||
|
||||
abstract protected void OnUpdate (float factor, bool isFinished);
|
||||
|
||||
/// <summary>
|
||||
/// Starts the tweening operation.
|
||||
/// </summary>
|
||||
|
||||
static public T Begin<T> (GameObject go, float duration, float delay = 0f) where T : UITweener
|
||||
{
|
||||
T comp = go.GetComponent<T>();
|
||||
#if UNITY_FLASH
|
||||
if ((object)comp == null) comp = (T)go.AddComponent<T>();
|
||||
#else
|
||||
// Find the tween with an unset group ID (group ID of 0).
|
||||
if (comp != null && comp.tweenGroup != 0)
|
||||
{
|
||||
comp = null;
|
||||
T[] comps = go.GetComponents<T>();
|
||||
for (int i = 0, imax = comps.Length; i < imax; ++i)
|
||||
{
|
||||
comp = comps[i];
|
||||
if (comp != null && comp.tweenGroup == 0) break;
|
||||
comp = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (comp == null)
|
||||
{
|
||||
comp = go.AddComponent<T>();
|
||||
|
||||
if (comp == null)
|
||||
{
|
||||
//Debug.LogError("Unable to add " + typeof(T) + " to " + NGUITools.GetHierarchy(go), go);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
comp.mStarted = false;
|
||||
comp.mFactor = 0f;
|
||||
comp.duration = duration;
|
||||
comp.mDuration = duration;
|
||||
comp.delay = delay;
|
||||
comp.mAmountPerDelta = duration > 0f ? Mathf.Abs(1f / duration) : 1000f;
|
||||
comp.style = Style.Once;
|
||||
comp.animationCurve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
comp.eventReceiver = null;
|
||||
comp.callWhenFinished = null;
|
||||
//comp.onFinished.Clear();
|
||||
//if (comp.mTemp != null) comp.mTemp.Clear();
|
||||
comp.enabled = true;
|
||||
return comp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the 'from' value to the current one.
|
||||
/// </summary>
|
||||
|
||||
public virtual void SetStartToCurrentValue () { }
|
||||
|
||||
/// <summary>
|
||||
/// Set the 'to' value to the current one.
|
||||
/// </summary>
|
||||
|
||||
public virtual void SetEndToCurrentValue () { }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c96860f5597f2494abb42d29cdca0bcc
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
Reference in New Issue
Block a user