Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Pause
 /// </summary>
 public void Pause()
 {
     if (AudioSource != null)
     {
         AudioSource.Pause();
     }
     delayDestroyGameObjectTask?.Release();
     delayDestroyGameObjectTask = null;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Stop
 /// </summary>
 public void Stop()
 {
     if (AudioSource != null)
     {
         AudioSource.Stop();
     }
     delayDestroyGameObjectTask?.Release();
     delayDestroyGameObjectTask = null;
     Dispose();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Play
        /// </summary>
        public void Play()
        {
            if (AudioSource != null)
            {
                AudioSource.Play();
            }

            if (!Loop)
            {
                delayDestroyGameObjectTask = DelayTask.Invoke(() =>
                {
                    Stop();
                }, (int)(AudioClip.length * 1000));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 释放某个任务
 /// </summary>
 /// <param name="delayTask"></param>
 public static void Release(DelayTask delayTask)
 {
     delayTask.taskLite.Release();
 }