码迷,mamicode.com
首页 > 其他好文 > 详细

NGUI UITween => PlayToggleOnce

时间:2014-11-25 00:14:05      阅读:484      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   for   on   

 

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 newEnd
21     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         else
49         {
50             _isForward = !_isForward;
51 
52             _tween.Play(_isForward);
53         }
54     }
55 }

 

NGUI UITween => PlayToggleOnce

标签:style   blog   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/chongxin/p/4119940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!