using System.Collections.Generic; using UnityEngine; using OnlyScove.Scripts; namespace Elbyss.Optimization { public class StressTestSpawner : MonoBehaviour { [Header("Spawn Settings")] public GameObject prefabToSpawn; public int spawnLimit = 1000; public int spawnsPerFrame = 10; public float spacing = 2.0f; [Header("Testing Mode")] public bool useAutoStateMachine = true; [Header("Optimization Options")] public bool stripHeavyComponents = false; private List spawnedObjects = new List(); private int currentSpawnCount = 0; private bool isSpawning = false; private void Update() { if (isSpawning && currentSpawnCount < spawnLimit) { for (int i = 0; i < spawnsPerFrame && currentSpawnCount < spawnLimit; i++) { SpawnObject(); } } } [ContextMenu("Start Stress Test")] public void StartStressTest() => isSpawning = true; [ContextMenu("Clear All")] public void ClearAll() { foreach (var obj in spawnedObjects) if (obj != null) Destroy(obj); spawnedObjects.Clear(); currentSpawnCount = 0; isSpawning = false; } private void SpawnObject() { if (prefabToSpawn == null) return; int rowSize = Mathf.CeilToInt(Mathf.Sqrt(spawnLimit)); float x = (currentSpawnCount % rowSize) * spacing; float z = (currentSpawnCount / rowSize) * spacing; Vector3 spawnPos = transform.position + new Vector3(x, 0, z); GameObject newObj = Instantiate(prefabToSpawn, spawnPos, transform.rotation); if (useAutoStateMachine) { var realInput = newObj.GetComponent(); if (realInput != null) realInput.enabled = false; var originalSM = newObj.GetComponent(); if (originalSM != null) { DestroyImmediate(originalSM); var autoSM = newObj.AddComponent(); autoSM.alwaysMoveForward = true; autoSM.alwaysRun = true; } } if (stripHeavyComponents) { if (newObj.TryGetComponent(out var anim)) anim.enabled = false; if (newObj.TryGetComponent(out var cc)) cc.enabled = false; if (newObj.TryGetComponent(out var sm)) sm.enabled = false; } spawnedObjects.Add(newObj); currentSpawnCount++; } } }