首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。