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 ]; } }
原文地址:http://blog.csdn.net/u010019717/article/details/44132433