1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using UnityEngine;
- /// <summary>
- /// Tween the object's local size.
- /// </summary>
- public class TweenScale : Tweener
- {
- public Vector3 from = Vector3.one;
- public Vector3 to = Vector3.one;
- Transform mTrans;
- public bool resetOnEnable = false;
- public Transform cachedTransform {
- get {
- if (mTrans == null)
- mTrans = transform;
- return mTrans;
- }
- }
- public Vector3 value {
- get {
- return cachedTransform.localScale;
- }
- set {
- cachedTransform.localScale = value;
- }
- }
- void OnEnable()
- {
- if (resetOnEnable)
- {
- tweenFactor = 0;
- Sample(0, false);
- }
- }
- /// <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 = Tweener.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;
- }
- }
|