Skip to content

Public API

WebAP is designed so that the developer maintains absolute control over the system. If your game has specific scenarios (e.g., cutscenes where FPS is less critical, or a heavy pause menu), you can manage the plugin and read its metrics via a straightforward C# API.

The singular entry point to the system is the Singleton WebPerformanceIndexer.Instance.

Global Control

You can pause the plugin's operations at any moment. When the Indexer is disabled, the current Scaler levels are frozen.

csharp
using GrindsetStudios.WebAdaptivePerformance.Core;

// Pause automatic optimization
WebPerformanceIndexer.Instance.enabled = false;

// Resume operations
WebPerformanceIndexer.Instance.enabled = true;

Reading Metrics

If you prefer not to utilize the built-in Dashboard and intend to output metrics to your own in-game UI (or dispatch them to analytics), you can retrieve raw data directly from the Tracker.

csharp
using GrindsetStudios.WebAdaptivePerformance.Core;
using UnityEngine;

public class CustomMetricsUI : MonoBehaviour
{
    private void Update()
    {
        var indexer = WebPerformanceIndexer.Instance;
        if (indexer == null || !indexer.enabled) return;

        var tracker = indexer.Tracker;

        // 1. Core timings
        float frameTime = tracker.AverageFrameTime;
        float cpuTime = tracker.AverageCpuTime;
        int currentFps = Mathf.RoundToInt(1f / frameTime);

        // 2. What is currently causing the lag? (CPU, GPU, TargetFrameRate, or Unknown)
        PerformanceBottleneck bottleneck = tracker.CurrentBottleneck;
        
        // 3. What is the plugin doing right now? (Increase, Decrease, Stale)
        PerformanceAction action = indexer.CurrentAction;

        Debug.Log($"FPS: {currentFps} | Bottleneck: {bottleneck} | Action: {action}");
    }
}

Manual Scaler Overrides

Occasionally, automation must be overridden. For instance, in the main menu, you might want the resolution to always be 100% and the image pristine, regardless of device lags.

Every Scaler possesses an OverrideLevel property.

How OverrideLevel Works

  • A value of -1 — the Scaler is managed automatically by the Indexer (default).
  • Values from 0 to MaxLevel — switch the Scaler into manual mode and rigidly lock the selected quality level.
csharp
using GrindsetStudios.WebAdaptivePerformance.Core;  
using GrindsetStudios.WebAdaptivePerformance.Scalers.Resolution;  
using UnityEngine;  
  
public class MenuController : MonoBehaviour  
{  
    public void OnEnterMainMenu()  
    {  
        var indexer = WebPerformanceIndexer.Instance;  
        // Locate the Resolution Scaler among the active ones  
        if (indexer.TryGetActiveScaler<WebResolutionScaler>(out var resScaler))  
        {  
            // Hard-lock Level 0 (Maximum quality)  
            // The Indexer can no longer alter it            
            resScaler.OverrideLevel = 0;  
        }  
    }  
  
    public void OnExitMainMenu()  
    {  
        var indexer = WebPerformanceIndexer.Instance;  
        if (indexer.TryGetActiveScaler<WebResolutionScaler>(out var resScaler))  
        {  
            // Return control to the plugin's automation  
            resScaler.OverrideLevel = -1;  
        }  
    }  
}

Dynamic Scaler Addition

You can enable and disable modules dynamically at runtime. For example, disable the WebPhysicsStepScaler when the player is driving a vehicle, and re-enable it when they are on foot.

Upon removing a Scaler, its parameters automatically and safely revert to maximum quality.

csharp
using GrindsetStudios.WebAdaptivePerformance.Core;  
using GrindsetStudios.WebAdaptivePerformance.Scalers;  
  
public class GameplayManager  
{  
    public void EnablePhysicsOptimization()  
    {  
        // Add a Scaler dynamically  
        WebPerformanceIndexer.Instance.TryAddScaler<WebPhysicsStepScaler>();  
    }  
  
    public void DisablePhysicsOptimization()  
    {  
        // Remove the Scaler (physics parameters revert to default)  
        WebPerformanceIndexer.Instance.TryRemoveScaler<WebPhysicsStepScaler>();  
    }  
}