Esempio n. 1
0
private static int pushNewTween( GameObject gameObject, Vector3 to, float time, TweenAction tweenAction, Hashtable optional ){
	init(maxTweens);
	if(gameObject==null)
		return -1;
	
	j = 0;
	for(i = startSearch; j < maxTweens; i++){
		if(i>=maxTweens-1){
			i = 0;
		}
		//Debug.Log("tweens["+i+"]:"+tweens[i].toggle);
		if(tweens[i].toggle==false){
			if(i+1>tweenMaxSearch){
				tweenMaxSearch = i+1;
				//Debug.Log("tweenMaxSearch:"+tweenMaxSearch);
			}
			startSearch = i + 1;
			break;
		}
		
		j++;
		if(j>=maxTweens){
			string errorMsg = "LeanTween - You have run out of available spaces for tweening. To avoid this error increase the number of spaces to available for tweening when you initialize the LeanTween class ex: LeanTween.init( "+(maxTweens*2)+" );";
			if(throwErrors) Debug.LogError(errorMsg); else Debug.Log(errorMsg);
			return -1;
		}
	}
	// if(tweenMaxSearch>lastMax){
	// 	lastMax = tweenMaxSearch;
	// 	Debug.Log("tweenMaxSearch:"+tweenMaxSearch);
	// }

	tween = tweens[i];
	tween.toggle = true;
	tween.trans = gameObject.transform;
	tween.to = to;
	tween.time = time;
	tween.passed = 0.0f;
	tween.type = tweenAction;
	tween.optional = optional;
	tween.delay = 0.0f;
	tween.id = i;
	tween.useEstimatedTime = false;
	tween.useFrames = false;
	tween.animationCurve = null;
	tween.tweenType = LeanTweenType.linear;

	if(optional!=null){
        var ease =optional["ease"];
        //LeanTweenType ease;
		var optionsNotUsed = 0;
		if(ease!=null)
        {
            //ease = (LeanTweenType)Enum.Parse(typeof(LeanTweenType), optional["ease"].ToString());
			tween.tweenType = LeanTweenType.notUsed;
			if( ease.GetType() ==typeof( LeanTweenType) )
            {
                tween.tweenType = (LeanTweenType)ease;// Enum.Parse(typeof(LeanTweenType), optional["ease"].ToString());
			}
            else if(ease.GetType() == typeof(AnimationCurve))
            {
				tween.animationCurve = optional["ease"] as AnimationCurve;
			}
            else{
				tween.tweenFunc = optional["ease"].ToString();
				if(tween.tweenFunc.Equals("easeOutQuad")){
					tween.tweenType = LeanTweenType.easeOutQuad;
				}else if(tween.tweenFunc.Equals("easeInQuad")){
					tween.tweenType = LeanTweenType.easeInQuad;
				}else if(tween.tweenFunc.Equals("easeInOutQuad")){
					tween.tweenType = LeanTweenType.easeInOutQuad;
				}
			}
			optionsNotUsed++;
		}
		if(optional["rect"]!=null){
			tween.ltRect = (LTRect)optional["rect"];
			optionsNotUsed++;
		}
		if(optional["delay"]!=null){
			tween.delay =(float) optional["delay"];
			optionsNotUsed++;
		}
		if(optional["useEstimatedTime"]!=null){
			tween.useEstimatedTime =(bool) optional["useEstimatedTime"];
			optionsNotUsed++;
		}
		if(optional["useFrames"]!=null){
			tween.useFrames =(bool) optional["useFrames"];
			optionsNotUsed++;
		}
		if(optional.Count <= optionsNotUsed)
			tween.optional = null;  // nothing else is used with the extra piece, so set to null
	}
	//Debug.Log("pushing new tween["+i+"]:"+tweens[i]);
	
	return tweens[i].id;
}
Esempio n. 2
0
public static void update() {
	if(frameRendered != Time.frameCount){ // make sure update is only called once per frame
		init();
		dtEstimated = (Application.targetFrameRate > 0 )? (1.0f/ Application.targetFrameRate ): (1.0f / 60.0f);
		dtActual = Time.deltaTime*Time.timeScale;
		// if(tweenMaxSearch>1500)
		// 	Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
		for( int i = 0; i < tweenMaxSearch && i < maxTweens; i++){
			
			//Debug.Log("tweens["+i+"].toggle:"+tweens[i].toggle);
			if(tweens[i].toggle){
				tween = tweens[i];
				trans = tween.trans as Transform;
				timeTotal = tween.time;
				tweenAction = (int)tween.type;
				tweenFunc = tween.tweenFunc;
				animationCurve = tween.animationCurve;
				optionalItems = tween.optional;
				//Debug.Log("type:"+tweens[i].type+" animationCurve:"+animationCurve);
				dt = dtActual;
				if( tween.useEstimatedTime ){
					dt = dtEstimated;
				}else if( tween.useFrames ){
					dt = 1;
				}
				//Debug.Log("tweens["+i+"]:"+tweens[i] + " dt:"+Time.deltaTime);
				
				if(trans==null){
					removeTween(i);
					continue;
				}
				
				// Check for tween finished
				isTweenFinished = false;
				if(tween.passed + dt > timeTotal){
					isTweenFinished = true;
					tween.passed = timeTotal; // Set to the exact end time so that it can finish tween exactly on the end value
				}
				
				if(tween.passed==0.0 && tweens[i].delay==0.0){
					// Initialize From Values
					switch((TweenAction)tweenAction){
						case TweenAction.MOVE:
							tween.from = trans.position; break;
						case TweenAction.MOVE_X:
							tween.from.x = trans.position.x; break;
						case TweenAction.MOVE_Y:
							tween.from.x = trans.position.y; break;
						case TweenAction.MOVE_Z:
							tween.from.x = trans.position.z; break;
						case TweenAction.MOVE_LOCAL_X:
							tweens[i].from.x = trans.localPosition.x; break;
						case TweenAction.MOVE_LOCAL_Y:
							tweens[i].from.x = trans.localPosition.y; break;
						case TweenAction.MOVE_LOCAL_Z:
							tweens[i].from.x = trans.localPosition.z; break;
						case TweenAction.SCALE_X:
							tween.from.x = trans.localScale.x; break;
						case TweenAction.SCALE_Y:
							tween.from.x = trans.localScale.y; break;
						case TweenAction.SCALE_Z:
							tween.from.x = trans.localScale.z; break;
						case TweenAction.ALPHA:
							tween.from.x = trans.gameObject.renderer.material.color.a; break;
						case TweenAction.MOVE_LOCAL:
							tween.from = trans.localPosition; break;
						case TweenAction.ROTATE:
							tween.from = trans.eulerAngles; 
							tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
							tween.to.y = LeanTween.closestRot( tween.from.y, tween.to.y);
							tween.to.z = LeanTween.closestRot( tween.from.z, tween.to.z);
							break;
						case TweenAction.ROTATE_X:
							tween.from.x = trans.eulerAngles.x; 
							tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
							break;
						case TweenAction.ROTATE_Y:
							tween.from.x = trans.eulerAngles.y; 
							tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
							break;
						case TweenAction.ROTATE_Z:
							tween.from.x = trans.eulerAngles.z; 
							tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
							break;
						case TweenAction.ROTATE_LOCAL:
							tween.from = trans.localEulerAngles; 
							tween.to.x = LeanTween.closestRot( tween.from.x, tween.to.x);
							tween.to.y = LeanTween.closestRot( tween.from.y, tween.to.y);
							tween.to.z = LeanTween.closestRot( tween.from.z, tween.to.z);
							break;
						case TweenAction.SCALE:
							tween.from = trans.localScale; break;
						case TweenAction.GUI_MOVE:
							tween.from =new Vector3(tween.ltRect.rect.x, tween.ltRect.rect.y, 0); break;
						case TweenAction.GUI_SCALE:
							tween.from =new  Vector3(tween.ltRect.rect.width, tween.ltRect.rect.height, 0); break;
					}
					tween.diff.x = tween.to.x - tween.from.x;
					tween.diff.y = tween.to.y - tween.from.y;
					tween.diff.z = tween.to.z - tween.from.z;
				}
				if(tween.delay<=0){
					// Move Values
					ratioPassed = tween.passed / timeTotal;
					if(ratioPassed>1.0)
						ratioPassed = 1.0f;
					
					if(tweenAction>=(int)TweenAction.MOVE_X && tweenAction<=(int)TweenAction.CALLBACK){
						if(animationCurve!=null){
							val = tweenOnCurve(tween, ratioPassed);
						}else {
							switch( tween.tweenType ){
								case LeanTweenType.linear:
									val = tween.from.x + tween.diff.x * ratioPassed; break;
								case LeanTweenType.easeOutQuad:
									val = easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
								case LeanTweenType.easeInQuad:
									val = easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
								case LeanTweenType.easeInOutQuad:
									val = easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed); break;
								case LeanTweenType.easeInCubic:
									val = easeInCubic(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutCubic:
									val = easeOutCubic(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutCubic:
									val = easeInOutCubic(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInQuart:
									val = easeInQuart(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutQuart:
									val = easeOutQuart(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutQuart:
									val = easeInOutQuart(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInQuint:
									val = easeInQuint(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutQuint:
									val = easeOutQuint(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutQuint:
									val = easeInOutQuint(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInSine:
									val = easeInSine(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutSine:
									val = easeOutSine(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutSine:
									val = easeInOutSine(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInExpo:
									val = easeInExpo(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutExpo:
									val = easeOutExpo(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutExpo:
									val = easeInOutExpo(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInCirc:
									val = easeInCirc(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutCirc:
									val = easeOutCirc(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutCirc:
									val = easeInOutCirc(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInBounce:
									val = easeInBounce(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutBounce:
									val = easeOutBounce(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutBounce:
									val = easeInOutBounce(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInBack:
									val = easeInBack(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutBack:
									val = easeOutBack(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutBack:
									val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInElastic:
									val = easeInElastic(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeOutElastic:
									val = easeOutElastic(tween.from.x, tween.to.x, ratioPassed); break;
								case LeanTweenType.easeInOutElastic:
									val = easeInOutElastic(tween.from.x, tween.to.x, ratioPassed); 
                                    break;
                                case LeanTweenType.punch:
									tween.animationCurve = LeanTween.punch;
									tween.to.x = tween.from.x + tween.to.x;
									val = tweenOnCurve(tween, ratioPassed); break;
                                default:
                                    {
                                        val = tween.from.x + tween.diff.x * ratioPassed; break;
                                    }
							}
						
						}
						//Debug.Log("from:"+from+" to:"+to+" val:"+val+" ratioPassed:"+ratioPassed);
						if((TweenAction)tweenAction==TweenAction.MOVE_X){
							trans.position=new Vector3( val,trans.position.y,trans.position.z);
						}else if((TweenAction)tweenAction==TweenAction.MOVE_Y){
							trans.position =new Vector3( trans.position.x,val,trans.position.z);
						}else if((TweenAction)tweenAction==TweenAction.MOVE_Z){
							trans.position=new Vector3( trans.position.x,trans.position.y,val);
						}if((TweenAction)tweenAction==TweenAction.MOVE_LOCAL_X){
							trans.localPosition=new Vector3( val,trans.localPosition.y,trans.localPosition.z);
						}else if((TweenAction)tweenAction==TweenAction.MOVE_LOCAL_Y){
							trans.localPosition=new Vector3( trans.localPosition.x,val,trans.localPosition.z);
						}else if((TweenAction)tweenAction==TweenAction.MOVE_LOCAL_Z){
							trans.localPosition=new Vector3( trans.localPosition.x,trans.localPosition.y,val);
						}else if((TweenAction)tweenAction==TweenAction.SCALE_X){
							trans.localScale=new Vector3(val, trans.localScale.y,trans.localScale.z);
						}else if((TweenAction)tweenAction==TweenAction.SCALE_Y){
							trans.localScale=new Vector3( trans.localScale.x,val,trans.localScale.z);
						}else if((TweenAction)tweenAction==TweenAction.SCALE_Z){
							trans.localScale=new Vector3(trans.localScale.x,trans.localScale.y,val);
						}else if((TweenAction)tweenAction==TweenAction.ROTATE_X){
					    	trans.eulerAngles=new Vector3(val, trans.eulerAngles.y,trans.eulerAngles.z);
					    }else if((TweenAction)tweenAction==TweenAction.ROTATE_Y){
					    	trans.eulerAngles=new Vector3(trans.eulerAngles.x,val,trans.eulerAngles.z);
					    }else if((TweenAction)tweenAction==TweenAction.ROTATE_Z){
					    	trans.eulerAngles=new Vector3(trans.eulerAngles.x,trans.eulerAngles.y,val);
					    }else if((TweenAction)tweenAction==TweenAction.ALPHA){
							trans.gameObject.renderer.material.color=new Color(trans.gameObject.renderer.material.color.r,trans.gameObject.renderer.material.color.g,trans.gameObject.renderer.material.color.b,val);
						}
						
					}else if((TweenAction) tweenAction>=TweenAction.MOVE){
						//
						
						if(animationCurve!=null){
							newVect = tweenOnCurveVector(tween, ratioPassed);
						}else{
							if(tween.tweenType == LeanTweenType.linear){
								newVect.x = tween.from.x + tween.diff.x * ratioPassed;
								newVect.y = tween.from.y + tween.diff.y * ratioPassed;
								newVect.z = tween.from.z + tween.diff.z * ratioPassed;
							}else if(tween.tweenType >= LeanTweenType.linear){
								switch(tween.tweenType){
									case LeanTweenType.easeOutQuad:
										newVect = new Vector3(easeOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
									case LeanTweenType.easeInQuad:
										newVect = new Vector3(easeInQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
									case LeanTweenType.easeInOutQuad:
										newVect = new Vector3(easeInOutQuadOpt(tween.from.x, tween.diff.x, ratioPassed), easeInOutQuadOpt(tween.from.y, tween.diff.y, ratioPassed), easeInOutQuadOpt(tween.from.z, tween.diff.z, ratioPassed)); break;
									case LeanTweenType.easeInCubic:
										newVect = new Vector3(easeInCubic(tween.from.x, tween.to.x, ratioPassed), easeInCubic(tween.from.y, tween.to.y, ratioPassed), easeInCubic(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutCubic:
										newVect = new Vector3(easeOutCubic(tween.from.x, tween.to.x, ratioPassed), easeOutCubic(tween.from.y, tween.to.y, ratioPassed), easeOutCubic(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutCubic:
										newVect = new Vector3(easeInOutCubic(tween.from.x, tween.to.x, ratioPassed), easeInOutCubic(tween.from.y, tween.to.y, ratioPassed), easeInOutCubic(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInQuart:
										newVect = new Vector3(easeInQuart(tween.from.x, tween.to.x, ratioPassed), easeInQuart(tween.from.y, tween.to.y, ratioPassed), easeInQuart(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutQuart:
										newVect = new Vector3(easeOutQuart(tween.from.x, tween.to.x, ratioPassed), easeOutQuart(tween.from.y, tween.to.y, ratioPassed), easeOutQuart(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutQuart:
										newVect = new Vector3(easeInOutQuart(tween.from.x, tween.to.x, ratioPassed), easeInOutQuart(tween.from.y, tween.to.y, ratioPassed), easeInOutQuart(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInQuint:
										newVect = new Vector3(easeInQuint(tween.from.x, tween.to.x, ratioPassed), easeInQuint(tween.from.y, tween.to.y, ratioPassed), easeInQuint(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutQuint:
										newVect = new Vector3(easeOutQuint(tween.from.x, tween.to.x, ratioPassed), easeOutQuint(tween.from.y, tween.to.y, ratioPassed), easeOutQuint(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutQuint:
										newVect = new Vector3(easeInOutQuint(tween.from.x, tween.to.x, ratioPassed), easeInOutQuint(tween.from.y, tween.to.y, ratioPassed), easeInOutQuint(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInSine:
										newVect = new Vector3(easeInSine(tween.from.x, tween.to.x, ratioPassed), easeInSine(tween.from.y, tween.to.y, ratioPassed), easeInSine(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutSine:
										newVect = new Vector3(easeOutSine(tween.from.x, tween.to.x, ratioPassed), easeOutSine(tween.from.y, tween.to.y, ratioPassed), easeOutSine(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutSine:
										newVect = new Vector3(easeInOutSine(tween.from.x, tween.to.x, ratioPassed), easeInOutSine(tween.from.y, tween.to.y, ratioPassed), easeInOutSine(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInExpo:
										newVect = new Vector3(easeInExpo(tween.from.x, tween.to.x, ratioPassed), easeInExpo(tween.from.y, tween.to.y, ratioPassed), easeInExpo(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutExpo:
										newVect = new Vector3(easeOutExpo(tween.from.x, tween.to.x, ratioPassed), easeOutExpo(tween.from.y, tween.to.y, ratioPassed), easeOutExpo(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutExpo:
										newVect = new Vector3(easeInOutExpo(tween.from.x, tween.to.x, ratioPassed), easeInOutExpo(tween.from.y, tween.to.y, ratioPassed), easeInOutExpo(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInCirc:
										newVect = new Vector3(easeInCirc(tween.from.x, tween.to.x, ratioPassed), easeInCirc(tween.from.y, tween.to.y, ratioPassed), easeInCirc(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutCirc:
										newVect = new Vector3(easeOutCirc(tween.from.x, tween.to.x, ratioPassed), easeOutCirc(tween.from.y, tween.to.y, ratioPassed), easeOutCirc(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutCirc:
										newVect = new Vector3(easeInOutCirc(tween.from.x, tween.to.x, ratioPassed), easeInOutCirc(tween.from.y, tween.to.y, ratioPassed), easeInOutCirc(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInBounce:
										newVect = new Vector3(easeInBounce(tween.from.x, tween.to.x, ratioPassed), easeInBounce(tween.from.y, tween.to.y, ratioPassed), easeInBounce(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutBounce:
										newVect = new Vector3(easeOutBounce(tween.from.x, tween.to.x, ratioPassed), easeOutBounce(tween.from.y, tween.to.y, ratioPassed), easeOutBounce(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutBounce:
										newVect = new Vector3(easeInOutBounce(tween.from.x, tween.to.x, ratioPassed), easeInOutBounce(tween.from.y, tween.to.y, ratioPassed), easeInOutBounce(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInBack:
										newVect = new Vector3(easeInBack(tween.from.x, tween.to.x, ratioPassed), easeInBack(tween.from.y, tween.to.y, ratioPassed), easeInBack(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutBack:
										newVect = new Vector3(easeOutBack(tween.from.x, tween.to.x, ratioPassed), easeOutBack(tween.from.y, tween.to.y, ratioPassed), easeOutBack(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutBack:
										newVect = new Vector3(easeInOutBack(tween.from.x, tween.to.x, ratioPassed), easeInOutBack(tween.from.y, tween.to.y, ratioPassed), easeInOutBack(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInElastic:
										newVect = new Vector3(easeInElastic(tween.from.x, tween.to.x, ratioPassed), easeInElastic(tween.from.y, tween.to.y, ratioPassed), easeInElastic(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeOutElastic:
										newVect = new Vector3(easeOutElastic(tween.from.x, tween.to.x, ratioPassed), easeOutElastic(tween.from.y, tween.to.y, ratioPassed), easeOutElastic(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.easeInOutElastic:
										newVect = new Vector3(easeInOutElastic(tween.from.x, tween.to.x, ratioPassed), easeInOutElastic(tween.from.y, tween.to.y, ratioPassed), easeInOutElastic(tween.from.z, tween.to.z, ratioPassed)); break;
									case LeanTweenType.punch:
										tween.animationCurve = LeanTween.punch;
										tween.to.x = tween.from.x + tween.to.x;
										tween.to.y = tween.from.y + tween.to.y;
										tween.to.z = tween.from.z + tween.to.z;
										if((TweenAction) tweenAction==TweenAction.ROTATE || (TweenAction) tweenAction==TweenAction.ROTATE_LOCAL){
											tween.to.x = closestRot(tween.from.x, tween.to.x);
											tween.to.y = closestRot(tween.from.y, tween.to.y);
											tween.to.z = closestRot(tween.from.z, tween.to.z);
										}
										newVect = tweenOnCurveVector(tween, ratioPassed); break;
								}
							}else{
								fromVect = tween.from;
								toVect = tween.to;
                                newVect.x = tween.from.x + tween.diff.x * ratioPassed;
								newVect.y = tween.from.y + tween.diff.y * ratioPassed;
								newVect.z = tween.from.z + tween.diff.z * ratioPassed;
							}
						}
						 
						if((TweenAction) tweenAction==TweenAction.MOVE){
							trans.position = newVect;
					    }else if((TweenAction) tweenAction==TweenAction.MOVE_LOCAL){
							trans.localPosition = newVect;
					    }else if((TweenAction) tweenAction==TweenAction.ROTATE){
					    	trans.eulerAngles = newVect;
					    }else if((TweenAction) tweenAction==TweenAction.ROTATE_LOCAL){
					    	trans.localEulerAngles = newVect;
					    }else if((TweenAction) tweenAction==TweenAction.SCALE){
					    	trans.localScale = newVect;
					    }else if((TweenAction) tweenAction==TweenAction.GUI_MOVE){
					    	tween.ltRect.rect.x = newVect.x;
					    	tween.ltRect.rect.y = newVect.y;
					    }else if((TweenAction) tweenAction==TweenAction.GUI_SCALE){
					    	tween.ltRect.rect.width = newVect.x;
					    	tween.ltRect.rect.height = newVect.y;
					    }
					}

					if(tween.optional!=null){
						var onUpdate = optionalItems["onUpdate"];
						if(onUpdate!=null){
							//Hashtable updateParam = (Hashtable)optionalItems["onUpdateParam"];
							if(onUpdate.GetType() == typeof(string)){
								string onUpdateS = onUpdate as string;
								if (optionalItems["onUpdateTarget"]!=null){
									customTarget = optionalItems["onUpdateTarget"] as GameObject;
									customTarget.BroadcastMessage( onUpdateS, val );
								}else{
									trans.gameObject.BroadcastMessage( onUpdateS, val );
								}
							}else{
                                //var onUpdateF:Function = onUpdate as Function;
                                //if(updateParam) onUpdateF( val, updateParam );
                                //else onUpdateF(val);
							}
						}
					}
				}
				
				if(isTweenFinished){
					//var callback=null;
					string callbackS=string.Empty;
					object callbackParam=null;
					if(tween.optional!=null && tween.trans){
						if(optionalItems["onComplete"]!=null){
							if(optionalItems["onComplete"].GetType()==typeof(string)){
								callbackS = optionalItems["onComplete"] as string;
							}else{
								//callback = optionalItems["onComplete"] as Function;
							}
						}
						callbackParam = optionalItems["onCompleteParam"];
					}
					removeTween(i);
					//if(callback){
						///if(callbackParam!=null) callback( callbackParam );
						//else callback();
					//}else
                    if(callbackS!=string.Empty){
						if (optionalItems["onCompleteTarget"]!=null){
							customTarget = optionalItems["onCompleteTarget"] as GameObject;
							if(callbackParam!=null) customTarget.BroadcastMessage ( callbackS, callbackParam );
							else customTarget.BroadcastMessage( callbackS );
						}else{
							if(callbackParam!=null) trans.gameObject.BroadcastMessage ( callbackS, callbackParam );
							else trans.gameObject.BroadcastMessage( callbackS );
						}
					}
				}else if(tween.delay<=0){
					tween.passed += dt;
				}else{
					tween.delay -= dt;
					if(tween.delay<0){
						tween.passed = 0.0f;//-tween.delay
						tween.delay = 0.0f;
					}
				}
			}
		}

		frameRendered = Time.frameCount;
	}
}
Esempio n. 3
0
private static Vector3 tweenOnCurveVector( TweenDescr tweenDescr, float ratioPassed ){
	return	new Vector3(tweenDescr.from.x + (tweenDescr.to.x-tweenDescr.from.x) * tweenDescr.animationCurve.Evaluate(ratioPassed),
						tweenDescr.from.y + (tweenDescr.to.y-tweenDescr.from.y) * tweenDescr.animationCurve.Evaluate(ratioPassed),
						tweenDescr.from.z + (tweenDescr.to.z-tweenDescr.from.z) * tweenDescr.animationCurve.Evaluate(ratioPassed) );
}
Esempio n. 4
0
/**
* This line is optional. Here you can specify the maximum number of tweens you will use (the default is 400).  This must be called before any use of LeanTween is made for it to be effective.
* 
* @method LeanTween.init
* @param {integer} maxSimultaneousTweens:int The maximum number of tweens you will use, make sure you don't go over this limit, otherwise the code will throw an error
* @example
*   LeanTween.init( 800 );
*/
public static void init(int maxSimultaneousTweens){
	if(tweens==null){
		maxTweens = maxSimultaneousTweens;
		tweens = new TweenDescr[maxTweens];
		tweenEmpty = new GameObject();
		tweenEmpty.name = "~LeanTween";
		tweenEmpty.AddComponent(typeof(LeanTween));
		tweenEmpty.isStatic = true;
		DontDestroyOnLoad( tweenEmpty );
		for(int i = 0; i < maxTweens; i++){
			tweens[i] = new TweenDescr();
		}
	}
}
Esempio n. 5
0
// Tweening Functions - Thanks to Robert Penner and GFX47

private static float tweenOnCurve( TweenDescr tweenDescr, float ratioPassed ){
	return tweenDescr.from.x + (tweenDescr.to.x - tweenDescr.from.x) * tweenDescr.animationCurve.Evaluate(ratioPassed);
}