using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DT : MonoBehaviour
{
float begin;
float end;
float time;
Action<float> action;
Action oncom;
float begintime;
public static DT To(Action<float> action,float begin,float end,float time)
{
GameObject g = new GameObject("DT");
DT dt=g.AddComponent<DT>();
dt.action = action;
dt.begin = begin;
dt.end = end;
dt.time = time;
dt.begintime=Time.time;
return dt;
}
public DT OnCom(Action oncom)
{
this.oncom = oncom;
return this;
}
void Start()
{
}
void Update()
{
if(Time.time-begintime<time)
{
float r=(Time.time-begintime)/time;
float dor = r * (end - begin) + begin;
action(dor);
}
else
{
action(end);
if(oncom!=null) oncom();
Destroy(gameObject);
}
}
}
以上就是手写的dotween