Skip to main content

OptimizationManager

A class in Root.Township, the global namespace.

Client singleton that steps graphics quality (LOD bias and shadows) up or down based on frame time. It follows the local player, so it only does anything on a client.

Constructors​

MemberWhat it is
OptimizationManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static OptimizationManager instanceThe single instance, set in Awake.
10 private and internal fields
MemberWhat it is
private float adjustmentDelaySeconds to wait after a quality change before measuring again.
private Coroutine coroutineThe running measuring coroutine, if any.
private int currentLevelBacking field for CurrentLevel.
private int defaultLevelQuality level applied on Awake.
private int frameCountToStepHow many slow or fast frames in a row trigger a step.
private int maxLevelHighest quality level index.
private OptimizationManager.QualitySetting[] qualityLevelsThe quality presets, from best to cheapest.
private OptimizationManager.Direction stepDirectionPending step (performance up, still or graphics up) applied on the next player move.
private float stepDownFPSFPS below which quality is lowered (60 by default).
private float stepUpFPSFPS above which quality is raised (85 by default).

Properties​

MemberWhat it is
int CurrentLevel { get; }Index of the quality level in use. Higher means lower quality.
2 private and internal properties
MemberWhat it is
private float StepDownFPS { get; set; }Frame time in milliseconds above which a frame counts as slow, from stepDownFPS.
private float StepUpFPS { get; set; }Frame time in milliseconds below which a frame counts as fast, from stepUpFPS.

Methods​

MemberWhat it is
void Run()Restarts the PerformanceMeasure coroutine.
void Stop()Stops the running measuring coroutine.
7 private and internal methods
MemberWhat it is
private void Awake()Sets instance, applies the default quality level, and hooks the local player's movement.
private void OnDestroy()Unhooks the local player events.
private IEnumerator PerformanceMeasure() (iterator)Coroutine started by Run: after enough slow or fast frames in a row it steps quality down or up, then waits.
private IEnumerator PerformanceMeasureOnPosition() (iterator)Coroutine that watches frame times and nudges stepDirection, which is applied the next time the player moves.
private void Run(IPlayer player)Restarts the PerformanceMeasure coroutine.
private void UpdateLocalPlayer(PlayerController controller)Hooks the local player's PositionChanged so quality steps happen when they move.
private void UpdatePosition(PlayerController controller, Vector3 from, Vector3 to, LocomotionFunction function)On player movement, applies any pending quality step and starts the position-based measuring coroutine.