ITweenX

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(C# - iTweenX.cs: replaced static to const for the strings.)
(Replaced the switch by an array, added some parameters.)
Line 22: Line 22:
 
{
 
{
 
iTween.ValueTo( gameObject, iTween.Hash( iTweenX.from, 0f, iTweenX.to, 1f, iTweenX.time, 1f,
 
iTween.ValueTo( gameObject, iTween.Hash( iTweenX.from, 0f, iTweenX.to, 1f, iTweenX.time, 1f,
                                                 iTweenX.onUpdate, "UpdateValue",
+
                                                 iTweenX.onUpdate, "OnUpdateValue",
 
                                                 iTweenX.onStart, "OnStart",
 
                                                 iTweenX.onStart, "OnStart",
 
                                                 iTweenX.onComplete, "OnComplete",
 
                                                 iTweenX.onComplete, "OnComplete",
Line 28: Line 28:
 
                                                 iTweenX.ignoreTimescale, true ) );
 
                                                 iTweenX.ignoreTimescale, true ) );
 
}
 
}
void UpdateValue(float value){ print( "UpdateValue" ); }
+
void OnUpdateValue(float value){ print( "OnUpdateValue : " + value.ToString() ); }
 
void OnStart(){ print( "OnStart" ); }
 
void OnStart(){ print( "OnStart" ); }
 
void OnComplete(){ print( "OnComplete" ); }
 
void OnComplete(){ print( "OnComplete" ); }
Line 74: Line 74:
 
public static class iTweenX
 
public static class iTweenX
 
{
 
{
public const string easeType =         "easeType";
+
public readonly static string[] easeTypes = new string[33]
public const string easeInQuad =      "easeInQuad";
+
{
public const string easeOutQuad =      "easeOutQuad";
+
"easeType",
public const string easeInOutQuad =    "easeInOutQuad";
+
"easeInQuad",
public const string easeInCubic =      "easeInCubic";
+
"easeOutQuad",
public const string easeOutCubic =    "easeOutCubic";
+
"easeInOutQuad",
public const string easeInOutCubic =  "easeInOutCubic";
+
"easeInCubic",
public const string easeInQuart =      "easeInQuart";
+
"easeOutCubic",
public const string easeOutQuart =    "easeOutQuart";
+
"easeInOutCubic",
public const string easeInOutQuart =  "easeInOutQuart";
+
"easeInQuart",
public const string easeInQuint =      "easeInQuint";
+
"easeOutQuart",
public const string easeOutQuint =    "easeOutQuint";
+
"easeInOutQuart",
public const string easeInOutQuint =  "easeInOutQuint";
+
"easeInQuint",
public const string easeInSine =      "easeInSine";
+
"easeOutQuint",
public const string easeOutSine =      "easeOutSine";
+
"easeInOutQuint",
public const string easeInOutSine =    "easeInOutSine";
+
"easeInSine",
public const string easeInExpo =      "easeInExpo";
+
"easeOutSine",
public const string easeOutExpo =      "easeOutExpo";
+
"easeInOutSine",
public const string easeInOutExpo =    "easeInOutExpo";
+
"easeInExpo",
public const string easeInCirc =      "easeInCirc";
+
"easeOutExpo",
public const string easeOutCirc =      "easeOutCirc";
+
"easeInOutExpo",
public const string easeInOutCirc =    "easeInOutCirc";
+
"easeInCirc",
public const string linear =          "linear";
+
"easeOutCirc",
public const string spring =          "spring";
+
"easeInOutCirc",
public const string easeInBounce =    "easeInBounce";
+
"linear",
public const string easeOutBounce =   "easeOutBounce";
+
"spring",
public const string easeInOutBounce = "easeInOutBounce";
+
"easeInBounce",
public const string easeInBack =       "easeInBack";
+
"easeOutBounce",
public const string easeOutBack =     "easeOutBack";
+
"easeInOutBounce",
public const string easeInOutBack =   "easeInOutBack";
+
"easeInBack",
public const string easeInElastic =   "easeInElastic";
+
"easeOutBack",
public const string easeOutElastic =   "easeOutElastic";
+
"easeInOutBack",
public const string easeInOutElastic = "easeInOutElastic";
+
"easeInElastic",
+
"easeOutElastic",
public const string time =             "time";
+
"easeInOutElastic"
public const string from =             "from";
+
};
public const string to =               "to";
+
public const string onStart =         "onstart";
+
public const string time = "time";
public const string onUpdate =         "onupdate";
+
public const string speed = "speed";
public const string onComplete =       "oncomplete";
+
public const string from = "from";
public const string ignoreTimescale = "ignoretimescale";
+
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 )
 
public static string Ease( EaseType type )
 
{
 
{
switch(type)
+
return easeTypes[ (int)type ];
{
+
case EaseType.EaseInQuad : return easeInQuad;
+
case EaseType.EaseOutQuad : return easeOutQuad;   
+
case EaseType.EaseInOutQuad : return easeInOutQuad; 
+
case EaseType.EaseInCubic : return easeInCubic;   
+
case EaseType.EaseOutCubic : return easeOutCubic; 
+
case EaseType.EaseInOutCubic : return easeInOutCubic;
+
case EaseType.EaseInQuart : return easeInQuart;   
+
case EaseType.EaseOutQuart : return easeOutQuart; 
+
case EaseType.EaseInOutQuart : return easeInOutQuart;
+
case EaseType.EaseInQuint : return easeInQuint;   
+
case EaseType.EaseOutQuint : return easeOutQuint; 
+
case EaseType.EaseInOutQuint : return easeInOutQuint;
+
case EaseType.EaseInSine : return easeInSine;   
+
case EaseType.EaseOutSine : return easeOutSine;   
+
case EaseType.EaseInOutSine : return easeInOutSine; 
+
case EaseType.EaseInExpo : return easeInExpo;   
+
case EaseType.EaseOutExpo : return easeOutExpo;   
+
case EaseType.EaseInOutExpo : return easeInOutExpo; 
+
case EaseType.EaseInCirc : return easeInCirc;   
+
case EaseType.EaseOutCirc : return easeOutCirc;   
+
case EaseType.EaseInOutCirc : return easeInOutCirc; 
+
case EaseType.Linear : return linear;       
+
case EaseType.Spring : return spring;       
+
case EaseType.EaseInBounce : return easeInBounce; 
+
case EaseType.EaseOutBounce : return easeOutBounce; 
+
case EaseType.EaseInOutBounce : return easeInOutBounce;
+
case EaseType.EaseInBack : return easeInBack;   
+
case EaseType.EaseOutBack : return easeOutBack;   
+
case EaseType.EaseInOutBack : return easeInOutBack; 
+
case EaseType.EaseInElastic : return easeInElastic; 
+
case EaseType.EaseOutElastic : return easeOutElastic;
+
case EaseType.EaseInOutElastic : return easeInOutElastic;
+
}
+
return easeInQuad;
+
 
}
 
}
 
}</syntaxhighlight>
 
}</syntaxhighlight>

Revision as of 10:00, 23 October 2012


Author: Berenger

Contents

Description

Bunch of variables to use with iTween instead of searching the keywords every times.

Usage

Put this script in your Standard Assets/Scripts folder; this way it can be easily used from javascript or Boo. If you declare a public var of type EaseType, you can easily pick the right easetype from the inspector.


Example

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" ); }
}


C# - iTweenX.cs

public enum EaseType
{
	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 static class iTweenX
{	
	public readonly static string[] easeTypes = new string[33]
	{
		"easeType",
		"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 ];
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox