首页 > 代码库 > NGUI UITween => PlayToggleOnce

NGUI UITween => PlayToggleOnce

 

NGUI 的 UITweenr 很 丰富,但是有时候 还是不足,比如 我想 Play Toggle 一次,它就没提供对应的API。

写一个扩展类,很简陋,只实现了初步功能。

当然最好还是修改其内部的源码,增加 Style 之类的。

 1 public static class Extensions 2 { 3  4     public static TweenPosition _tween; 5     public static bool _isForward; 6      7     public static void PlayToggleOnce(this TweenPosition tween, bool isForward) 8     { 9         _isForward = isForward;10         _tween = tween;11         _newOrigin = default(Vector3);12         _newEnd = default(Vector3);13         _tween.Play(_isForward);14         EventDelegate.Add(_tween.onFinished, Reverse, true);15     }16 17     public static Vector3 _newOrigin = default(Vector3);18     public static Vector3 _newEnd = default(Vector3);19     20     /// start at newOrigin , end at newEnd21     public static void PlayToggleOnceWithNew(this TweenPosition tween, bool isForward,Vector3 newOrigin, Vector3 newEnd)22     {23         _isForward = isForward;24         _tween = tween;25         _newOrigin = newOrigin;26         _newEnd = newEnd;27 28         _tween.Play(_isForward);29         EventDelegate.Add(_tween.onFinished, Reverse, true);30     }31     32     public static void Reverse()33     {34         if (_newOrigin != default(Vector3) && _newEnd != default(Vector3))35         {36             _tween.ResetToBeginning();37 38             _tween.transform.localPosition = _newOrigin;39             _tween.SetStartToCurrentValue();40             //_tween.from = _newOrigin;41             42             _tween.to = _newEnd;43             44             Debug.Log("toggle");45 46             _tween.Play(_isForward);47         }48         else49         {50             _isForward = !_isForward;51 52             _tween.Play(_isForward);53         }54     }55 }

 

NGUI UITween => PlayToggleOnce