//Detect when delay was passed private void DetectDelay() { foreach (BaseTweenObject tween in tweens) { if (Time.time > tween.startTime + tween.delay && !tween.canStart) { if (tween.tweenType == TweenType.TweenPosition) { TweenPositionObject tweenPos = tween as TweenPositionObject; tweenPos.startValue = this.transform.position; } else if (tween.tweenType == TweenType.TweenRotation) { TweenRotationObject tweenRot = tween as TweenRotationObject; tweenRot.startValue = this.transform.rotation.eulerAngles; } else if (tween.tweenType == TweenType.TweenAlpha) { TweenAlphaObject tweenAlpha = tween as TweenAlphaObject; if (GetComponent <GUITexture> () != null) { tweenAlpha.startValue = GetComponent <GUITexture> ().color.a; } else { tweenAlpha.startValue = this.GetComponent <Renderer> ().material.color.a; } } this.ClearTweensSameType(tween); tween.canStart = true; } } }
//Tween alpha public void TweenAlpha(TweenAlphaObject obj) { TweenAlphaObject tween = new TweenAlphaObject(); tween.startTime = Time.time; tween.CopyTween(obj); tween.tweenValue = obj.tweenValue; tween.Init(); this.tweens.Add(tween); }
//Update Alpha private void UpdateAlpha(TweenAlphaObject tween) { float begin = tween.startValue; float finish = tween.tweenValue; float change = finish - begin; float duration = tween.totalTime; float currentTime = Time.time - (tween.startTime + tween.delay); float alpha = Equations.ChangeFloat(currentTime, begin, change, duration, tween.ease); float redColor; float redGreen; float redBlue; if (GetComponent <GUITexture> () != null) { redColor = GetComponent <GUITexture> ().color.r; redGreen = GetComponent <GUITexture> ().color.g; redBlue = GetComponent <GUITexture> ().color.b; GetComponent <GUITexture> ().color = new Color(redColor, redGreen, redBlue, alpha); if (duration == 0) { this.EndTween(tween); GetComponent <GUITexture> ().color = new Color(redColor, redGreen, redBlue, finish); return; } } else { redColor = this.GetComponent <Renderer> ().material.color.r; redGreen = this.GetComponent <Renderer> ().material.color.g; redBlue = this.GetComponent <Renderer> ().material.color.b; this.GetComponent <Renderer> ().material.color = new Color(redColor, redGreen, redBlue, alpha); if (duration == 0) { this.EndTween(tween); this.GetComponent <Renderer> ().material.color = new Color(redColor, redGreen, redBlue, finish); return; } } if (Time.time > tween.startTime + tween.delay + duration) { this.EndTween(tween); } }