123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using UnityEngine;
- /// <summary>
- /// Tween the object's Offset.
- /// </summary>
- public class TweenOffset : Tweener
- {
- [System.NonSerialized]
- public Vector3 defaultPosition = Vector3.one * 213.57f;
- public Vector3 offset;
- Transform mTrans;
- public Transform cachedTransform {
- get {
- if (mTrans == null)
- mTrans = transform;
- return mTrans;
- }
- }
- /// <summary>
- /// Tween's current value.
- /// </summary>
- public Vector3 value {
- get {
- return cachedTransform.localPosition;
- }
- set {
- cachedTransform.localPosition = value;
- }
- }
- /// <summary>
- /// Tween the value.
- /// </summary>
- protected override void OnUpdate(float factor, bool isFinished)
- {
- if (defaultPosition == Vector3.one * 213.57f)
- defaultPosition = value;
- Vector3 v3 = value;
- if (offset.x != 0)
- v3.x = defaultPosition.x * (1f - factor) + (defaultPosition.x + offset.x) * factor;
- if (offset.y != 0)
- v3.y = defaultPosition.y * (1f - factor) + (defaultPosition.y + offset.y) * factor;
- if (offset.z != 0)
- v3.z = defaultPosition.z * (1f - factor) + (defaultPosition.z + offset.z) * factor;
- value = v3;
- //value = defaultPosition * (1f - factor) + (defaultPosition + offset) * factor;
- }
- /// <summary>
- /// Start the tweening operation.
- /// </summary>
- static public TweenOffset Begin(GameObject go, float duration, Vector3 offset)
- {
- TweenOffset comp = Tweener.Begin<TweenOffset>(go, duration);
- comp.offset = offset;
- if (duration <= 0f)
- {
- comp.Sample(1f, true);
- comp.enabled = false;
- }
- return comp;
- }
- }
|