/// <summary> /// 压入一个延迟函数,按照时间来延迟 /// </summary> /// <param name="task"></param> /// <param name="delayTime">延迟时间,单位:ms毫秒</param> /// <param name="type"></param> /// <param name="tag"></param> /// <returns></returns> public static DelayTask Invoke(Action task, int delayTime, object tag = null) { var delayTask = new DelayTask { Task = task, Delay = delayTime, Type = DelayType.Time, Tag = tag }; delayTask.taskLite = TaskLite.Invoke(t => { if (t < delayTime) { return(false); } task(); return(true); }); m_tasks.Add(delayTask); return(delayTask); }
/// <summary> /// Pause /// </summary> public void Pause() { if (AudioSource != null) { AudioSource.Pause(); } delayDestroyGameObjectTask?.Release(); delayDestroyGameObjectTask = null; }
/// <summary> /// Stop /// </summary> public void Stop() { if (AudioSource != null) { AudioSource.Stop(); } delayDestroyGameObjectTask?.Release(); delayDestroyGameObjectTask = null; Dispose(); }
/// <summary> /// Play /// </summary> public void Play() { if (AudioSource != null) { AudioSource.Play(); } if (!Loop) { delayDestroyGameObjectTask = DelayTask.Invoke(() => { Stop(); }, (int)(AudioClip.length * 1000)); } }
/// <summary> /// 释放某个任务 /// </summary> /// <param name="delayTask"></param> public static void Release(DelayTask delayTask) { delayTask.taskLite.Release(); }