没注释,Update里面代码不理解。。。
代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DT : MonoBehaviour
{
public float beginTime;
public float begin;
public float end;
public float time;
public Action<float> action;
public Action complete;
public static DT To(Action<float> action, float begin, float end, float time)
{
GameObject go = new GameObject("DT");
DT dt = go.AddComponent<DT>();
dt.beginTime = Time.time;
dt.begin = begin;
dt.end = end;
dt.time = time;
dt.action = action;
return dt;
}
public DT OnComplete(Action complete)
{
this.complete = complete;
return this;
}
private void Update()
{
if (Time.time-beginTime<time)
{
float ratio=(Time.time - beginTime)/time;
float offset = ratio * (begin - end) + end;
action(offset);
}
else
{
action(end);
if (complete!=null)
{
complete();
}
Destroy(gameObject);
}
}
}