internal override void UpdateValue(bool force) { if (!enabled) { return; } int roundedValue = (int)newValue; if (LastValue != roundedValue || force) { LastValue = roundedValue; dirty = true; } if (LastValue <= criticalLevelValue) { if (LastValue != 0 && CurrentFpsLevel != FPSLevel.Critical) { CurrentFpsLevel = FPSLevel.Critical; if (OnFPSLevelChange != null) { OnFPSLevelChange(CurrentFpsLevel); } } } else if (LastValue < warningLevelValue) { if (LastValue != 0 && CurrentFpsLevel != FPSLevel.Warning) { CurrentFpsLevel = FPSLevel.Warning; if (OnFPSLevelChange != null) { OnFPSLevelChange(CurrentFpsLevel); } } } else { if (LastValue != 0 && CurrentFpsLevel != FPSLevel.Normal) { CurrentFpsLevel = FPSLevel.Normal; if (OnFPSLevelChange != null) { OnFPSLevelChange(CurrentFpsLevel); } } } // since ms calculates from fps we can calculate it when fps changed if (dirty && milliseconds) { LastMillisecondsValue = 1000f / newValue; } if (render) { if (renderTimeBank > 0) { var frameCount = Time.frameCount; var framesSinceLastUpdate = frameCount - previousFrameCount; if (framesSinceLastUpdate == 0) { framesSinceLastUpdate = 1; } var renderTime = renderTimeBank / framesSinceLastUpdate; if (System.Math.Abs(renderTime - LastRenderValue) > 0.0001f || force) { LastRenderValue = renderTime; dirty = true; } previousFrameCount = frameCount; renderTimeBank = 0; } } int currentAverageRounded = 0; if (average) { if (averageSamples == 0) { currentAverageSamples++; currentAverageRaw += (LastValue - currentAverageRaw) / currentAverageSamples; } else { if (accumulatedAverageSamples == null) { accumulatedAverageSamples = new float[averageSamples]; ResetAverage(); } accumulatedAverageSamples[currentAverageSamples % averageSamples] = LastValue; currentAverageSamples++; currentAverageRaw = GetAverageFromAccumulatedSamples(); } currentAverageRounded = Mathf.RoundToInt(currentAverageRaw); if (LastAverageValue != currentAverageRounded || force) { LastAverageValue = currentAverageRounded; dirty = true; if (averageMilliseconds) { LastAverageMillisecondsValue = 1000f / LastAverageValue; } } } if (minMax) { if (minMaxIntervalsSkipped <= minMaxIntervalsToSkip) { if (!force) { minMaxIntervalsSkipped++; } } else if (LastMinimumValue == -1) { dirty = true; } if (minMaxIntervalsSkipped > minMaxIntervalsToSkip && dirty) { if (LastMinimumValue == -1) { LastMinimumValue = LastValue; if (minMaxMilliseconds) { LastMinMillisecondsValue = 1000f / LastMinimumValue; } } else if (LastValue < LastMinimumValue) { LastMinimumValue = LastValue; if (minMaxMilliseconds) { LastMinMillisecondsValue = 1000f / LastMinimumValue; } } if (LastMaximumValue == -1) { LastMaximumValue = LastValue; if (minMaxMilliseconds) { LastMaxMillisecondsValue = 1000f / LastMaximumValue; } } else if (LastValue > LastMaximumValue) { LastMaximumValue = LastValue; if (minMaxMilliseconds) { LastMaxMillisecondsValue = 1000f / LastMaximumValue; } } } } if (dirty && main.OperationMode == OperationMode.Normal) { string coloredStartText; if (LastValue >= warningLevelValue) { coloredStartText = colorCached; } else if (LastValue <= criticalLevelValue) { coloredStartText = colorCriticalCached; } else { coloredStartText = colorWarningCached; } text.Length = 0; text.Append(coloredStartText).Append(LastValue).Append(COLOR_TEXT_END); if (milliseconds) { if (LastValue >= warningLevelValue) { coloredStartText = colorCachedMs; } else if (LastValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMs; } else { coloredStartText = colorWarningCachedMs; } text.Append(coloredStartText).Append(LastMillisecondsValue.ToString("F")).Append(MS_TEXT_END); } if (average) { text.Append(averageNewLine ? AFPSCounter.NEW_LINE : AFPSCounter.SPACE); if (currentAverageRounded >= warningLevelValue) { coloredStartText = colorCachedAvg; } else if (currentAverageRounded <= criticalLevelValue) { coloredStartText = colorCriticalCachedAvg; } else { coloredStartText = colorWarningCachedAvg; } text.Append(coloredStartText).Append(currentAverageRounded); if (averageMilliseconds) { text.Append(" [").Append(LastAverageMillisecondsValue.ToString("F")).Append(" MS]"); } text.Append(COLOR_TEXT_END); } if (minMax) { text.Append(minMaxNewLine ? AFPSCounter.NEW_LINE : AFPSCounter.SPACE); if (LastMinimumValue >= warningLevelValue) { coloredStartText = colorCachedMin; } else if (LastMinimumValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMin; } else { coloredStartText = colorWarningCachedMin; } text.Append(coloredStartText).Append(LastMinimumValue); if (minMaxMilliseconds) { text.Append(" [").Append(LastMinMillisecondsValue.ToString("F")).Append(" MS]"); } text.Append(COLOR_TEXT_END); text.Append(minMaxTwoLines ? AFPSCounter.NEW_LINE : AFPSCounter.SPACE); if (LastMaximumValue >= warningLevelValue) { coloredStartText = colorCachedMax; } else if (LastMaximumValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMax; } else { coloredStartText = colorWarningCachedMax; } text.Append(coloredStartText).Append(LastMaximumValue); if (minMaxMilliseconds) { text.Append(" [").Append(LastMaxMillisecondsValue.ToString("F")).Append(" MS]"); } text.Append(COLOR_TEXT_END); } if (render) { text.Append(renderNewLine ? AFPSCounter.NEW_LINE : AFPSCounter.SPACE). Append(colorCachedRender). Append(LastRenderValue.ToString("F")).Append(" MS"). Append(COLOR_TEXT_END); } ApplyTextStyles(); } }
internal override void UpdateValue(bool force) { if (!enabled) { return; } int roundedValue = (int)newValue; if (LastValue != roundedValue || force) { LastValue = roundedValue; dirty = true; } if (LastValue <= criticalLevelValue) { if (LastValue != 0 && CurrentFpsLevel != FPSLevel.Critical) { CurrentFpsLevel = FPSLevel.Critical; if (OnFpsLevelChange != null) { OnFpsLevelChange(CurrentFpsLevel); } } } else if (LastValue < warningLevelValue) { if (LastValue != 0 && CurrentFpsLevel != FPSLevel.Warning) { CurrentFpsLevel = FPSLevel.Warning; if (OnFpsLevelChange != null) { OnFpsLevelChange(CurrentFpsLevel); } } } else { if (LastValue != 0 && CurrentFpsLevel != FPSLevel.Normal) { CurrentFpsLevel = FPSLevel.Normal; if (OnFpsLevelChange != null) { OnFpsLevelChange(CurrentFpsLevel); } } } // since ms calculates from fps we can calculate it when fps changed if (dirty && milliseconds) { LastMillisecondsValue = 1000f / newValue; } int currentAverageRounded = 0; if (average) { if (averageSamples == 0) { currentAverageSamples++; currentAverageRaw += (LastValue - currentAverageRaw) / currentAverageSamples; } else { if (accumulatedAverageSamples == null) { accumulatedAverageSamples = new float[averageSamples]; ResetAverage(); } accumulatedAverageSamples[currentAverageSamples % averageSamples] = LastValue; currentAverageSamples++; currentAverageRaw = GetAverageFromAccumulatedSamples(); } currentAverageRounded = Mathf.RoundToInt(currentAverageRaw); if (LastAverageValue != currentAverageRounded || force) { LastAverageValue = currentAverageRounded; dirty = true; } } if (minMax) { if (minMaxIntervalsSkipped < minMaxIntervalsToSkip) { if (!force) { minMaxIntervalsSkipped++; } } else if (dirty) { if (LastMinimumValue == -1) { LastMinimumValue = LastValue; } else if (LastValue < LastMinimumValue) { LastMinimumValue = LastValue; dirty = true; } if (LastMaximumValue == -1) { LastMaximumValue = LastValue; } else if (LastValue > LastMaximumValue) { LastMaximumValue = LastValue; dirty = true; } } } if (dirty && main.OperationMode == OperationMode.Normal) { string coloredStartText; if (LastValue >= warningLevelValue) { coloredStartText = colorCached; } else if (LastValue <= criticalLevelValue) { coloredStartText = colorCriticalCached; } else { coloredStartText = colorWarningCached; } text.Length = 0; text.Append(coloredStartText).Append(LastValue).Append(FPS_TEXT_END); if (milliseconds) { if (LastValue >= warningLevelValue) { coloredStartText = colorCachedMs; } else if (LastValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMs; } else { coloredStartText = colorWarningCachedMs; } text.Append(coloredStartText).Append(LastMillisecondsValue.ToString("F")).Append(MS_TEXT_END); } if (average) { if (currentAverageRounded >= warningLevelValue) { coloredStartText = colorCachedAvg; } else if (currentAverageRounded <= criticalLevelValue) { coloredStartText = colorCriticalCachedAvg; } else { coloredStartText = colorWarningCachedAvg; } text.Append(coloredStartText).Append(currentAverageRounded).Append(AVG_TEXT_END); } if (minMax) { text.Append(minMaxNewLine ? AFPSCounter.NEW_LINE : AFPSCounter.SPACE); if (LastMinimumValue >= warningLevelValue) { coloredStartText = colorCachedMin; } else if (LastMinimumValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMin; } else { coloredStartText = colorWarningCachedMin; } text.Append(coloredStartText).Append(LastMinimumValue).Append(MIN_TEXT_END); if (LastMaximumValue >= warningLevelValue) { coloredStartText = colorCachedMax; } else if (LastMaximumValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMax; } else { coloredStartText = colorWarningCachedMax; } text.Append(coloredStartText).Append(LastMaximumValue).Append(MAX_TEXT_END); } } }