Unified state statistics tracking system for components. More...
Public Member Functions | |
| void | Initialize (bool? useDESTime=null, Func< double > customTimeFunc=null) |
| Initialize the statistics system. | |
| void | SetState (string newState) |
| Set a new state by name. | |
| void | SetState (Enum enumState) |
| Set a new state from an enum value. | |
| string | GetCurrentState () |
| Get the current state name. | |
| void | UpdateStatistics () |
| Lightweight statistics update. | |
| void | FlushInspectorStats () |
| Forces a full rebuild of inspector-visible lists. | |
| float | GetUtilization01 () |
| Get utilization as a value between 0 and 1. | |
| float | GetUtilizationPercent () |
| Get utilization as a percentage (0-100). | |
| float | GetStatePercentage (string state) |
| Get the percentage of time spent in a specific state. | |
| float | GetStateDuration (string state) |
| Get the duration spent in a specific state. | |
| Dictionary< string, float > | GetAllStatePercentages () |
| Get all state percentages as a dictionary. | |
| float | GetTotalTime () |
| Get total tracked time. | |
| void | StatReset () |
| Reset all statistics. Implements IStatReset interface. | |
| string | GetDisplay () |
| Get formatted display string for statistics. Implements IStatDisplay interface. | |
| bool | IsFreeState (string state) |
| Check if a state is considered "free" (non-utilized). P10: O(1) via HashSet. | |
| void | AddFreeState (string state) |
| Add a state to the free states list. | |
| void | RemoveFreeState (string state) |
| Remove a state from the free states list. | |
| void | SetStateColor (string stateName, Color color) |
| Set a custom color for a specific state. | |
| Color | GetStateColor (string stateName, Color defaultColor) |
| Get the color for a specific state. | |
| bool | HasStateColor (string stateName) |
| Check if a custom color has been set for a state. | |
| void | ClearStateColors () |
| Clear all custom state colors. | |
| string | GetDetailedReport () |
| Get a detailed report of all statistics. | |
Detailed Description
Unified state statistics tracking system for components.
Tracks time spent in different states, calculates utilization, and provides visualization data. Can be used by both regular components (using Time.time) and DES components (using DES.Now). Performance-optimized: 0 GC allocations in hot path. Inspector lists updated lazily on demand.
Member Function Documentation
◆ AddFreeState()
| void realvirtual.StateStatistics.AddFreeState | ( | string | state | ) |
Add a state to the free states list.
◆ ClearStateColors()
| void realvirtual.StateStatistics.ClearStateColors | ( | ) |
Clear all custom state colors.
◆ FlushInspectorStats()
| void realvirtual.StateStatistics.FlushInspectorStats | ( | ) |
Forces a full rebuild of inspector-visible lists.
Call only when display is needed (e.g., editor repaint, gizmo draw, report generation, end of simulation).
◆ GetAllStatePercentages()
| Dictionary< string, float > realvirtual.StateStatistics.GetAllStatePercentages | ( | ) |
Get all state percentages as a dictionary.
P8: Still allocates a new dictionary (unavoidable for this API), but no UpdateStatistics cascade.
◆ GetCurrentState()
| string realvirtual.StateStatistics.GetCurrentState | ( | ) |
Get the current state name.
◆ GetDetailedReport()
| string realvirtual.StateStatistics.GetDetailedReport | ( | ) |
Get a detailed report of all statistics.
◆ GetDisplay()
| string realvirtual.StateStatistics.GetDisplay | ( | ) |
Get formatted display string for statistics. Implements IStatDisplay interface.
Implements realvirtual.IStatDisplay.
◆ GetStateColor()
| Color realvirtual.StateStatistics.GetStateColor | ( | string | stateName, |
| Color | defaultColor | ||
| ) |
Get the color for a specific state.
- Parameters
-
stateName The name of the state defaultColor The default color to use if no custom color is set
- Returns
- The color for this state
◆ GetStateDuration()
| float realvirtual.StateStatistics.GetStateDuration | ( | string | state | ) |
Get the duration spent in a specific state.
P7: Calculates directly from raw data - no UpdateStatistics cascade, 0 GC.
- Parameters
-
state The state name to query
- Returns
- Time spent in that state (seconds)
◆ GetStatePercentage()
| float realvirtual.StateStatistics.GetStatePercentage | ( | string | state | ) |
Get the percentage of time spent in a specific state.
P6: Calculates directly from raw data - no UpdateStatistics cascade, 0 GC.
- Parameters
-
state The state name to query
- Returns
- Percentage of time in that state (0-100)
◆ GetTotalTime()
| float realvirtual.StateStatistics.GetTotalTime | ( | ) |
Get total tracked time.
◆ GetUtilization01()
| float realvirtual.StateStatistics.GetUtilization01 | ( | ) |
Get utilization as a value between 0 and 1.
◆ GetUtilizationPercent()
| float realvirtual.StateStatistics.GetUtilizationPercent | ( | ) |
Get utilization as a percentage (0-100).
◆ HasStateColor()
| bool realvirtual.StateStatistics.HasStateColor | ( | string | stateName | ) |
Check if a custom color has been set for a state.
- Parameters
-
stateName The name of the state
- Returns
- True if a custom color exists for this state
◆ Initialize()
| void realvirtual.StateStatistics.Initialize | ( | bool? | useDESTime = null, |
| Func< double > | customTimeFunc = null |
||
| ) |
Initialize the statistics system.
- Parameters
-
useDESTime If true, uses DES.Now for time tracking. If false, uses Time.time. If null, auto-detects. customTimeFunc Optional custom function to get current time
◆ IsFreeState()
| bool realvirtual.StateStatistics.IsFreeState | ( | string | state | ) |
Check if a state is considered "free" (non-utilized). P10: O(1) via HashSet.
◆ RemoveFreeState()
| void realvirtual.StateStatistics.RemoveFreeState | ( | string | state | ) |
Remove a state from the free states list.
◆ SetState() [1/2]
| void realvirtual.StateStatistics.SetState | ( | Enum | enumState | ) |
Set a new state from an enum value.
- Parameters
-
enumState The enum value representing the new state
◆ SetState() [2/2]
| void realvirtual.StateStatistics.SetState | ( | string | newState | ) |
Set a new state by name.
Lightweight: just records elapsed time, no inspector rebuild.
- Parameters
-
newState The name of the new state
◆ SetStateColor()
| void realvirtual.StateStatistics.SetStateColor | ( | string | stateName, |
| Color | color | ||
| ) |
Set a custom color for a specific state.
- Parameters
-
stateName The name of the state color The color to use for this state in visualizations
◆ StatReset()
| void realvirtual.StateStatistics.StatReset | ( | ) |
Reset all statistics. Implements IStatReset interface.
Implements realvirtual.IStatReset.
◆ UpdateStatistics()
| void realvirtual.StateStatistics.UpdateStatistics | ( | ) |
Lightweight statistics update.
Marks dirty for lazy inspector rebuild. No GC allocations. Call freely from hot paths.