protected override void PerformDeActivationActions() { base.PerformDeActivationActions(); ResetMinMax(true); ResetAverage(); LastValue = 0; CurrentFpsLevel = FPSLevel.Normal; }
internal override void Deactivate() { if (!inited) { return; } base.Deactivate(); main.StopCoroutine(COROUTINE_NAME); ResetMinMax(); ResetAverage(); LastValue = 0; CurrentFpsLevel = FPSLevel.Normal; inited = false; }
private void OnFPSLevelChanged(FPSLevel newLevel) { _configuration.CurrentFpsLevel = newLevel; }
private void OnFPSLevelChanged(FPSLevel newLevel) { currentFPSLevel = newLevel; }
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); } } }
internal override void UpdateValue(bool force) { if (!enabled) { return; } if (!realtimeFPS && !average && !minMax && !render) { if (text.Length > 0) { text.Length = 0; } return; } var 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 (Math.Abs(renderTime - LastRenderValue) > 0.0001f || force) { LastRenderValue = renderTime; dirty = true; } previousFrameCount = frameCount; renderTimeBank = 0; } } var currentAverageRounded = -1; if (average && LastValue > -1) { currentAverageSamples++; if (currentAverageSamples > averageSamples && averageSamples != 0) { currentAverageRaw += (LastValue - currentAverageRaw) / (averageSamples + 1); } else { currentAverageRaw += (LastValue - currentAverageRaw) / currentAverageSamples; } 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; text.Length = 0; if (realtimeFPS) { if (LastValue >= warningLevelValue || LastValue == -1) { coloredStartText = colorCached; } else if (LastValue <= criticalLevelValue) { coloredStartText = colorCriticalCached; } else { coloredStartText = colorWarningCached; } text.Append(coloredStartText).AppendLookup(LastValue).Append(ColorTextEnd); if (milliseconds) { if (LastValue >= warningLevelValue || LastValue == -1) { coloredStartText = colorCachedMs; } else if (LastValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMs; } else { coloredStartText = colorWarningCachedMs; } text.Append(coloredStartText).AppendLookup(LastMillisecondsValue).Append(MsTextEnd); } } if (average) { if (realtimeFPS) { text.Append(averageNewLine ? AFPSCounter.NewLine : AFPSCounter.Space); } if (currentAverageRounded >= warningLevelValue || currentAverageRounded == -1) { coloredStartText = colorCachedAvg; } else if (currentAverageRounded <= criticalLevelValue) { coloredStartText = colorCriticalCachedAvg; } else { coloredStartText = colorWarningCachedAvg; } text.Append(coloredStartText).AppendLookup(currentAverageRounded); if (averageMilliseconds) { text.Append(" [").AppendLookup(LastAverageMillisecondsValue).Append(" MS]"); } text.Append(ColorTextEnd); } if (minMax) { if (realtimeFPS || average) { text.Append(minMaxNewLine ? AFPSCounter.NewLine : AFPSCounter.Space); } if (LastMinimumValue >= warningLevelValue || LastMinimumValue == -1) { coloredStartText = colorCachedMin; } else if (LastMinimumValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMin; } else { coloredStartText = colorWarningCachedMin; } text.Append(coloredStartText).AppendLookup(LastMinimumValue); if (minMaxMilliseconds) { text.Append(" [").AppendLookup(LastMinMillisecondsValue).Append(" MS]"); } text.Append(ColorTextEnd); text.Append(minMaxTwoLines ? AFPSCounter.NewLine : AFPSCounter.Space); if (LastMaximumValue >= warningLevelValue || LastMaximumValue == -1) { coloredStartText = colorCachedMax; } else if (LastMaximumValue <= criticalLevelValue) { coloredStartText = colorCriticalCachedMax; } else { coloredStartText = colorWarningCachedMax; } text.Append(coloredStartText).AppendLookup(LastMaximumValue); if (minMaxMilliseconds) { text.Append(" [").AppendLookup(LastMaxMillisecondsValue).Append(" MS]"); } text.Append(ColorTextEnd); } if (render) { if (realtimeFPS || average || minMax) { text.Append(renderNewLine ? AFPSCounter.NewLine : AFPSCounter.Space); } text.Append(colorCachedRender). AppendLookup(LastRenderValue).Append(" MS"). Append(ColorTextEnd); } ApplyTextStyles(); } }