赞
踩
- 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);
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。