public void AddTween(TweenType type) { if (null == _tweens) { _tweens = new SerializedTween[1]; } else { Array.Resize <SerializedTween>(ref _tweens, _tweens.Length + 1); } var tween = new SerializedTween { Type = type }; switch (type) { case TweenType.Color: tween.From = tween.To = Vector3.one; break; case TweenType.Play: tween.From = Vector3.one; break; } _tweens[_tweens.Length - 1] = tween; }
public static float Eval(float a, float b, float x, TweenType tween) { if (x < 0f) { x = 0f; } if (x > 1f) { x = 1f; } var diff = (b - a); switch (tween) { case (TweenType.Linear): return(a + diff * x); case (TweenType.Accelerate): //n = (x * x) * (1f - x); //return a + diff * (n * n * n + x * x); return(a + diff * (-(x * x * x) + 2 * x * x)); case (TweenType.Decelerate): return(a + diff * (x * x - x * x * x + x)); case (TweenType.Smooth): if (x > 0.5f) { return(a + diff * Eval(0.5f, 1f, (x - 0.5f) * 2f, TweenType.Decelerate)); } return(a + diff * Eval(0f, 0.5f, x * 2f, TweenType.Accelerate)); } return(0f); }
internal static double Current(float val, TweenType type) { switch (type) { case TweenType.easeInQuad: return System.Math.Pow(val, 2); case TweenType.easeOutQuad: return -(System.Math.Pow((val-1), 2) -1); case TweenType.easeInCubic: return System.Math.Pow(val, 3); case TweenType.easeOutCubic: return (System.Math.Pow((val-1), 3) +1); case TweenType.easeInSine: return -System.Math.Cos(val* (System.Math.PI/2)) + 1; case TweenType.easeOutSine: return System.Math.Sin(val * (System.Math.PI/2)); case TweenType.elastic: return -1 * System.Math.Pow(4, -8 * val) * System.Math.Sin((val * 6 - 1) * (2 * System.Math.PI) / 2) + 1; case TweenType.spring: return 1 - (System.Math.Cos(val * 4.5 * System.Math.PI) * System.Math.Exp(-val* 6)); case TweenType.wobble: return (-System.Math.Cos(val* System.Math.PI * (9 * val)) / 2) + 0.5; case TweenType.linear: default: return val; } }
public static void Evaluate(this TSSItem item, float time, ItemKey direction) { float effectValue = 0; if (item.state != ItemState.slave) { item.state = ItemState.slave; } for (int i = 0; i < item.tweens.Count; i++) { if (!item.tweens[i].enabled || (direction == ItemKey.closed && item.tweens[i].direction != TweenDirection.Close && item.tweens[i].direction != TweenDirection.OpenClose) || (direction == ItemKey.opened && item.tweens[i].direction != TweenDirection.Open && item.tweens[i].direction != TweenDirection.OpenClose)) { continue; } TweenType type = item.tweens[i].mode == TweenMode.Single ? item.tweens[i].type : (direction == ItemKey.closed ? item.tweens[i].closingType : item.tweens[i].type); effectValue = item.tweens[i].Evaluate(time, type); if (item.tweens[i].effect == ItemEffect.property) { DoProperty(item, item.tweens[i].matProperty, effectValue); } else { effects[(int)item.tweens[i].effect](item, effectValue); } } }
//移动(Move)动画 private void UpdateMove(TweenType type, GameObject obj, Vector3 fromPos, Vector3 toPos, float t, bool isCounterX = false, bool isCounterY = false, float offset = 0) { if (type == TweenType.None) { return; } Vector3 move = toPos - fromPos; float xVar = xCurve.Evaluate(t); float yVar = yCurve.Evaluate(t); float val = t / time; move.x *= !isCounterX ? val - (val - xVar) : val + (val - xVar); move.y *= !isCounterY ? val - (val - yVar) : val + (val - yVar); //偏移值 float offsetVal = offsetCurve.Evaluate(t); float oVal = offset * offsetVal; float a = Vector3.Angle(move, Vector3.left) - 90; float offsetY = oVal * Mathf.Sin(a * Mathf.Deg2Rad); float offsetX = oVal * Mathf.Cos(a * Mathf.Deg2Rad); obj.transform.localPosition = fromPos + move + new Vector3(-offsetX, offsetY, 0); }
public static float Tween(TweenType type, float curTime, float beginingValue, float changeInValue, float duration) { float result; switch (type) { case TweenType.LinearTween: result = LinearTween(curTime, beginingValue, changeInValue, duration); break; case TweenType.EaseInQuad: result = EaseInQuad(curTime, beginingValue, changeInValue, duration); break; case TweenType.EaseOutQuad: result = EaseOutQuad(curTime, beginingValue, changeInValue, duration); break; case TweenType.EaseInOutQuad: result = EaseInOutQuad(curTime, beginingValue, changeInValue, duration); break; default: result = LinearTween(curTime, beginingValue, changeInValue, duration); break; } return(result); }
/// <private/> protected override void _OnClear() { this.pauseFadeOut = true; this.fadeOutMode = AnimationFadeOutMode.All; this.fadeOutTweenType = TweenType.Line; this.fadeOutTime = -1.0f; this.actionEnabled = true; this.additiveBlending = false; this.displayControl = true; this.pauseFadeIn = true; this.resetToPose = true; this.fadeInTweenType = TweenType.Line; this.playTimes = -1; this.layer = 0; this.position = 0.0f; this.duration = -1.0f; this.timeScale = -100.0f; this.weight = 1.0f; this.fadeInTime = -1.0f; this.autoFadeOutTime = -1.0f; this.name = ""; this.animation = ""; this.group = ""; this.boneMask.Clear(); }
public static EasingData CreatEasingData(TweenType tweenType, CSVectorFloat easingparma) { EasingData easingData = new EasingData(tweenType); if (easingparma != null) { if (tweenType == TweenType.Custom) { int count = easingparma.Count; if (count == 8) { for (int i = 0; i < count; i += 2) { easingData.ProportionPoints.Add(new Point((int)easingparma[i], (int)easingparma[i + 1])); } } } else { int count = easingparma.Count; for (int i = 0; i < count; i++) { easingData.ProportionPoints.Add(new Point((int)easingparma[i], 0)); } } } return(easingData); }
public virtual void StartTween(TweenType tweenType, TweenCallback tweenCallback) { StartTweenCommon(tweenCallback); switch (_tweenStyle) { case TweenStyle.In: InTween(tweenType); break; case TweenStyle.Out: OutTween(tweenType); break; case TweenStyle.InAndOut: InAndOutTween(tweenType); break; case TweenStyle.NoTween: break; default: throw new ArgumentOutOfRangeException(); } }
/// <private/> public void CopyFrom(AnimationConfig value) { this.pauseFadeOut = value.pauseFadeOut; this.fadeOutMode = value.fadeOutMode; this.autoFadeOutTime = value.autoFadeOutTime; this.fadeOutTweenType = value.fadeOutTweenType; this.actionEnabled = value.actionEnabled; this.additiveBlending = value.additiveBlending; this.displayControl = value.displayControl; this.pauseFadeIn = value.pauseFadeIn; this.resetToPose = value.resetToPose; this.playTimes = value.playTimes; this.layer = value.layer; this.position = value.position; this.duration = value.duration; this.timeScale = value.timeScale; this.fadeInTime = value.fadeInTime; this.fadeOutTime = value.fadeOutTime; this.fadeInTweenType = value.fadeInTweenType; this.weight = value.weight; this.name = value.name; this.animation = value.animation; this.group = value.group; boneMask.ResizeList(value.boneMask.Count, null); for (int i = 0, l = boneMask.Count; i < l; ++i) { boneMask[i] = value.boneMask[i]; } }
private IEnumerator Tween(MoveTweenData data, Action onComplete) { float timer = 0; float duration = data.Duration; TweenType tweenType = data.TweenType; Vector3 startPosition = transform.position; Vector3 endPosition = startPosition + data.EndPosition; Vector3 difference = endPosition - startPosition; Vector3 newPosition = startPosition; while (timer < duration) { // @TODO: Limit it only to necessary axis for performance. // For development purposes, all axis are available. newPosition.x = TweenEase.GetNewValue(tweenType, timer, startPosition.x, difference.x, duration); newPosition.y = TweenEase.GetNewValue(tweenType, timer, startPosition.y, difference.y, duration); newPosition.z = TweenEase.GetNewValue(tweenType, timer, startPosition.z, difference.z, duration); transform.position = newPosition; timer = Mathf.Clamp(timer + Time.deltaTime, 0, duration); yield return(new WaitForEndOfFrame()); } transform.position = endPosition; onComplete?.Invoke(); }
public static EasingData CreatEasingData(TweenType tweenType, List <float> easingparma) { EasingData easingData = new EasingData(tweenType); if (easingparma != null) { if (tweenType == TweenType.Custom) { int count = easingparma.Count; if (count == 8) { int index = 0; while (index < count) { easingData.ProportionPoints.Add(new Point((int)easingparma[index], (int)easingparma[index + 1])); index += 2; } } } else { int count = easingparma.Count; for (int index = 0; index < count; ++index) { easingData.ProportionPoints.Add(new Point((int)easingparma[index], 0)); } } } return(easingData); }
public static UITweener createUITweener(RectTransform recTra, TweenType type) { TweenPosition twPos = new TweenPosition(); float posY = recTra.anchoredPosition.y; switch (type) { case TweenType.TOP_IN: recTra.anchoredPosition = new Vector2(recTra.anchoredPosition.x, recTra.sizeDelta.y); twPos.from = recTra.anchoredPosition; twPos.to = new Vector2(recTra.anchoredPosition.x, posY); twPos.method = UITweener.Method.QuintEaseInOut; twPos.duration = .5f; break; case TweenType.TOP_OUT: twPos.from = recTra.anchoredPosition; twPos.to = new Vector2(recTra.anchoredPosition.x, recTra.sizeDelta.y); twPos.method = UITweener.Method.QuintEaseInOut; twPos.duration = .4f; break; } twPos.trans = recTra; return(twPos); }
public void AddProvider(TweenType tweenType, Type objectType, Type providerType) { if (!providerOptions.ContainsKey(tweenType)) providerOptions[tweenType] = new List<KeyValuePair<Type, Type>>(); providerOptions[tweenType].Add(new KeyValuePair<Type, Type>(objectType, providerType)); }
//选择性 动画类型开启方式 (移动,缩放,旋转,Alpha) public void OpenTweenType(bool isOpenMoveType, bool isOpenScaleType, bool isOpenRotateType, bool isOpenAlphaType) { moveType = isOpenMoveType ? TweenType.Normal : TweenType.None; scaleType = isOpenScaleType ? TweenType.Normal : TweenType.None; rotateType = isOpenRotateType ? TweenType.Normal : TweenType.None; alphaType = isOpenAlphaType ? TweenType.Normal : TweenType.None; }
public PotaTween SetAlpha(TweenType type, float value, string colorProperty = "_Color") { this._colorProperty = colorProperty; Renderer tempRender = GetComponent <Renderer>() ? GetComponent <Renderer>() : GetComponentInChildren <Renderer>(); Image tempImageRender = GetComponentInChildren <Image>(); float targetAlpha = tempImageRender != null ? tempImageRender.color.a : tempRender.sharedMaterial.GetColor(colorProperty).a; if (tempRender is SpriteRenderer) { targetAlpha = ((SpriteRenderer)tempRender).color.a; } switch (type) { case TweenType.From: Alpha = new PTTFloat(value, targetAlpha); break; case TweenType.To: Alpha = new PTTFloat(targetAlpha, value); break; } GetRenderers(); return(this); }
//还原成默认 动画类型 public void InitTweenType() { moveType = beginTypeList[0]; scaleType = beginTypeList[1]; rotateType = beginTypeList[2]; alphaType = beginTypeList[3]; }
public void Copy(Attribute attribute) { if ((attribute == this) || (attribute == null)) { return; } TweenName = attribute.TweenName; EaseType = attribute.EaseType; To = attribute.To; Color = attribute.Color; Fade = attribute.Fade; ToText = attribute.ToText; FromPos = attribute.FromPos; FromColor = attribute.FromColor; FromFade = attribute.FromFade; Duration = attribute.Duration; DelayTime = attribute.DelayTime; Loop = attribute.Loop; LoopType = attribute.LoopType; TweenType = attribute.TweenType; isNeedFrom = attribute.isNeedFrom; }
public static float2 Tween(float2 xy, TweenType startX, TweenType stopX, TweenType startY, TweenType stopY, BlendType blend) { return(new float2(Tween(new Sample <float>(xy.x, 1), startX, stopX, blend).Value, Tween(new Sample <float>(xy.y, 1), startY, stopY, blend).Value)); }
override protected void _onUpdateFrame() { base._onUpdateFrame(); var tweenProgress = 0.0f; if (_tweenColor != TweenType.None) { if (_tweenColor == TweenType.Once) { _tweenColor = TweenType.None; tweenProgress = 0.0f; } else { tweenProgress = _tweenProgress; } var currentColor = _currentFrame.color; _color.alphaMultiplier = currentColor.alphaMultiplier + _durationColor.alphaMultiplier * tweenProgress; _color.redMultiplier = currentColor.redMultiplier + _durationColor.redMultiplier * tweenProgress; _color.greenMultiplier = currentColor.greenMultiplier + _durationColor.greenMultiplier * tweenProgress; _color.blueMultiplier = currentColor.blueMultiplier + _durationColor.blueMultiplier * tweenProgress; _color.alphaOffset = currentColor.alphaOffset + (int)(_durationColor.alphaOffset * tweenProgress); _color.redOffset = currentColor.redOffset + (int)(_durationColor.redOffset * tweenProgress); _color.greenOffset = currentColor.greenOffset + (int)(_durationColor.greenOffset * tweenProgress); _color.blueOffset = currentColor.blueOffset + (int)(_durationColor.blueOffset * tweenProgress); _colorDirty = true; } }
public static Fade Create(float time, TweenType tweenType, ColorF color) { Ensure.True(time >= 0f); return(new Fade { Time = time, TweenType = tweenType, Color = color }); }
override protected void _onUpdateFrame() { base._onUpdateFrame(); var tweenProgress = 0.0f; if (_tweenFFD != TweenType.None) { if (_tweenFFD == TweenType.Once) { _tweenFFD = TweenType.None; tweenProgress = 0.0f; } else { tweenProgress = _tweenProgress; } var currentFFDVertices = _currentFrame.tweens; for (int i = 0, l = currentFFDVertices.Count; i < l; ++i) { _ffdVertices[i] = currentFFDVertices[i] + _durationFFDVertices[i] * tweenProgress; } _ffdDirty = true; } }
public static bool IsContinuous(TweenType tween) { return(tween == TweenType.LinearContinuous || tween == TweenType.QuadraticContinuous || tween == TweenType.SineContinuous || tween == TweenType.BumpContinuous); }
private static int IntToEnum(IntPtr L) { int num = (int)LuaDLL.lua_tonumber(L, 1); TweenType tweenType = (TweenType)num; ToLua.Push(L, tweenType); return(1); }
/// <summary> /// adds a tween that will start as soon as this tween completes /// </summary> public Tween next(Transform trans, TweenType tweenType, float duration, Vector3 targetVector, float delay = 0, EaseFunction easeFunction = null, bool isRelativeTween = false) { var tween = GoKitLite.instance.vectorTweenTo(trans, tweenType, duration, targetVector, delay, easeFunction, isRelativeTween); nextTween = tween; return(tween); }
public void PositionXYZEaseDelay(GameObject targetObject, EaseType type, TweenType tweentype, float start, float end, float delay, float duration, bool isLocal = false, EventHandler hdr = null) { TweenInformation info = new TweenInformation(); info.SetTweenValue(type, tweentype, targetObject, duration, delay, isLocal, hdr, new Vector2(start, end)); _tweenObjectList.Add(info); }
public TweenOperation(AnimationCurve aniCurve, float velocity, TweenType type, Action <float> tweenFun) { m_tweenType = type; m_aniCurve = aniCurve; m_velocity = velocity; m_tweenFun = tweenFun; m_totalTween = m_aniCurve.keys[m_aniCurve.length - 1].time; }
/// <summary> /// 获取动画曲线 /// </summary> /// <param name="tweenType"></param> /// <returns></returns> public AnimationCurve GetEase(TweenType tweenType) { if (animationCurveDic.ContainsKey(tweenType)) { return(animationCurveDic[tweenType]); } return(null); }
public Tween(float duration, TweenType type, Action onComplete, Func<float, float> onEase) { m_timeScale = 0; m_duration = duration; m_type = type; m_onComplete = onComplete; m_onEase = onEase; }
public void SetPosition(Vector2 newPosition) { this.Position = newPosition; this.PositionFrom = newPosition; this.PositionGoTO = newPosition; tweenType = TweenType.Instant; currentStep = 0; tweenSteps = 0; }
public TweenTrans1(float a1, float a2, TweenType tween, double endTime) { Enabled = true; A1 = a1; A2 = a2; StartTime = Engine.Time - 1.0; EndTime = endTime - 1.0; Tween = tween; }
/// <summary> /// Removes the Tween component on the given GameObject with the given TweenType /// </summary> public static void RemoveTween(GameObject obj, TweenType tweenType) { Tween tweenObject = GetTween(obj, tweenType); if (tweenObject != null) { Destroy(tweenObject); } }
public Alarm(double totalSeconds, TweenType type = TweenType.OneShot, AlarmFinished alarmFinished = null) { this.alarmStart = false; this.currentSeconds = totalSeconds; this.totalSeconds = totalSeconds; this.alarmFinished = alarmFinished; this.tweenType = type; this.SpeedFactor = 1; }
public static TweenFunc Create(TweenType tweenType, double startValue, double endValue, double duration, TweenCallback finished = null) { var time = 0.0; var called = false; return overrideTimer => { var t = overrideTimer != null ? overrideTimer.Value : (time = Math.Min(time + GameOptions.Timestep, duration)); if (t >= duration && !called && finished != null) { called = true; finished(); } return (TweenMain(tweenType, t, duration) / (1 / (endValue - startValue))) + startValue; }; }
public Tween(IEasing easing, TweenType easingType = TweenType.In) { _name = easing.Name; _type = easingType; switch (easingType) { case TweenType.In: _easing = easing.In; break; case TweenType.Out: _easing = easing.Out; break; case TweenType.OutIn: _easing = easing.OutIn; break; default: throw new ArgumentException("easingType must be one of [Tween.TweenType.In, Tween.TweenType.Out, Tween.TweenType.OutIn]. Value: " + easingType); } StartTime = 0; EndTime = 1000; StartValue = 0; EndValue = 1; }
/// <summary> /// adds a tween that will start as soon as this tween completes /// </summary> public Tween next( Transform trans, TweenType tweenType, float duration, Vector3 targetVector, bool isRelativeTween = false ) { var tween = GoKitLite.instance.vectorTweenTo( trans, tweenType, duration, targetVector, isRelativeTween ); tween.delay = delay; nextTween = tween; return tween; }
/// <summary> /// adds a tween that will start as soon as this tween completes /// </summary> public Tween next( Transform trans, TweenType tweenType, float duration, Vector3 targetVector, float delay = 0, EaseFunction easeFunction = null, bool isRelativeTween = false ) { var tween = GoKitLite.instance.vectorTweenTo( trans, tweenType, duration, targetVector, delay, easeFunction, isRelativeTween ); nextTween = tween; return tween; }
internal Tween vectorTweenTo( Transform trans, TweenType tweenType, float duration, Vector3 targetVector, bool isRelativeTween = false ) { var tween = nextAvailableTween( trans, duration, tweenType ); tween.targetVector = targetVector; tween.isRelativeTween = isRelativeTween; return tween; }
/// <summary> /// Completely resets the Tweener except its target, /// and applies a new <see cref="TweenType"/>, duration, and <see cref="TweenParms"/>. /// </summary> /// <param name="p_tweenType">New tween type (to/from)</param> /// <param name="p_newDuration">New duration</param> /// <param name="p_newParms">New parameters</param> public void ResetAndChangeParms(TweenType p_tweenType, float p_newDuration, TweenParms p_newParms) { if (_destroyed) { TweenWarning.Log("ResetAndChangeParms can't run because the tween was destroyed - set AutoKill or autoKillOnComplete to FALSE if you want to avoid destroying a tween after completion"); return; } Reset(); _duration = p_newDuration; if (p_tweenType == TweenType.From) p_newParms = p_newParms.IsFrom(); p_newParms.InitializeObject(this, _target); if (plugins != null && plugins.Count > 0) { // Valid plugins were added: mark this as not empty anymore. _isEmpty = false; } SetFullDuration(); }
/// <summary> /// Jump to a position in the scroller based on a dataIndex. This overload allows you /// to specify a specific offset within a cell as well. /// </summary> /// <param name="dataIndex">he data index to jump to</param> /// <param name="scrollerOffset">The offset from the start (top / left) of the scroller in the range 0..1. /// Outside this range will jump to the location before or after the scroller's viewable area</param> /// <param name="cellOffset">The offset from the start (top / left) of the cell in the range 0..1</param> /// <param name="useSpacing">Whether to calculate in the spacing of the scroller in the jump</param> /// <param name="tweenType">What easing to use for the jump</param> /// <param name="tweenTime">How long to interpolate to the jump point</param> /// <param name="jumpComplete">This delegate is fired when the jump completes</param> public void JumpToDataIndex(int dataIndex, float scrollerOffset = 0, float cellOffset = 0, bool useSpacing = true, TweenType tweenType = TweenType.immediate, float tweenTime = 0f, Action jumpComplete = null ) { var cellOffsetPosition = 0f; if (cellOffset != 0) { // calculate the cell offset position // get the cell's size var cellSize = (_delegate != null ? _delegate.GetCellViewSize(this, dataIndex) : 0); if (useSpacing) { // if using spacing add spacing from one side cellSize += spacing; // if this is not a bounday cell, then add spacing from the other side if (dataIndex > 0 && dataIndex < (NumberOfCells - 1)) cellSize += spacing; } // calculate the position based on the size of the cell and the offset within that cell cellOffsetPosition = cellSize * cellOffset; } var newScrollPosition = 0f; // cache the offset for quicker calculation var offset = -(scrollerOffset * ScrollRectSize) + cellOffsetPosition; if (loop) { // if looping, then we need to determine the closest jump position. // we do that by checking all three sets of data locations, and returning the closest one // get the scroll positions for each data set. // Note: we are calculating the position based on the cell view index, not the data index here var set1Position = GetScrollPositionForCellViewIndex(dataIndex, CellViewPositionEnum.Before) + offset; var set2Position = GetScrollPositionForCellViewIndex(dataIndex + NumberOfCells, CellViewPositionEnum.Before) + offset; var set3Position = GetScrollPositionForCellViewIndex(dataIndex + (NumberOfCells * 2), CellViewPositionEnum.Before) + offset; // get the offsets of each scroll position from the current scroll position var set1Diff = (Mathf.Abs(_scrollPosition - set1Position)); var set2Diff = (Mathf.Abs(_scrollPosition - set2Position)); var set3Diff = (Mathf.Abs(_scrollPosition - set3Position)); // choose the smallest offset from the current position (the closest position) if (set1Diff < set2Diff) { if (set1Diff < set3Diff) { newScrollPosition = set1Position; } else { newScrollPosition = set3Position; } } else { if (set2Diff < set3Diff) { newScrollPosition = set2Position; } else { newScrollPosition = set3Position; } } } else { // not looping, so just get the scroll position from the dataIndex newScrollPosition = GetScrollPositionForDataIndex(dataIndex, CellViewPositionEnum.Before) + offset + _contentOffset; } // clamp the scroll position to a valid location newScrollPosition = Mathf.Clamp(newScrollPosition, 0, GetScrollPositionForCellViewIndex(_cellViewSizeArray.Count - 1, CellViewPositionEnum.Before)); // if spacing is used, adjust the final position if (useSpacing) { // move back by the spacing if necessary newScrollPosition = Mathf.Clamp(newScrollPosition - spacing, 0, GetScrollPositionForCellViewIndex(_cellViewSizeArray.Count - 1, CellViewPositionEnum.Before)); } // start tweening StartCoroutine(TweenPosition(tweenType, tweenTime, ScrollPosition, newScrollPosition, jumpComplete)); }
/// <summary> /// Generates a set of AnimationCurve keys from a tween type /// Only needed if you want to create your own AnimationCurves from tween functions /// </summary> /// <param name="tweenType"></param> /// <returns>The generated keyset</returns> public static float[][] GetAnimCurveKeys(TweenType tweenType) { float[][] keys; if (tweenType == TweenType.Linear) { keys = new[] { new[] { 0, 0f }, new[] { 1f, 1f } }; } else { keys = new[] { new[] { 0, 0f }, new[] { 0.1f, 0f }, new[] { 0.2f, 0f }, new[] { 0.3f, 0f }, new[] { 0.4f, 0f }, new[] { 0.5f, 0f }, new[] { 0.6f, 0f }, new[] { 0.7f, 0f }, new[] { 0.8f, 0f }, new[] { 0.9f, 0f }, new[] { 1f, 0f } }; } const float start = 0f; const float end = 1f; float keyLength = keys.Length; switch (tweenType) { case TweenType.Overshoot: for (int i = 0; i < keys.Length; i++) { keys[i][1] = Overshoot(start, end, i / keyLength, end); } break; case TweenType.Bounce: for (int i = 0; i < keys.Length; i++) { keys[i][1] = Bounce(start, end, i / keyLength, end); } break; case TweenType.EaseInCubed: for (int i = 0; i < keys.Length; i++) { keys[i][1] = CubeIn(start, end, i / keyLength, end); } break; case TweenType.EaseOutCubed: for (int i = 0; i < keys.Length; i++) { keys[i][1] = CubeOut(start, end, i / keyLength, end); } break; case TweenType.SoftEaseOutCubed: for (int i = 0; i < keys.Length; i++) { keys[i][1] = CubeSoftOut(start, end, i / keyLength, end); } break; case TweenType.EaseInOutCubed: for (int i = 0; i < keys.Length; i++) { keys[i][1] = CubeInOut(start, end, i / keyLength, end); } break; case TweenType.EaseInQuint: for (int i = 0; i < keys.Length; i++) { keys[i][1] = QuintIn(start, end, i / keyLength, end); } break; case TweenType.EaseOutQuint: for (int i = 0; i < keys.Length; i++) { keys[i][1] = QuintOut(start, end, i / keyLength, end); } break; case TweenType.SoftEaseOutQuint: for (int i = 0; i < keys.Length; i++) { keys[i][1] = QuintSoftOut(start, end, i / keyLength, end); } break; case TweenType.EaseInOutQuint: for (int i = 0; i < keys.Length; i++) { keys[i][1] = QuintInOut(start, end, i / keyLength, end); } break; case TweenType.EaseInSept: for (int i = 0; i < keys.Length; i++) { keys[i][1] = SeptIn(start, end, i / keyLength, end); } break; case TweenType.EaseOutSept: for (int i = 0; i < keys.Length; i++) { keys[i][1] = SeptOut(start, end, i / keyLength, end); } break; case TweenType.SoftEaseOutSept: for (int i = 0; i < keys.Length; i++) { keys[i][1] = SeptSoftOut(start, end, i / keyLength, end); } break; case TweenType.EaseInOutSept: for (int i = 0; i < keys.Length; i++) { keys[i][1] = SeptInOut(start, end, i / keyLength, end); } break; } return keys; }
/// <summary> /// Get an instance of the given tween function /// </summary> /// <param name="progressMode"></param> /// <returns></returns> public static TweenMethods.TweenFunction GetTweenFunction(TweenType progressMode) { TweenMethods.TweenFunction tweenFunction = null; switch (progressMode) { case TweenType.easeInQuad: tweenFunction = TweenMethods.easeInQuad; break; case TweenType.easeOutQuad: tweenFunction = TweenMethods.easeOutQuad; break; case TweenType.easeInOutQuad: tweenFunction = TweenMethods.easeInOutQuad; break; case TweenType.easeInCubic: tweenFunction = TweenMethods.easeInCubic; break; case TweenType.easeOutCubic: tweenFunction = TweenMethods.easeOutCubic; break; case TweenType.easeInOutCubic: tweenFunction = TweenMethods.easeInOutCubic; break; case TweenType.easeInQuart: tweenFunction = TweenMethods.easeInQuart; break; case TweenType.easeOutQuart: tweenFunction = TweenMethods.easeOutQuart; break; case TweenType.easeInOutQuart: tweenFunction = TweenMethods.easeInOutQuart; break; case TweenType.easeInQuint: tweenFunction = TweenMethods.easeInQuint; break; case TweenType.easeOutQuint: tweenFunction = TweenMethods.easeOutQuint; break; case TweenType.easeInOutQuint: tweenFunction = TweenMethods.easeInOutQuint; break; case TweenType.easeInSine: tweenFunction = TweenMethods.easeInSine; break; case TweenType.easeOutSine: tweenFunction = TweenMethods.easeOutSine; break; case TweenType.easeInOutSine: tweenFunction = TweenMethods.easeInOutSine; break; case TweenType.easeInExpo: tweenFunction = TweenMethods.easeInExpo; break; case TweenType.easeOutExpo: tweenFunction = TweenMethods.easeOutExpo; break; case TweenType.easeInOutExpo: tweenFunction = TweenMethods.easeInOutExpo; break; case TweenType.easeInCirc: tweenFunction = TweenMethods.easeInCirc; break; case TweenType.easeOutCirc: tweenFunction = TweenMethods.easeOutCirc; break; case TweenType.easeInOutCirc: tweenFunction = TweenMethods.easeInOutCirc; break; case TweenType.linear: tweenFunction = TweenMethods.linear; break; case TweenType.spring: tweenFunction = TweenMethods.spring; break; /* GFX47 MOD START */ /*case TransitionHelper.TweenType.bounce: ease = new EasingFunction(bounce); break;*/ case TweenType.easeInBounce: tweenFunction = TweenMethods.easeInBounce; break; case TweenType.easeOutBounce: tweenFunction = TweenMethods.easeOutBounce; break; case TweenType.easeInOutBounce: tweenFunction = TweenMethods.easeInOutBounce; break; /* GFX47 MOD END */ case TweenType.easeInBack: tweenFunction = TweenMethods.easeInBack; break; case TweenType.easeOutBack: tweenFunction = TweenMethods.easeOutBack; break; case TweenType.easeInOutBack: tweenFunction = TweenMethods.easeInOutBack; break; /* GFX47 MOD START */ /*case TransitionHelper.TweenType.elastic: ease = new EasingFunction(elastic); break;*/ case TweenType.easeInElastic: tweenFunction = TweenMethods.easeInElastic; break; case TweenType.easeOutElastic: tweenFunction = TweenMethods.easeOutElastic; break; case TweenType.easeInOutElastic: tweenFunction = TweenMethods.easeInOutElastic; break; /* GFX47 MOD END */ } return tweenFunction; }
private Tween nextAvailableTween( Transform trans, float duration, TweenType tweenType ) { Tween tween = null; if( _inactiveTweenStack.Count > 0 ) tween = _inactiveTweenStack.Pop(); else tween = new Tween(); tween.id = ++_tweenIdCounter; tween.transform = trans; tween.duration = duration; tween.tweenType = tweenType; return tween; }
/// <summary> /// Moves the scroll position over time between two points given an easing function. When the /// tween is complete it will fire the jumpComplete delegate. /// </summary> /// <param name="tweenType">The type of easing to use</param> /// <param name="time">The amount of time to interpolate</param> /// <param name="start">The starting scroll position</param> /// <param name="end">The ending scroll position</param> /// <param name="jumpComplete">The action to fire when the tween is complete</param> /// <returns></returns> protected IEnumerator TweenPosition(TweenType tweenType, float time, float start, float end, Action tweenComplete) { if (tweenType == TweenType.immediate || time == 0) { // if the easing is immediate or the time is zero, just jump to the end position ScrollPosition = end; } else { // zero out the velocity _scrollRect.velocity = Vector2.zero; // fire the delegate for the tween start IsTweening = true; if (scrollerTweeningChanged != null) scrollerTweeningChanged(this, true); _tweenTimeLeft = 0; var newPosition = 0f; // while the tween has time left, use an easing function while (_tweenTimeLeft < time) { switch (tweenType) { case TweenType.linear: newPosition = linear(start, end, (_tweenTimeLeft / time)); break; case TweenType.spring: newPosition = spring(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInQuad: newPosition = easeInQuad(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutQuad: newPosition = easeOutQuad(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutQuad: newPosition = easeInOutQuad(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInCubic: newPosition = easeInCubic(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutCubic: newPosition = easeOutCubic(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutCubic: newPosition = easeInOutCubic(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInQuart: newPosition = easeInQuart(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutQuart: newPosition = easeOutQuart(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutQuart: newPosition = easeInOutQuart(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInQuint: newPosition = easeInQuint(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutQuint: newPosition = easeOutQuint(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutQuint: newPosition = easeInOutQuint(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInSine: newPosition = easeInSine(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutSine: newPosition = easeOutSine(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutSine: newPosition = easeInOutSine(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInExpo: newPosition = easeInExpo(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutExpo: newPosition = easeOutExpo(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutExpo: newPosition = easeInOutExpo(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInCirc: newPosition = easeInCirc(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutCirc: newPosition = easeOutCirc(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutCirc: newPosition = easeInOutCirc(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInBounce: newPosition = easeInBounce(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutBounce: newPosition = easeOutBounce(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutBounce: newPosition = easeInOutBounce(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInBack: newPosition = easeInBack(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutBack: newPosition = easeOutBack(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutBack: newPosition = easeInOutBack(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInElastic: newPosition = easeInElastic(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeOutElastic: newPosition = easeOutElastic(start, end, (_tweenTimeLeft / time)); break; case TweenType.easeInOutElastic: newPosition = easeInOutElastic(start, end, (_tweenTimeLeft / time)); break; } if (loop) { // if we are looping, we need to make sure the new position isn't past the jump trigger. // if it is we need to reset back to the jump position on the other side of the area. if (end > start && newPosition > _loopLastJumpTrigger) { //Debug.Log("name: " + name + " went past the last jump trigger, looping back around"); newPosition = _loopFirstScrollPosition + (newPosition - _loopLastJumpTrigger); } else if (start > end && newPosition < _loopFirstJumpTrigger) { //Debug.Log("name: " + name + " went past the first jump trigger, looping back around"); newPosition = _loopLastScrollPosition - (_loopFirstJumpTrigger - newPosition); } } // set the scroll position to the tweened position ScrollPosition = newPosition; // increase the time elapsed _tweenTimeLeft += Time.unscaledDeltaTime; yield return null; } // the time has expired, so we make sure the final scroll position // is the actual end position. ScrollPosition = end; } // the tween jump is complete, so we fire the delegate if (tweenComplete != null) tweenComplete(); // fire the delegate for the tween ending IsTweening = false; if (scrollerTweeningChanged != null) scrollerTweeningChanged(this, false); }
private static double TweenMain(TweenType tweenType, double t, double d, double b = 0, double c = 1) { var backS = BackAmount; switch (tweenType) { case TweenType.Linear: return c * t / d + b; case TweenType.InQuad: return c * (t /= d) * t + b; case TweenType.OutQuad: return -c * (t /= d) * (t - 2) + b; case TweenType.InOutQuad: if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; case TweenType.InCubic: return c * (t /= d) * t * t + b; case TweenType.OutCubic: return c * ((t = t / d - 1) * t * t + 1) + b; case TweenType.InOutCubic: if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; case TweenType.InQuart: return c * (t /= d) * t * t * t + b; case TweenType.OutQuart: return -c * ((t = t / d - 1) * t * t * t - 1) + b; case TweenType.InOutQuart: if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; case TweenType.InQuint: return c * (t /= d) * t * t * t * t + b; case TweenType.OutQuint: return c * ((t = t / d - 1) * t * t * t * t + 1) + b; case TweenType.InOutQuint: if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; case TweenType.InSine: return -c * Math.Cos(t / d * (Math.PI / 2)) + c + b; case TweenType.OutSine: return c * Math.Sin(t / d * (Math.PI / 2)) + b; case TweenType.InOutSine: return -c / 2 * (Math.Cos(Math.PI * t / d) - 1) + b; case TweenType.InExpo: return (t <= 0) ? b : c * Math.Pow(2, 10 * (t / d - 1)) + b; case TweenType.OutExpo: return (t >= d) ? b + c : c * (-Math.Pow(2, -10 * t / d) + 1) + b; case TweenType.InOutExpo: if (t <= 0) return b; if (t >= d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Math.Pow(2, 10 * (t - 1)) + b; return c / 2 * (-Math.Pow(2, -10 * --t) + 2) + b; case TweenType.InCirc: return -c * (Math.Sqrt(1 - (t /= d) * t) - 1) + b; case TweenType.OutCirc: return c * Math.Sqrt(1 - (t = t / d - 1) * t) + b; case TweenType.InOutCirc: if ((t /= d / 2) < 1) return -c / 2 * (Math.Sqrt(1 - t * t) - 1) + b; return c / 2 * (Math.Sqrt(1 - (t -= 2) * t) + 1) + b; case TweenType.InElastic: { double s; var p = d * 0.3; var a = c; if (t <= 0) return b; if ((t /= d) >= 1) return b + c; if (a < Math.Abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.Asin(c / a); return -(a * Math.Pow(2, 10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b; } case TweenType.OutElastic: { double s; var p = d * .3; var a = c; if (t <= 0) return b; if ((t /= d) >= 1) return b + c; if (a < Math.Abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.Asin(c / a); return a * Math.Pow(2, -10 * t) * Math.Sin((t * d - s) * (2 * Math.PI) / p) + c + b; } case TweenType.InOutElastic: { double s; var p = d * (.3 * 1.5); var a = c; if (t <= 0) return b; if ((t /= d / 2) >= 2) return b + c; if (a < Math.Abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.Asin(c / a); if (t < 1) return -.5 * (a * Math.Pow(2, 10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p)) + b; return a * Math.Pow(2, -10 * (t -= 1)) * Math.Sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; } case TweenType.InBounce: { var outBounce = Create(TweenType.OutBounce, 0, c, d); return c - outBounce(d - t) + b; } case TweenType.OutBounce: if ((t /= d) < (1 / 2.75)) return c * (7.5625 * t * t) + b; if (t < (2 / 2.75)) return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; if (t < (2.5 / 2.75)) return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; case TweenType.InOutBounce: { var inBounce = Create(TweenType.InBounce, 0, c, d); var outBounce = Create(TweenType.OutBounce, 0, c, d); if (t < d / 2) return inBounce(t * 2) * .5 + b; return outBounce(t * 2 - d) * .5 + c * .5 + b; } case TweenType.InBack: return c * (t /= d) * t * ((backS + 1) * t - backS) + b; case TweenType.OutBack: return c * ((t = t / d - 1) * t * ((backS + 1) * t + backS) + 1) + b; case TweenType.InOutBack: if ((t /= d / 2) < 1) return c / 2 * (t * t * (((backS *= (1.525)) + 1) * t - backS)) + b; return c / 2 * ((t -= 2) * t * (((backS *= (1.525)) + 1) * t + backS) + 2) + b; default: return b; } }
/// <summary> /// Returns a float evaluated from a TweenType curve or AnimationCurve /// </summary> /// <param name="type">The TweenType to use, set to 'Custom' to use an AnimationCurve</param> /// <param name="startValue">The start value of the tween</param> /// <param name="endValue">Th end value of the tween</param> /// <param name="time">The current time in the tween</param> /// <param name="duration">The duration of the tween</param> /// <param name="curve">The custom AnimationCurve to use, if desired</param> /// <returns>The calulated value</returns> public static float Evaluate(TweenType type, float startValue, float endValue, float time, float duration, AnimationCurve curve = null) { switch (type) { case TweenType.Linear: return Linear(startValue, endValue, time, duration); case TweenType.Overshoot: return Overshoot(startValue, endValue, time, duration); case TweenType.Bounce: return Bounce(startValue, endValue, time, duration); case TweenType.EaseInCubed: return CubeIn(startValue, endValue, time, duration); case TweenType.EaseInQuint: return QuintIn(startValue, endValue, time, duration); case TweenType.EaseInSept: return SeptIn(startValue, endValue, time, duration); case TweenType.EaseOutCubed: return CubeOut(startValue, endValue, time, duration); case TweenType.EaseOutQuint: return QuintOut(startValue, endValue, time, duration); case TweenType.EaseOutSept: return SeptOut(startValue, endValue, time, duration); case TweenType.EaseInOutCubed: return CubeInOut(startValue, endValue, time, duration); case TweenType.EaseInOutQuint: return QuintInOut(startValue, endValue, time, duration); case TweenType.EaseInOutSept: return SeptInOut(startValue, endValue, time, duration); case TweenType.SoftEaseOutCubed: return CubeSoftOut(startValue, endValue, time, duration); case TweenType.SoftEaseOutQuint: return QuintSoftOut(startValue, endValue, time, duration); case TweenType.SoftEaseOutSept: return SeptSoftOut(startValue, endValue, time, duration); case TweenType.Custom: return (endValue - startValue) * curve.Evaluate(time / duration) + startValue; } return 0f; }
internal Tween vectorTweenTo( Transform trans, TweenType tweenType, float duration, Vector3 targetVector, float delay = 0, EaseFunction easeFunction = null, bool isRelativeTween = false ) { var tween = nextAvailableTween( trans, duration, tweenType ); tween.delay = delay; tween.targetVector = targetVector; tween.easeFunction = easeFunction; tween.isRelativeTween = isRelativeTween; return tween; }