add performance optimization unity project

This commit is contained in:
2025-12-01 18:37:09 +01:00
parent bc4b9f1691
commit 9284c52926
72 changed files with 7525 additions and 0 deletions
@@ -0,0 +1,39 @@
using System;
using Unity.Profiling;
using UnityEngine;
namespace DefaultNamespace
{
public class MassInstantiation : MonoBehaviour
{
[SerializeField] private GameObject prefab;
[SerializeField] private int objectsToSpawn = 1000;
[SerializeField] private bool isInstantiating;
private static readonly ProfilerMarker _profilerMarker = new ProfilerMarker("MassInstantiationMarker");
private void Update()
{
if (isInstantiating) InstantiateObjects();
if (Input.GetKeyDown(KeyCode.Space)) DestroyAllChildren();
}
public void InstantiateObjects()
{
_profilerMarker.Begin();
for (int i = 0; i < objectsToSpawn; i++)
{
Instantiate(prefab, transform);
}
_profilerMarker.End();
}
private void DestroyAllChildren()
{
for (int i = transform.childCount - 1; i >= 0; i--)
{
Destroy(transform.GetChild(i).gameObject);
}
}
}
}