コード例 #1
0
        protected void Update()
        {
            // 这里也要调用一次的原因是,当前帧可能没执行FixedUpdate
            BeginFrame();

            float deltaTime  = Time.deltaTime;
            int   frameCount = Time.frameCount;

            ParallelUpdate(deltaTime);

            for (int iBehaviour = 0; iBehaviour < m_BehavioursForTraverse.Count; iBehaviour++)
            {
                BaseBehaviour iterBehaviour = m_BehavioursForTraverse[iBehaviour];
                if (!iterBehaviour.CanUpdate())
                {
                    continue;
                }

                float behaviourDeltaTime;
                if (iterBehaviour.HasFeature(FeatureFlag.UpdateFrequency))
                {
                    try
                    {
                        if (!iterBehaviour.ControlUpdateFrequency(out behaviourDeltaTime, deltaTime, frameCount))
                        {
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        MDebug.LogError("Core"
                                        , $"Execute {iterBehaviour.GetName()}.ControlUpdateFrequency Exception:{e.ToString()}");
                        continue;
                    }
                }
                else
                {
                    behaviourDeltaTime = deltaTime;
                }

                try
                {
                    MDebug.LogVerbose("Core"
                                      , $"Before execute {iterBehaviour.GetName()}.OnUpdate");

                    iterBehaviour.OnUpdate(behaviourDeltaTime);

                    MDebug.LogVerbose("Core"
                                      , $"After execute {iterBehaviour.GetName()}.OnUpdate");
                }
                catch (Exception e)
                {
                    MDebug.LogError("Core"
                                    , $"Execute {iterBehaviour.GetName()}.OnUpdate Exception:{e.ToString()}");
                }
            }
        }