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

使用ITweenX 来简化iTween插件的函数调用

时间:2015-03-08 14:20:01      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:3d   unity3d   unity   animation   

??

iTween插件是u3d中很火的动画插件。

但是几乎所有函数的参数都是字符串,函数名也要以字符串的方式传入,这就不好了,我们没有必要去记EaseType和其他的参数串。


对于  设计模式的要求是  多组合,少继承。多扩展,少修改。

由于这个插件本身的功能没有任何问题。所以我们没有必要做任何徒劳的重构。就是扩展就玩了呗。


使用:

把脚本放进Standard Assets/Scripts 等等文件夹中即可; 这也很容易被javascript 或 Boo语言使用. 如果你声明一个 public 的EaseType类型变量, 你能够很容易的设置easetype 在面板 inspector. 上。


例子,随便调用一个方法:

public class MyClass: MonoBehaviour
{
	public EaseType easeType;
 
	void Start()
	{
		iTween.ValueTo( gameObject, iTween.Hash( iTweenX.from, 0f, iTweenX.to, 1f, iTweenX.time, 1f,
                                                 iTweenX.onUpdate, "OnUpdateValue",
                                                 iTweenX.onStart, "OnStart",
                                                 iTweenX.onComplete, "OnComplete",
                                                 iTweenX.easeType, iTweenX.Ease(easeType),
                                                 iTweenX.ignoreTimescale, true ) );
	}
	void OnUpdateValue(float value){ print( "OnUpdateValue : " + value.ToString() ); }
	void OnStart(){ print( "OnStart" ); }
	void OnComplete(){ print( "OnComplete" ); }
}

iTweenX.cs 

public enum EaseType
{
	EaseInQuad = 0,
	EaseOutQuad,    
	EaseInOutQuad,  
	EaseInCubic,    
	EaseOutCubic,   
	EaseInOutCubic, 
	EaseInQuart,    
	EaseOutQuart,   
	EaseInOutQuart, 
	EaseInQuint,    
	EaseOutQuint,   
	EaseInOutQuint, 
	EaseInSine,     
	EaseOutSine,    
	EaseInOutSine,  
	EaseInExpo,     
	EaseOutExpo,    
	EaseInOutExpo,  
	EaseInCirc,     
	EaseOutCirc,    
	EaseInOutCirc,  
	Linear,         
	Spring,         
	EaseInBounce,   
	EaseOutBounce,  
	EaseInOutBounce,
	EaseInBack,     
	EaseOutBack,    
	EaseInOutBack,  
	EaseInElastic,  
	EaseOutElastic, 
	EaseInOutElastic
}
 
public static class iTweenX
{	
	public readonly static string[] easeTypes = new string[32]
	{
		"easeInQuad",
		"easeOutQuad",
		"easeInOutQuad",
		"easeInCubic",
		"easeOutCubic",
		"easeInOutCubic",
		"easeInQuart",
		"easeOutQuart",
		"easeInOutQuart",
		"easeInQuint",
		"easeOutQuint",
		"easeInOutQuint",
		"easeInSine",
		"easeOutSine",
		"easeInOutSine",
		"easeInExpo",
		"easeOutExpo",
		"easeInOutExpo",
		"easeInCirc",
		"easeOutCirc",
		"easeInOutCirc",
		"linear",
		"spring",
		"easeInBounce",
		"easeOutBounce",
		"easeInOutBounce",
		"easeInBack",
		"easeOutBack",
		"easeInOutBack",
		"easeInElastic",
		"easeOutElastic",
		"easeInOutElastic"
	};
 
	public const string time =		"time";
	public const string speed =		"speed";
	public const string from =		"from";
	public const string to =		"to";
	public const string onStart =          	"onstart";
	public const string onStartTarget =	"onstarttarget";
	public const string onStartParams =	"onstartparams";
	public const string onUpdate =		"onupdate";
	public const string onUpdateTarget =	"onupdatetarget";
	public const string onUpdateParams =	"onupdateparams";
	public const string onComplete =	"oncomplete";
	public const string onCompleteTarget =	"oncompletetarget";
	public const string onCompleteParams =	"oncompleteparams";
	public const string ignoreTimescale =	"ignoretimescale";
	public const string easeType =		"easetype";
 
	public static string Ease( EaseType type )
	{
		return easeTypes[ (int)type ];
	}
}

使用ITweenX 来简化iTween插件的函数调用

标签:3d   unity3d   unity   animation   

原文地址:http://blog.csdn.net/u010019717/article/details/44132433

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