123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using UnityEngine;
- /// <summary>
- /// Tween the object's position.
- /// </summary>
- [RequireComponent(typeof(RectTransform))]
- public class TweenAnchorMin : Tweener
- {
- public Vector2 from;
- public Vector2 to;
- RectTransform mTrans;
- public RectTransform cachedTransform {
- get {
- if (mTrans == null)
- {
- mTrans = GetComponent<RectTransform>();
- if (mTrans == null)
- mTrans = gameObject.AddComponent<RectTransform>();
- }
- return mTrans;
- }
- }
- /// <summary>
- /// Tween's current value.
- /// </summary>
- public Vector2 value {
- get {
- return cachedTransform.anchorMin;
- }
- set {
- cachedTransform.anchorMin = 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 TweenSize Begin(GameObject go, float duration, Vector2 size)
- {
- TweenSize comp = Tweener.Begin<TweenSize>(go, duration);
- comp.from = comp.value;
- comp.to = size;
- 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;
- }
- }
|