NGUI中我们要同时完成Scale与Transform的效果,会发现动画并不是同我们想的那样运行的。
原因就是Tween Scale与Tween Transform的冲突调用。
Tween Scale中
用来设置localScale
Tween Transform中
也用来设置localScale。
这就产生冲突了。。。这里最简单的方法就是把两个脚本合并一下删掉Tween Transform中的localScale,因为还是得用Tween Scale来控制Scale。
using UnityEngine; using System.Collections; public class TweenScaleTransform : UITweener { public Vector3 from = Vector3.one; public Vector3 to = Vector3.one; public bool updateTable = false; public Transform fromt; public Transform tot; public bool parentWhenFinished = false; Transform mTrans; Vector3 mPos; Quaternion mRot; Vector3 mScale; UITable mTable; 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; if (updateTable) { if (mTable == null) { mTable = NGUITools.FindInParents<UITable>(gameObject); if (mTable == null) { updateTable = false; return; } } mTable.repositionNow = true; } if (tot != null) { if (mTrans == null) { mTrans = transform; mPos = mTrans.position; mRot = mTrans.rotation; mScale = mTrans.localScale; } if (fromt != null) { mTrans.position = fromt.position * (1f - factor) + tot.position * factor; mTrans.rotation = Quaternion.Slerp(fromt.rotation, tot.rotation, factor); } else { mTrans.position = mPos * (1f - factor) + tot.position * factor; mTrans.rotation = Quaternion.Slerp(mRot, tot.rotation, factor); } // Change the parent when finished, if requested if (parentWhenFinished && isFinished) mTrans.parent = tot; } } /// <summary> /// Start the tweening operation. /// </summary> static public TweenScaleTransform Begin(GameObject go, float duration, Vector3 scale, Transform from, Transform to) { TweenScaleTransform comp = UITweener.Begin<TweenScaleTransform>(go, duration); comp.from = comp.value; comp.to = scale; comp.fromt = from; comp.tot = 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; } }
时间: 2024-09-29 02:19:02