private void UpdateMainThreadMeter() { float allTime = CustomPlayerLoop.GetLastExecuteTime(); float scriptUpdateTime = CustomPlayerLoop.GetProfilingTime <Update.ScriptRunBehaviourUpdate>() + CustomPlayerLoop.GetProfilingTime <PreLateUpdate.ScriptRunBehaviourLateUpdate>() + CustomPlayerLoop.GetProfilingTime <FixedUpdate.ScriptRunBehaviourFixedUpdate>() + CustomPlayerLoop.GetProfilingTime <Update.ScriptRunDelayedDynamicFrameRate>(); float animatorTime = CustomPlayerLoop.GetProfilingTime <PreLateUpdate.DirectorUpdateAnimationBegin>() + CustomPlayerLoop.GetProfilingTime <PreLateUpdate.DirectorUpdateAnimationEnd>(); float renderTime = CustomPlayerLoop.GetProfilingTime <PostLateUpdate.FinishFrameRendering>(); float physicsTime = CustomPlayerLoop.GetProfilingTime <FixedUpdate.PhysicsFixedUpdate>(); // for android multiThread #if UNITY_ANDROID && !UNITY_EDITOR if (SystemInfo.graphicsMultiThreaded) { float waitForGfxPresent = CustomPlayerLoop.GetGfxWaitForPresent(); renderTime -= waitForGfxPresent; allTime -= waitForGfxPresent; } #endif float otherTime = allTime - scriptUpdateTime - animatorTime - renderTime - physicsTime; mainThreadMeter.SetParameter(MeterIdxScript, scriptUpdateTime / this.expectedExecuteTime); mainThreadMeter.SetParameter(MeterIdxAnimator, animatorTime / this.expectedExecuteTime); mainThreadMeter.SetParameter(MeterIdxRendeing, renderTime / this.expectedExecuteTime); mainThreadMeter.SetParameter(MeterIdxPhysics, physicsTime / this.expectedExecuteTime); mainThreadMeter.SetParameter(MeterIdxOther, otherTime / this.expectedExecuteTime); }
// Update is called once per frame private void Update() { UpdateExpectedExecuteTime(); UpdateMainThreadMeter(); #if DEBUG || DEVELOPMENT_BUILD UpdateRenderThreadMeter(); #endif int sec = (int)Time.realtimeSinceStartup; float allTime = CustomPlayerLoop.GetLastExecuteTime(); // for android multiThread #if UNITY_ANDROID && !UNITY_EDITOR if (SystemInfo.graphicsMultiThreaded) { float waitForGfxPresent = CustomPlayerLoop.GetGfxWaitForPresent(); allTime -= waitForGfxPresent; } #endif AppendExecuteTime(allTime); if (this.currentStartSec != sec) { stringBuilderBuffer.Length = 0; stringBuilderBuffer.Append("FPS:").Append(this.sumCount).Append(" "); stringBuilderBuffer.Append("(Avg:") .AddMsecFromSec(this.sumExecuteTime / (float)this.sumCount) .Append("ms)\n"); stringBuilderBuffer.Append("min-max:") .AddMsecFromSec(this.minExecuteTime) .Append("ms"); stringBuilderBuffer.Append(" - ") .AddMsecFromSec(this.maxExecuteTime) .Append("ms"); frameRateText.text = stringBuilderBuffer.ToString(); this.GotoNextSec(sec); } }