zoukankan      html  css  js  c++  java
  • NGUI Tween动画Scale与Transform冲突

    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; }
    
    }
  • 相关阅读:
    131. Palindrome Partitioning
    130. Surrounded Regions
    129. Sum Root to Leaf Numbers
    128. Longest Consecutive Sequence
    125. Valid Palindrome
    124. Binary Tree Maximum Path Sum
    122. Best Time to Buy and Sell Stock II
    121. Best Time to Buy and Sell Stock
    120. Triangle
    119. Pascal's Triangle II
  • 原文地址:https://www.cnblogs.com/SHOR/p/5454253.html
Copyright © 2011-2022 走看看