Ejemplo n.º 1
0
    //替换任务
    public bool ReplaceTimeTask(Action <int> callback, float delay, PEtimeUnit timeUnit = PEtimeUnit.Second, int count = 1)
    {
        switch (timeUnit)
        {
        case PEtimeUnit.MilliSecond:
            delay = delay / 1000;
            break;

        case PEtimeUnit.Second:
            //delay = delay;
            break;

        case PEtimeUnit.Minute:
            delay = delay * 60;
            break;

        case PEtimeUnit.Hour:
            delay = delay * 60 * 60;
            break;

        case PEtimeUnit.Day:
            delay = delay * 60 * 60 * 24;
            break;

        default:
            break;
        }
        //触发时间=当前时间(游戏启动到现在经历的时间)+需要延迟的时间
        nowTime = GetUTCSeconds() + delay;
        //新建这个task
        PETimeTask newTask = new PETimeTask(tID, callback, nowTime, delay, count);
        bool       isRep   = false;

        //去任务列表中寻找这个tid的任务,把它替换掉
        for (int i = 0; i < taskTimeList.Count; i++)
        {
            if (taskTimeList[i].tID == tID)
            {
                taskTimeList[i] = newTask;
                isRep           = true;
                break;
            }
        }
        //没有找到的话就去缓存列表里面找
        if (!isRep)
        {
            for (int i = 0; i < tmpTimeList.Count; i++)
            {
                if (tmpTimeList[i].tID == tID)
                {
                    tmpTimeList[i] = newTask;
                    isRep          = true;
                    break;
                }
            }
        }
        return(isRep);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 定时系统任务添加
    /// </summary>
    /// <param name="callback">要执行的任务</param>
    /// <param name="delay">延时时间</param>
    /// <param name="time">时间单位</param>
    /// <param name="count">执行次数(0为执行无数次)</param>
    /// <returns>新建一个任务后返回一个任务ID</returns>
    public int AddTimeTask(Action <int> callback, double delay, PEtimeUnit timeUnit = PEtimeUnit.Second, int count = 1)
    {
        switch (timeUnit)
        {
        case PEtimeUnit.MilliSecond:
            delay = delay / 1000;
            break;

        case PEtimeUnit.Second:
            //delay = delay;
            break;

        case PEtimeUnit.Minute:
            delay = delay * 60;
            break;

        case PEtimeUnit.Hour:
            delay = delay * 60 * 60;
            break;

        case PEtimeUnit.Day:
            delay = delay * 60 * 60 * 24;
            break;

        default:
            break;
        }


        //获得一个唯一的任务ID
        int tID = GetTaskID();

        //触发时间=当前时间(游戏启动到现在经历的时间)+需要延迟的时间
        nowTime = GetUTCSeconds() + delay;

        //新建一个定时任务 给这个任务设定数据

        //增加进缓存任务列表
        tmpTimeList.Add(new PETimeTask(tID, callback, nowTime, delay, count));


        tIDList.Add(tID);
        return(tID);
    }