LTDescr.updateInternal C# (CSharp) Method

updateInternal() public method

public updateInternal ( ) : bool
return bool
    public bool updateInternal()
    {
        float directionLocal = this.direction;
        if(this.usesNormalDt){
            dt = LeanTween.dtActual;
        }else if( this.useEstimatedTime ){
            dt = LeanTween.dtEstimated;
        }else if( this.useFrames ){
            dt = this.optional.initFrameCount==0 ? 0 : 1;
            this.optional.initFrameCount = Time.frameCount;
        }else if( this.useManualTime ){
            dt = LeanTween.dtManual;
        }

        //		Debug.Log ("tween:" + this+ " dt:"+dt);
        if(this.delay<=0f && directionLocal!=0f){
            if(trans==null)
                return true;

            // initialize if has not done so yet
            if(!this.hasInitiliazed)
                this.init();

            dt = dt*directionLocal;
            this.passed += dt;

            this.ratioPassed = Mathf.Clamp01(this.passed / this.time); // need to clamp when finished so it will finish at the exact spot and not overshoot

            this.easeInternal();

            if(this.hasUpdateCallback)
                this._optional.callOnUpdate(val, this.ratioPassed);

            bool isTweenFinished = directionLocal>0f ? this.passed>=this.time : this.passed<=0f;
            //			Debug.Log("lt "+this+" dt:"+dt+" fin:"+isTweenFinished);
            if(isTweenFinished){ // increment or flip tween
                this.loopCount--;
                if(this.loopType==LeanTweenType.pingPong){
                    this.direction = 0.0f-directionLocal;
                }else{
                    this.passed = Mathf.Epsilon;
                }

                isTweenFinished = this.loopCount == 0 || this.loopType == LeanTweenType.once; // only return true if it is fully complete

                if(isTweenFinished==false && this.onCompleteOnRepeat && this.hasExtraOnCompletes)
                    callOnCompletes(); // this only gets called if onCompleteOnRepeat is set to true, otherwise LeanTween class takes care of calling it

                return isTweenFinished;
            }
        }else{
            this.delay -= dt;
        }

        return false;
    }

Usage Example

Beispiel #1
0
	public static void update() {
		if(frameRendered != Time.frameCount){ // make sure update is only called once per frame
			init();

			#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5
			dtEstimated = Time.realtimeSinceStartup - previousRealTime;
			if(dtEstimated>0.2f) // a catch put in, when at the start sometimes this number can grow unrealistically large
			dtEstimated = 0.2f;
			previousRealTime = Time.realtimeSinceStartup;
			#else

			dtEstimated = dtEstimated<0f ? 0f : dtEstimated = Time.unscaledDeltaTime;

			//		Debug.Log("Time.unscaledDeltaTime:"+Time.unscaledDeltaTime);
			#endif

			dtActual = Time.deltaTime;
			maxTweenReached = 0;
			finishedCnt = 0;
			// if(tweenMaxSearch>1500)
			//			 Debug.Log("tweenMaxSearch:"+tweenMaxSearch +" maxTweens:"+maxTweens);
			for( int i = 0; i <= tweenMaxSearch && i < maxTweens; i++){
				tween = tweens[i];
//				if(i==0 && tweens[i].toggle)
//					Debug.Log("tweens["+i+"]"+tweens[i]);
				if(tween.toggle){
					maxTweenReached = i;

					if (tween.updateInternal()) { // returns true if the tween is finished with it's loop
						tweensFinished[finishedCnt] = i;
						finishedCnt++;
					}
				}
			}

			// Debug.Log("maxTweenReached:"+maxTweenReached);
			tweenMaxSearch = maxTweenReached;
			frameRendered = Time.frameCount;

			for(int i = 0; i < finishedCnt; i++){
				j = tweensFinished[i];
				tween = tweens[ j ];
				//				Debug.Log("removing tween:"+tween);
				removeTween(j);
				if(tween.hasExtraOnCompletes && tween.trans!=null)
					tween.callOnCompletes();
			}

		}
	}
LTDescr