예제 #1
0
    // update只有在编辑器或者手机上才会生效
    // 如果该代码是运行在其他平台上则标识是验证客户端不需要Update驱动
    // 外面逻辑自己驱动
    #if UNITY_IPHONE || UNITY_ANDROID || UNITY_EDITOR
    /// <summary>
    /// Update this instance.
    /// </summary>
    void Update()
    {
        mFixedModeInternal = true;
        long uf      = (long)FixedDeltaTime;
        bool steping = true;

        // 计算时间差
        long interval = (long)((FixedPrecision(Time.time) - mStartTime) * mPrecision * mTimeScalePrecition);

        // 循环驱动固定协程
        while (uf > 0 && (mFixedTime + uf) <= interval)
        {
            mFixedTime += uf;

            if (steping && mCoroutionFixedList.Count > 0)
            {
                Proxy[] ps = new Proxy[mCoroutionFixedList.Count];
                mCoroutionFixedList.CopyTo(ps, 0);
                int i = 0;

                // 如果mLastProxy不为null,则接着上衣系驱动继续驱动
                if (mLastProxy != null)
                {
                    for (i = 0; i < ps.Length; i++)
                    {
                        if (ps[i] == mLastProxy)
                        {
                            break;
                        }
                    }

                    if (i == ps.Length)
                    {
                        i = 0;
                    }

                    mLastProxy = null;
                }

                // 接着上一次驱动继续StepFixed
                for (; i < ps.Length; i++)
                {
                    Proxy p = ps[i];

                    // StepFixed
                    StepFixed(p);

                    // 时间缩放没有改变
                    long newUF = (long)FixedDeltaTime;
                    if (uf == newUF)
                    {
                        continue;
                    }

                    // 时间缩放改变不能再继续驱动了,记录uf
                    uf = newUF;

                    // 标识steping为false
                    steping = false;

                    // 记录当前驱动位置
                    if (i < ps.Length - 1)
                    {
                        mLastProxy = ps[i + 1];
                    }

                    // 退出驱动
                    break;
                }
            }
        }

        // 标识mFixedModeInternal驱动结束
        mFixedModeInternal = false;

        // 刷新TimeScale
        TimeMgr.RefreshTimeScale();
    }