1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-21 01:36:05 +08:00

64 lines
2.5 KiB
C#

// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/03/29 22:56
using System;
using DG.Tweening.Core;
using DG.Tweening.Core.Easing;
using DG.Tweening.Core.Enums;
using DG.Tweening.Plugins.Core;
using DG.Tweening.Plugins.Options;
#pragma warning disable 1591
namespace DG.Tweening.Plugins
{
public class LongPlugin : ABSTweenPlugin<long, long, NoOptions>
{
public override void Reset(TweenerCore<long, long, NoOptions> t) { }
public override void SetFrom(TweenerCore<long, long, NoOptions> t, bool isRelative)
{
long prevEndVal = t.endValue;
t.endValue = t.getter();
t.startValue = isRelative ? t.endValue + prevEndVal : prevEndVal;
t.setter(t.startValue);
}
public override void SetFrom(TweenerCore<long, long, NoOptions> t, long fromValue, bool setImmediately)
{
t.startValue = fromValue;
if (setImmediately) t.setter(fromValue);
}
public override long ConvertToStartValue(TweenerCore<long, long, NoOptions> t, long value)
{
return value;
}
public override void SetRelativeEndValue(TweenerCore<long, long, NoOptions> t)
{
t.endValue += t.startValue;
}
public override void SetChangeValue(TweenerCore<long, long, NoOptions> t)
{
t.changeValue = t.endValue - t.startValue;
}
public override float GetSpeedBasedDuration(NoOptions options, float unitsXSecond, long changeValue)
{
float res = changeValue / unitsXSecond;
if (res < 0) res = -res;
return res;
}
public override void EvaluateAndApply(NoOptions options, Tween t, bool isRelative, DOGetter<long> getter, DOSetter<long> setter, float elapsed, long startValue, long changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice)
{
if (t.loopType == LoopType.Incremental) startValue += changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops);
if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) {
startValue += changeValue * (t.loopType == LoopType.Incremental ? t.loops : 1)
* (t.sequenceParent.isComplete ? t.sequenceParent.completedLoops - 1 : t.sequenceParent.completedLoops);
}
setter((long)Math.Round(startValue + changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod)));
}
}
}