//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; } } }
public void OccupyNode(PathNode previousNode, NPC currentNPC) { _prevNode = previousNode; UnityTween tween = currentNPC.gameObject.GetComponent <UnityTween>(); TweenPositionObject tweenPosition = new TweenPositionObject(); tweenPosition.tweenValue = gameObject.transform.position; tweenPosition.totalTime = 1; tween.TweenPosition(tweenPosition); }
//Add Tween in arrayList //Tween position public void TweenPosition(TweenPositionObject obj) { TweenPositionObject tween = new TweenPositionObject(); tween.startTime = Time.time; tween.CopyTween(obj); tween.tweenValue = obj.tweenValue; tween.Init(); this.tweens.Add(tween); }
//Update Position private void UpdatePosition(TweenPositionObject tween) { Vector3 begin = tween.startValue; Vector3 finish = tween.tweenValue; Vector3 change = finish - begin; float duration = tween.totalTime; float currentTime = Time.time - (tween.startTime + tween.delay); if (duration == 0) { this.EndTween(tween); this.transform.position = finish; return; } if (Time.time > tween.startTime + tween.delay + duration) { this.EndTween(tween); } this.transform.position = Equations.ChangeVector(currentTime, begin, change, duration, tween.ease); }