Skip to main content

SpawningTimer

A class in Root.Township, the global namespace.

Editor test tool that times spawning, instantiating, initializing and destroying network prefabs, for one prefab or all of them into a CSV.

Constructors​

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

Fields​

6 private and internal fields
MemberWhat it is
private bool isSpawningInspector button that runs Spawn.
private bool isTestingAllInspector button that runs the slow all-prefabs test.
private int numberOfTimesToSpawnHow many copies each test makes.
private NetworkPrefab prefabToSpawnPrefab timed by Spawn.
private NetworkScene sceneNetwork scene whose spawner is used.
private Stopwatch stopwatchStopwatch reused by TimeFunction.

Methods​

6 private and internal methods
MemberWhat it is
private void Awake()Finds the NetworkScene if none is set.
private void Spawn()Times the chosen prefab and logs each average as an error so it shows up.
private IEnumerator SpawnAll() (iterator)Coroutine that times every prefab under Resources/Network Prefabs/ and writes spawn-times.csv in the data folder.
private void StartSpawningAll()Starts SpawnAll.
private double TimeFunction(Action functionToTime)Runs an action and returns the milliseconds it took, or -1 if it threw.
private SpawningTimer.ResultTimes TimeSpawnPrefab(NetworkPrefab prefabToSpawn)Spawns, instantiates, initializes, rescales and destroys a prefab many times and returns the total times.