using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScheduleOnce : UnitySingleton<ScheduleOnce>
{
int id = 0;
Dictionary<int, Coroutine> dic = new Dictionary<int, Coroutine>();
public int AddSchedule(float time, Action<object> action,params object[] arr)
{
int name = id++;
Coroutine coroutine = StartCoroutine(DelayFun(name, time, action,arr));
dic.Add(name, coroutine);
return id;
}
//携程函數
IEnumerator DelayFun(int name, float time, Action<object> action, params object[] arr)
{
yield return new WaitForSeconds(time);
action(arr);
StopSchedule(name);
}
public int AddSchedule(float time, Action action)
{
int name = id++;
Coroutine coroutine = StartCoroutine(DelayFun( name, time, action));
dic.Add(name, coroutine);
return id;
}
//携程函數
IEnumerator DelayFun(int name, float time, Action action)
{
yield return new WaitForSeconds(time);
action();
StopSchedule(name);
}
public void StopSchedule(int name)
{
if (dic.ContainsKey(name))
{
StopCoroutine(dic[name]);
dic.Remove(name);
}
}
}
unity下携程延时器
最新推荐文章于 2024-06-05 11:09:50 发布