查看: 2621|回复: 7
打印 上一主题 下一主题

iTween代码提示介绍 iTween Parameter Code Hinting

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-11-24 14:15:00 |只看该作者 |倒序浏览




           For those who don’t already know, iTween is a great tweening library for Unity. If you haven’t yet had a chance to use it, go download it. I guarantee that you will find it useful.
         

           Now that introductions are out of the way, on to the point at hand. Many code libraries (especially tweening libraries) have the problem that there is no access to code hinting for properties being passed into it’s functions. The reason being since there are so many possible parameters that could be past into each function a list of optional parameters are requested instead of a sequentially list of required parameters. This makes using these functions a lot easier and more customizable. The downside is there is no coding hinting for what  parameters could be possible passed in.
         

            
         

           In the case of using iTween in C# you pass arguments into a Hashtable and that Hashtable is then in turn passed into the these functions.
         



           Example:
         

           Hashtable tweenHash = new Hashtable();
         



           tweenHash.Add("x", -5);
         



           tweenHash.Add("y", 5);
         



           tweenHash.Add("time", 10);
         



           iTween.MoveAdd(gameObject, tweenHash);
         

           Or as a single line (if using Unity 3.0 or greater):
         

           iTween.MoveAdd(gameObject,new Hashtable(){{"x",-5},{"y",5},{"time",10}});
         

           Or an even shorter single line (does have additional creation overhead)
         

           iTween.MoveAdd(gameObject,iTween.Hash("x",-5,"y",5,"time",10));
         

           The only way to know what the list of possible parameters are for a particular function is to either a) open iTween’s source and look at the comments or b) look through the iTween documentation.
         

           Since this slows down learning and speed of using a new library I set off to try to find a better way. After exploring some different options I think I have found a better way. I wrote an app that goes through the iTween library and creates a Helper class called iT (contained within iTweenHinting.cs). Using this class you will have the ability to access code hinting/discovery when using iTween.
         

           For example:
         

           Hashtable tweenHash = new Hashtable();
         



           tweenHash.Add(iT.MoveAdd.x, -5);
         



           tweenHash.Add(iT.MoveAdd.y, 5);
         



           tweenHash.Add(iT.MoveAdd.time, 10);
         



           iTween.MoveAdd(gameObject, tweenHash);
         

           Or as a single line (if using Unity 3.0 or greater):
         

           iTween.MoveAdd(gameObject,new Hashtable(){{iT.MoveAdd.x,-5},{iT.MoveAdd.y,5},{iT.MoveAdd.time,10}});
         

           Or even shorter single line (does have additional creation overhead)
         

           iTween.MoveAdd(gameObject,iTween.Hash(iT.MoveAdd.x,-5,iT.MoveAdd.y,5,iT.MoveAdd.time,10));
         

           When you type ‘iT.’ within a code editor it will give you a list of all tweening functions within iTween. Once you select the function you wish to use (ex: MoveAdd), hit ‘.’ and your code editor will then give you a list of all possible parameters for that function (see image above).
         

           The great thing about this method, is as you get more comfortable with the iTween you can write out the strings of the simple and easy to remember parameters, while still having the ability to fallback on the helper class.
         

           To download iTweenHinting.cs click here (right-click save as).
         

           Note: While I don’t expect the list of functions and parameters within iTween to change that often. I will do my best to keep iTweenHinting.cs up-to-date.
         

           If you have any suggestions on ways I could improve/change iTweenHinting.cs please leave them in the comments below.
         

           Interesting side note: For this project I wrote code that reads code to write code that allows you to write code faster. Plus it was AS3 that was reading and writing C#. Isn’t programming .
         

           由 u8 发表  转自 www.unity3d8.com
           

            
         
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-2-16 23:30:22 |只看该作者
爱咋咋地!
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-2-21 23:31:01 |只看该作者
不会吧,太恐怖了
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

地板
发表于 2012-5-17 23:25:05 |只看该作者
凡系斑竹滴话要听;凡系朋友滴帖要顶
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-6-18 23:26:20 |只看该作者
有意思!学习了!
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-7-29 23:26:34 |只看该作者
已阵亡的 蝶 随 风 舞 说过  偶尔按一下 CTRL A 会发现 世界还有另一面
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

7#
发表于 2012-9-19 10:03:16 |只看该作者
好`我顶``顶顶
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

8#
发表于 2012-11-1 23:18:32 |只看该作者
既来之,则看之!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-20 07:25 , Processed in 0.095097 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部