1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 17:26:03 +08:00
2015-05-27 13:01:57 +02:00

67 lines
2.8 KiB
C#

// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2014/05/06 16:33
//
// License Copyright (c) Daniele Giardini.
// This work is subject to the terms at http://dotween.demigiant.com/license.php
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;
using UnityEngine;
#pragma warning disable 1591
namespace DG.Tweening.Plugins
{
public class FloatPlugin : ABSTweenPlugin<float,float,FloatOptions>
{
public override void Reset(TweenerCore<float, float, FloatOptions> t) { }
public override void SetFrom(TweenerCore<float, float, FloatOptions> t, bool isRelative)
{
float prevEndVal = t.endValue;
t.endValue = t.getter();
t.startValue = isRelative ? t.endValue + prevEndVal : prevEndVal;
t.setter(!t.plugOptions.snapping ? t.startValue : (float)Math.Round(t.startValue));
}
public override float ConvertToStartValue(TweenerCore<float, float, FloatOptions> t, float value)
{
return value;
}
public override void SetRelativeEndValue(TweenerCore<float, float, FloatOptions> t)
{
t.endValue += t.startValue;
}
public override void SetChangeValue(TweenerCore<float, float, FloatOptions> t)
{
t.changeValue = t.endValue - t.startValue;
}
public override float GetSpeedBasedDuration(FloatOptions options, float unitsXSecond, float changeValue)
{
float res = changeValue / unitsXSecond;
if (res < 0) res = -res;
return res;
}
public override void EvaluateAndApply(FloatOptions options, Tween t, bool isRelative, DOGetter<float> getter, DOSetter<float> setter, float elapsed, float startValue, float 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(
!options.snapping
? startValue + changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod)
: (float)Math.Round(startValue + changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod))
);
}
}
}