Beispiel #1
0
    public MonoEX.Timer Reset(float live)
    {
        if (m_Timer != null)
        {
            m_Timer.Kill();
        }
        m_Timer = new MonoEX.Timer(live)
                  .OnComplete(() => { if (OnComplete != null)
                                      {
                                          OnComplete();
                                      }
                              })
                  .OnKill(() => { if (OnKill != null)
                                  {
                                      OnKill();
                                  }
                          });

        //当前处于启用状态,立即运行
        if (enabled)
        {
            m_Timer.Play();
        }

        return(m_Timer);
    }
Beispiel #2
0
    // ---------------------静态方法-------------------------


    // ---------------------连贯视野--------------------------


    /// <summary>
    /// 对物体进行连续移动
    /// </summary>
    /// <param name="paramList">位移列表</param>
    /// <param name="obj">被位移对象</param>
    /// <param name="frameRate">游戏帧数</param>
    /// <param name="completeCallback">回调方法</param>
    public void MoveAndRotateObj(IList <MoveTarget> paramList, GameObject obj, int frameRate, Action completeCallback)
    {
        // 验证参数有效
        if (obj == null || paramList == null)
        {
            return;
        }
        // 中断
        StopMove();

        // 本地化数据
        var tmpParamEnumerator  = paramList.GetEnumerator();
        var tmpObj              = obj;
        var tmpCompleteCallback = completeCallback;


        MonoEX.TimerCallback tick = null;

        tmpParamEnumerator.MoveNext();

        // tick定义
        tick = () =>
        {
            // 获取迭代器当前对象
            var param = tmpParamEnumerator.Current;
            // 计算移动次数
            if (param != null)
            {
                if (param.MoveObj == null)
                {
                    param.MoveObj = tmpObj;
                }
                if (param.FrameRate == 0)
                {
                    param.FrameRate = frameRate;
                }

                // 是否移动结束
                if (!param.MoveNext())
                {
                    if (tmpParamEnumerator.MoveNext())
                    {
                        // tick
                        _timer = new MonoEX.Timer(TickTime).Play().OnComplete(tick);
                    }
                    else
                    {
                        // 结束回调
                        if (tmpCompleteCallback != null)
                        {
                            tmpCompleteCallback();
                        }
                    }
                }
                else
                {
                    _timer = new MonoEX.Timer(TickTime).Play().OnComplete(tick);
                }
            }
        };

        // 开始tick
        _timer = new MonoEX.Timer(TickTime).Play().OnComplete(tick);
    }