您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
25 行
592 B
25 行
592 B
using System;
|
|
using UnityEngine;
|
|
|
|
public abstract class Interpolation<T> : MonoBehaviour
|
|
{
|
|
public abstract Func<T, T, float, T> LerpFunction { get;}
|
|
|
|
private (float, T) _last;
|
|
private (float, T) _previous;
|
|
|
|
public T GetValueForTime(float time)
|
|
{
|
|
float timeSincePrevious = time - _previous.Item1;
|
|
float t = (timeSincePrevious / (_last.Item1 - _previous.Item1) - 1f);
|
|
|
|
return LerpFunction(_previous.Item2, _last.Item2, t);
|
|
}
|
|
|
|
public void AddValue(float time, T value)
|
|
{
|
|
_previous = _last;
|
|
_last = (time, value);
|
|
}
|
|
|
|
}
|