public Tween(TweenMode mode, Ease.Easer easer = null, int duration = 1, bool start = false) { Mode = mode; Easer = easer; Duration = duration; Active = false; if (start) Start(); }
public static Tween Create(TweenMode mode, Ease.Easer easer = null, float duration = 1f, bool start = false) { Tween tween; if (cached.Count == 0) tween = new Tween(); else tween = cached.Pop(); tween.OnUpdate = tween.OnComplete = tween.OnStart = null; tween.Init(mode, easer, duration, start); return tween; }
public static Tween Create(TweenMode mode, Ease.Easer easer = null, float duration = 1f, bool start = false) { Tween tween; if (cached.Count == 0) { tween = new Tween(); } else { tween = cached.Pop(); } tween.OnUpdate = tween.OnComplete = tween.OnStart = null; tween.Init(mode, easer, duration, start); return(tween); }
void Initialize( Ease ease, float duration, TweenMode mode, bool canStart) { Ease = ease; Duration = Math.Max(Math.Abs(duration), float.Epsilon); TimeLeft = Percent = Value = 0f; Mode = mode; IsActive = false; if (canStart) { Start(); } }
public Tween(TweenMode mode, Ease.Easer easer = null, int duration = 1, bool start = false) : base(false, false) { #if DEBUG if (duration < 1) throw new Exception("Tween duration cannot be less than 1"); #endif Mode = mode; Easer = easer; Duration = duration; Active = false; if (start) Start(); }
/// <summary> /// 回転 /// </summary> void RotateStart(bool isBack) { Vector3 vec = setting.param.option.vec; Hashtable hash = SetHashTable("rotation", vec, "amount", vec); TweenMode mode = setting.param.mode; if (mode == TweenMode.To) { iTween.RotateTo(Target, hash); } else if (mode == TweenMode.From) { iTween.RotateFrom(Target, hash); } else if (mode == TweenMode.By) { iTween.RotateBy(Target, hash); } }
public static Tween CreateAndApply( Entity entity, Ease ease, float duration, TweenMode mode, Action <Tween> onUpdate, Action <Tween> onBegin = null, Action <Tween> onEnd = null) { var tween = Create(ease, duration, mode, true); tween.OnUpdate += onUpdate; tween.OnBegin += onBegin; tween.OnEnd += onEnd; if (entity != null) { entity.Components.Add(tween); } return(tween); }
private Tween(TweenMode mode, float value, EaseFunction.Ease easer, float millisecondsDuration, Action onStart = null, Action onFinish = null) { OnStart = onStart; OnFinish = onFinish; Mode = mode; IsReverse = false; TargetValue = value; Ease = easer; Eased = Percent = 0; Duration = millisecondsDuration; if (Mode == TweenMode.Loop || Mode == TweenMode.Yoyo || Mode == TweenMode.Restart) { IsRepeating = true; } if (millisecondsDuration <= 0) { throw new Exception($"[Tween]: Duration must be a positive integer. Setting from '{millisecondsDuration}'to 0 (zero)."); } }
/// <summary> /// Tweens target transform to destination position over time. /// </summary> /// <param name="mode">how to tween.</param> /// <param name="target">Target imob.</param> /// <param name="destination">Final position.</param> /// <param name="time">Time to take to do the tween.</param> /// <param name="callback">Called when tween completes.</param> /// <returns>The isntance doing the tween.</returns> public void TweenWithTime(TweenMode tweenMode, IMob target, Vector3 destination, float time, Action <IMob, Vector3> callback) { // Early exits if (!(target is Component)) { Debug.LogWarning("IMobPositionTweener doesn't now how to tween a target that isn't a Component"); } if (Active) { Stop(); } this.target = target; this.destination = destination; this.callback = callback; /// Not actually tweening if (tweenMode == TweenMode.SNAP) { ((Component)target).transform.position = destination; if (callback != null) { callback(target, destination); } } // Tween by fixed speed else { float distance = Vector3.Distance(((Component)target).transform.position, destination); speed = distance / time; // Use an easing function switch (tweenMode) { case TweenMode.LINEAR: break; default: Debug.Log("No tween function available for mode: " + tweenMode); break; } StartCoroutine(DoTween()); } }
/// <summary> /// Tweens target transform to destination position with given rate (speed). /// </summary> /// <param name="mode">How to tween.</param> /// <param name="target">Target object.</param> /// <param name="finalPosition">Final position.</param> /// <param name="speed">How fast to move.</param> /// <param name="callback">Callback.</param> /// <returns>The isntance doing the tween.</returns> public void TweenWithRate(TweenMode tweenMode, Transform target, Vector3 destination, float speed, Action <Transform, Vector3> callback) { if (Active) { Stop(); } this.target = target; this.destination = destination; this.callback = callback; this.speed = speed; /// Not actually tweening if (tweenMode == TweenMode.SNAP) { transform.position = destination; if (callback != null) { callback(target, destination); } } // Tween by fixed speed else { switch (tweenMode) { case TweenMode.LINEAR: easingFunction = Linear; break; case TweenMode.EASE_IN_OUT: easingFunction = BezierBlend; break; default: Debug.Log("No tween function available for mode: " + tweenMode); break; } // How long do we have float distance = Vector3.Distance(target.position, destination); time = distance / speed; direction = (destination - target.position).normalized; StartCoroutine(DoEasedTween()); } }
public static Tween Move( Entity entity, Vector2 target, Ease ease, float duration, TweenMode mode = TweenMode.PlayOnce) { var tween = Create(ease, duration, mode, true); if (entity != null) { var position = entity.Position; tween.OnUpdate = (t) => { entity.Position = Vector2.Lerp(position, target, t.Value); }; entity.Components.Add(tween); } return(tween); }
/// <summary> /// Tweens target transform to destination position over time. /// </summary> /// <param name="mode">how to tween.</param> /// <param name="target">Target object.</param> /// <param name="destination">Final position.</param> /// <param name="time">Time to take to do the tween.</param> /// <param name="callback">Called when tween completes.</param> /// <returns>The isntance doing the tween.</returns> public void TweenWithTime(TweenMode tweenMode, Transform target, Vector3 destination, float time, Action <Transform, Vector3> callback) { if (Active) { Stop(); } this.time = time; this.target = target; this.destination = destination; this.callback = callback; /// Not actually tweening if (tweenMode == TweenMode.SNAP) { target.position = destination; if (callback != null) { callback(target, destination); } } // Tween by fixed speed else { // Use an easing function switch (tweenMode) { case TweenMode.LINEAR: easingFunction = Linear; break; case TweenMode.EASE_IN_OUT: easingFunction = BezierBlend; break; default: Debug.Log("No tween function available for mode: " + tweenMode); break; } direction = (destination - target.position).normalized; StartCoroutine(DoEasedTween()); } }
/// <summary> /// Tweens target transform to destination position over time. /// </summary> /// <param name="mode">how to tween.</param> /// <param name="target">Target object.</param> /// <param name="targetColor">Target color.</param> /// <param name="time">Time to take to do the tween.</param> /// <param name="callback">Called when tween completes.</param> /// <returns>The isntance doing the tween.</returns> public void TweenWithTime(TweenMode tweenMode, Component target, Color32 targetColor, float time, Action <Component, Color32> callback) { if (Active) { // Debug.LogWarning("You should stop the active tween before starting a new one"); Stop(); } this.time = time; this.target = target; this.callback = callback; this.targetColor = targetColor; /// Not actually tweening if (tweenMode == TweenMode.SNAP) { SetColorForComponent(target, targetColor); if (callback != null) { callback(target, targetColor); } } // Tween by fixed speed else { // Use an easing function switch (tweenMode) { case TweenMode.LINEAR: easingFunction = Linear; break; case TweenMode.EASE_IN_OUT: easingFunction = BezierBlend; break; default: Debug.Log("No tween function available for mode: " + tweenMode); break; } StartCoroutine(DoEasedTween()); } }
/// <summary> /// 移動 /// </summary> void MoveStart(bool isBackward) { Vector3 vec = setting.param.option.vec; Hashtable hash = SetHashTable("position", vec, "amount", vec); TweenMode mode = setting.param.mode; if (mode == TweenMode.To) { if (isBackward) { hash = SetHashTable("position", cache.pos, "amount", cache.pos); } iTween.MoveTo(Target, hash); } else if (mode == TweenMode.From) { if (isBackward) { hash = SetHashTable("position", cache.pos, "amount", cache.pos); Target.transform.localPosition = setting.param.option.vec; } else { Target.transform.localPosition = cache.pos; } iTween.MoveFrom(Target, hash); } else if (mode == TweenMode.By) { if (isBackward) { hash = SetHashTable("position", vec * -1, "amount", vec * -1); } iTween.MoveBy(Target, hash); } }
/// <summary> /// 拓展的Transform移动方法 /// </summary> /// <param name="obj"></param> /// <param name="targetPos"></param> /// <param name="needTime"></param> /// <param name="tweenMode"></param> /// <returns></returns> public static TweenObject DOLocalMove(this Transform obj, Vector3 targetPos, float needTime, TweenMode tweenMode = TweenMode.UnityTimeLineImpact) { if (LocalMoveTransformDic.ContainsKey(obj)) { LocalMoveTransformDic[obj].Stop(); //暂停上一个 LocalMoveTransformDic.Remove(obj); //清除上一个 } float timeNow = Time.realtimeSinceStartup; Vector3 pos = obj.localPosition; //记录最初位置 Vector3 startPos = obj.localPosition; //记录开始位置 float posSpace = Vector3.Distance(pos, targetPos); //记录最初距离 TweenObject tweenObject = new TweenObject((tween) => { float fpsTimeDir = 0; switch (tweenMode) { case TweenMode.UnityTimeLineImpact: fpsTimeDir = Time.deltaTime; break; case TweenMode.NoUnityTimeLineImpact: fpsTimeDir = Time.realtimeSinceStartup - timeNow; break; default: break; } pos = Vector3.MoveTowards(pos, targetPos, fpsTimeDir * posSpace / needTime); //没有运用动画曲线正常的值 float f = 1 - (Vector3.Distance(pos, targetPos) / posSpace); //通过正常值得出当前进度 obj.localPosition = Vector3.LerpUnclamped(startPos, obj.forward * targetPos.z, tween.GetAnimationCurveValue()); //通过当前进度得到动画曲线的值 obj.localPosition = Vector3.LerpUnclamped(startPos, obj.up * targetPos.y, tween.GetAnimationCurveValue()); //通过当前进度得到动画曲线的值 obj.localPosition = Vector3.LerpUnclamped(startPos, obj.right * targetPos.x, tween.GetAnimationCurveValue()); //通过当前进度得到动画曲线的值 timeNow = Time.realtimeSinceStartup; //保存这一帧的时间 return(f); }); tweenObject.onComplete += () => { obj.localPosition = obj.forward * targetPos.z; obj.localPosition = obj.up * targetPos.y; obj.localPosition = obj.right * targetPos.x; }; LocalMoveTransformDic.Add(obj, tweenObject); return(tweenObject); }
public static Tween Set(Entity entity, int duration, Ease.Easer easer, Action<Tween> onUpdate, TweenMode tweenMode = TweenMode.Oneshot) { Tween tween = new Tween(tweenMode, easer, duration, true); tween.OnUpdate += onUpdate; entity.Add(tween); return tween; }
public static Tween Scale(GraphicsComponent image, Vector2 targetScale, int duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot) { Vector2 startScale = image.Scale; Tween tween = new Tween(tweenMode, easer, duration, true); tween.OnUpdate = (t) => { image.Scale = Vector2.Lerp(startScale, targetScale, t.Eased); }; image.Entity.Add(tween); return tween; }
/// <summary> /// Tweens target transform to destination position with given rate (speed). /// </summary> /// <param name="mode">How to tween.</param> /// <param name="target">Target object.</param> /// <param name="finalPosition">Final position.</param> /// <param name="speed">How fast to move.</param> /// <param name="callback">Callback.</param> /// <returns>The isntance doing the tween.</returns> public void TweenWithRate(TweenMode tweenMode, Transform target, Vector3 destination, float speed, Action <Transform, Vector3> callback) { Debug.LogWarning("You can't tween with rate on the RotationBySpeedTweener. Use tween with time and set the rates in the rotationRates field."); }
private IEnumerator TweenFloatRoutine(IEnumerable <Renderer> renderers, string propertyName, float to, TweenMode mode, float tweenSpeed, bool isAlpha, float waitSecondsBeforeCallback, Action callback, float?from = null) { float?currentValue = from; Func <float, float, bool> breakCondition = (x, y) => false; Func <float, float, float> linearOperation = (x, y) => x + 0; if (currentValue.HasValue) { if (isAlpha) { //Debug.LogFormat("[ShaderTweener] Beginning the tween routine for alpha property {0}, changing value from {1} to {2}", propertyName, from.Value, to); } else { //Debug.LogFormat("[ShaderTweener] Beginning the tween routine for float property {0}, changing value from {1} to {2}", propertyName, from.Value, to); } if (mode == TweenMode.Linear) { breakCondition = DetermineBreakCondition(from.Value, to); linearOperation = DetermineLinearOperation(from.Value, to); } } else { if (isAlpha) { from = lastAlphaValue; //Debug.LogFormat("[ShaderTweener] No start value defined, using the last value ({0})", lastAlphaValue); //Debug.LogFormat("[ShaderTweener] Start value set. Beginning the tween routine for alpha property {0}, changing value from {1} to {2}", propertyName, from.Value, to); } else { from = lastFloatValue; //Debug.LogFormat("[ShaderTweener] No start value defined, using the last value ({0})", lastFloatValue); //Debug.LogFormat("[ShaderTweener] Start value set. Beginning the tween routine for float property {0}, changing value from {1} to {2}", propertyName, from.Value, to); } currentValue = from; if (mode == TweenMode.Linear) { breakCondition = DetermineBreakCondition(from.Value, to); linearOperation = DetermineLinearOperation(from.Value, to); } } while (!breakCondition(currentValue.Value, to)) { switch (mode) { case TweenMode.Linear: currentValue = LinearTween(currentValue.Value, from.Value, to, tweenSpeed, linearOperation); break; case TweenMode.Ease: currentValue = EasingTween(currentValue.Value, to, tweenSpeed); break; case TweenMode.PingPong: currentValue = PingPongTween(currentValue.Value, from.Value, to, tweenSpeed); break; default: throw new NotImplementedException(); } foreach (var renderer in renderers) { foreach (var material in renderer.materials) { if (!material.HasProperty(propertyName)) { //Debug.LogWarningFormat("[ShaderTweener] material {0} does not have a property {1}", material, propertyName); } else { if (isAlpha) { UpdateAlpha(propertyName, currentValue.Value, material); } else { UpdateFloat(propertyName, currentValue.Value, material); } } } } yield return(null); } if (callback != null) { if (waitSecondsBeforeCallback > 0) { yield return(new WaitForSeconds(waitSecondsBeforeCallback)); } callback(); } if (isAlpha) { alphaTweenRoutine = null; } else { floatTweenRoutine = null; } }
public void TweenAlpha(IEnumerable <Renderer> renderers, string propertyName, float to, float?from = null, TweenMode mode = TweenMode.Linear, float tweenSpeed = 1, float waitSecondsBeforeCallback = 0, Action callback = null) { if (disabled) { return; } if (alphaTweenRoutine != null) { StopCoroutine(alphaTweenRoutine); } if (gameObject.activeInHierarchy) { alphaTweenRoutine = StartCoroutine(TweenFloatRoutine(renderers, propertyName, to, mode, tweenSpeed, true, waitSecondsBeforeCallback, callback, from)); } }
/// <summary> /// 拓展CanvasGroup方法 /// </summary> /// <param name="canvasGroup"></param> /// <param name="value"></param> /// <param name="needTime"></param> public static TweenObject DOFillAlpha(this CanvasGroup canvasGroup, float value, float needTime, TweenMode tweenMode = TweenMode.UnityTimeLineImpact) { if (value > 1) { value = 1; } else if (value < 0) { value = 0; } if (canvasGroupDic.ContainsKey(canvasGroup)) { canvasGroupDic[canvasGroup].Stop(); //暂停上一个 canvasGroupDic.Remove(canvasGroup); //清除上一个 } float timeNow = Time.realtimeSinceStartup; float alpha = canvasGroup.alpha; //记录最初角度数据 float startAlpha = canvasGroup.alpha; //记录开始角度数据 float alphaSpace = Mathf.Abs(canvasGroup.alpha - value); //记录最初间隔 TweenObject tweenOgject = new TweenObject((tween) => { float fpsTimeDir = 0; switch (tweenMode) { case TweenMode.UnityTimeLineImpact: fpsTimeDir = Time.deltaTime; //直接更新时间差 break; case TweenMode.NoUnityTimeLineImpact: fpsTimeDir = Time.realtimeSinceStartup - timeNow; //与上一帧的时间差 break; default: break; } alpha = Mathf.MoveTowards(alpha, value, fpsTimeDir * alphaSpace / needTime); //没有运用动画曲线正常的值 float f = 1 - (Mathf.Abs(alpha - value) / alphaSpace); //通过正常值得出当前进度 if (canvasGroup) { canvasGroup.alpha = Mathf.LerpUnclamped(startAlpha, value, tween.GetAnimationCurveValue());//通过当前进度得到动画曲线的值 } else { tween.Stop(); } timeNow = Time.realtimeSinceStartup;//保存这一帧的时间 return(f); }); tweenOgject.OnComplete(() => { canvasGroup.alpha = value; }); canvasGroupDic.Add(canvasGroup, tweenOgject); return(tweenOgject); }
public static Tween Position(Entity entity, Vector2 target, int duration, Ease.Easer easer, TweenMode mode = TweenMode.Single) { Tween tween = new Tween(mode, easer, duration, true); Vector2 start = entity.Position; tween.OnUpdate = (Tween t) => { entity.Position = Vector2.Lerp(start, target, t.Value); }; entity.Add(tween); return tween; }
public static Tween Set(Entity entity, TweenMode tweenMode, float duration, Ease.Easer easer, Action<Tween> onUpdate, Action<Tween> onComplete = null) { Tween tween = Tween.Create(tweenMode, easer, duration, true); tween.OnUpdate += onUpdate; tween.OnComplete += onComplete; entity.Add(tween); return tween; }
/// <summary> /// 拓展的Transform移动方法 /// </summary> /// <param name="obj"></param> /// <param name="targetValue"></param> /// <param name="needTime"></param> /// <param name="tweenMode"></param> /// <returns></returns> public static TweenObject DOLocalMoveZ(this RectTransform obj, float targetValue, float needTime, TweenMode tweenMode = TweenMode.UnityTimeLineImpact) { Vector3 targetPos = obj.localPosition; targetPos.z = targetValue; if (LocalMoveZCanvasGroupDic.ContainsKey(obj)) { LocalMoveZCanvasGroupDic[obj].Stop(); //暂停上一个 LocalMoveZCanvasGroupDic.Remove(obj); //清除上一个 } float timeNow = Time.realtimeSinceStartup; float posZ = obj.localPosition.z; //记录最初角度数据 Vector3 startPos = obj.localPosition; //记录开始角度数据 float posZSpace = Mathf.Abs(obj.localPosition.z - targetValue); //记录最初间隔 TweenObject tweenObject = new TweenObject((tween) => { float fpsTimeDir = 0; switch (tweenMode) { case TweenMode.UnityTimeLineImpact: fpsTimeDir = Time.deltaTime; break; case TweenMode.NoUnityTimeLineImpact: fpsTimeDir = Time.realtimeSinceStartup - timeNow; break; default: break; } posZ = Mathf.MoveTowards(posZ, targetPos.z, fpsTimeDir * posZSpace / needTime); //没有运用动画曲线正常的值 float f = 1 - (Mathf.Abs(targetPos.z - posZ) / posZSpace); //通过正常值得出当前进度 obj.localPosition = Vector3.LerpUnclamped(startPos, targetPos, tween.GetAnimationCurveValue());//通过当前进度得到动画曲线的值 timeNow = Time.realtimeSinceStartup;//保存这一帧的时间 return(f); }); tweenObject.onComplete += () => { obj.localPosition = targetPos; }; LocalMoveZCanvasGroupDic.Add(obj, tweenObject); return(tweenObject); }
public static Tween Alpha(GraphicsComponent image, float targetAlpha, int duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot) { Entity entity = image.Entity; float startAlpha = image.Color.A / 255; Tween tween = new Tween(tweenMode, easer, duration, true); tween.OnUpdate = (t) => { image.Color.A = (byte)Math.Round(MathHelper.Lerp(startAlpha, targetAlpha, t.Eased) * 255.0f); }; entity.Add(tween); return tween; }
public Tween(TweenMode mode, TweenProperty property, float value, EaseFunction.Ease easer, float millisecondsDuration, Action onStart = null, Action onFinish = null) : this(mode, value, easer, millisecondsDuration, onStart, onFinish) { Property = property; }
public ActionParam() { target = TweenTarget.Position; mode = TweenMode.To; option = new OptionData(); }
static public Tween Position(Entity entity, Vector2 targetPosition, float duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot) { Vector2 startPosition = entity.Position; Tween tween = Tween.Create(tweenMode, easer, duration, true); tween.OnUpdate = (t) => { entity.Position = Vector2.Lerp(startPosition, targetPosition, t.Eased); }; entity.Add(tween); return(tween); }
/// <summary> /// 拓展的Transform缩放方法 /// </summary> /// <param name="obj"></param> /// <param name="targetSize"></param> /// <param name="needTime"></param> /// <param name="tweenMode"></param> /// <returns></returns> public static TweenObject DOSizeZ(this Transform obj, float targetSize, float needTime, TweenMode tweenMode = TweenMode.UnityTimeLineImpact) { Vector3 _targetSize = new Vector3(obj.localScale.x, obj.localScale.y, targetSize); if (SizeZTransformDic.ContainsKey(obj)) { SizeZTransformDic[obj].Stop(); //暂停上一个 SizeZTransformDic.Remove(obj); //清除上一个 } float timeNow = Time.realtimeSinceStartup; Vector3 size = obj.localScale; //记录最初位置 Vector3 startSize = obj.localScale; //记录开始位置 float sizeSpace = Vector3.Distance(size, _targetSize); //记录最初距离 TweenObject tweenObject = new TweenObject((tween) => { float fpsTimeDir = 0; switch (tweenMode) { case TweenMode.UnityTimeLineImpact: fpsTimeDir = Time.deltaTime; break; case TweenMode.NoUnityTimeLineImpact: fpsTimeDir = Time.realtimeSinceStartup - timeNow; break; default: break; } size = Vector3.MoveTowards(size, _targetSize, fpsTimeDir * sizeSpace / needTime); //没有运用动画曲线正常的值 float f = 1 - (Vector3.Distance(size, _targetSize) / sizeSpace); //通过正常值得出当前进度 obj.localScale = Vector3.LerpUnclamped(startSize, _targetSize, tween.GetAnimationCurveValue()); //通过当前进度得到动画曲线的值 timeNow = Time.realtimeSinceStartup; //保存这一帧的时间 return(f); }); tweenObject.onComplete += () => { obj.localScale = _targetSize; }; SizeZTransformDic.Add(obj, tweenObject); return(tweenObject); }
/// <summary> /// 拓展的Transform移动方法 /// </summary> /// <param name="obj"></param> /// <param name="targetValue"></param> /// <param name="needTime"></param> /// <param name="tweenMode"></param> /// <returns></returns> public static TweenObject DOMoveX(this RectTransform obj, float targetValue, float needTime, TweenMode tweenMode = TweenMode.UnityTimeLineImpact) { Vector3 targetPos = new Vector3(targetValue, obj.position.y, obj.position.z); if (MoveXCanvasGroupDic.ContainsKey(obj)) { MoveXCanvasGroupDic[obj].Stop(); //暂停上一个 MoveXCanvasGroupDic.Remove(obj); //清除上一个 } float timeNow = Time.realtimeSinceStartup; Vector3 pos = obj.position; //记录最初位置 Vector3 startPos = obj.position; //记录开始位置 float posSpace = Vector3.Distance(pos, targetPos); //记录最初距离 TweenObject tweenObject = new TweenObject((tween) => { float fpsTimeDir = 0; switch (tweenMode) { case TweenMode.UnityTimeLineImpact: fpsTimeDir = Time.deltaTime; break; case TweenMode.NoUnityTimeLineImpact: fpsTimeDir = Time.realtimeSinceStartup - timeNow; break; default: break; } pos = Vector3.MoveTowards(pos, targetPos, fpsTimeDir * posSpace / needTime); //没有运用动画曲线正常的值 float f = 1 - (Vector3.Distance(pos, targetPos) / posSpace); //通过正常值得出当前进度 obj.position = Vector3.LerpUnclamped(startPos, targetPos, tween.GetAnimationCurveValue()); //通过当前进度得到动画曲线的值 timeNow = Time.realtimeSinceStartup; //保存这一帧的时间 return(f); }); tweenObject.onComplete += () => { obj.position = targetPos; }; MoveXCanvasGroupDic.Add(obj, tweenObject); return(tweenObject); }
public static Tween Add(Entity entity, int duration, Ease.Easer easer, Action<Tween> onUpdate, TweenMode mode = TweenMode.Single) { Tween tween = new Tween(mode, easer, duration, true); tween.OnUpdate = onUpdate; entity.Add(tween); return tween; }
private void Init(TweenMode mode, Ease.Easer easer, float duration, bool start) { #if DEBUG if (duration <= 0) throw new Exception("Tween duration cannot be less than zero"); #else if (duration <= 0) duration = .000001f; #endif Mode = mode; Easer = easer; Duration = duration; TimeLeft = 0; Percent = 0; Active = false; if (start) Start(); }
/// <summary> /// Tweens target transform to destination position with given rate (speed). /// </summary> /// <param name="mode">How to tween.</param> /// <param name="target">Target object.</param> /// <param name="finalPosition">Final position.</param> /// <param name="speed">How fast to move.</param> /// <param name="callback">Callback.</param> /// <returns>The isntance doing the tween.</returns> public void TweenWithRate(TweenMode tweenMode, Component target, Color32 targetColor, float speed, Action <Component, Color32> callback) { Debug.LogWarning("ColorTweener does not support tween by rate"); }
public static Tween Position(Entity entity, Vector2 targetPosition, float duration, Ease.Easer easer, TweenMode tweenMode = TweenMode.Oneshot) { Vector2 startPosition = entity.Position; Tween tween = Tween.Create(tweenMode, easer, duration, true); tween.OnUpdate = (t) => { entity.Position = Vector2.Lerp(startPosition, targetPosition, t.Eased); }; entity.Add(tween); return tween; }