ClientServer/Client/Assets/Scripts/Util/ObjectLayerChecker.cs
TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

59 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.SceneManagement;
public class ObjectLayerChecker : MonoBehaviour
{
private void Awake()
{
CheckUsedLayers();
}
public static void CheckUsedLayers()
{
Debug.Log("Check used layers");
Dictionary<string, int> layerCount = new Dictionary<string, int>();
List<GameObject> gameObjects = FindObjectsOfType<GameObject>().ToList();
// iterate objects and save to dictionary
for (int i = 0; i < gameObjects.Count; ++i)
{
string layerName = LayerMask.LayerToName(gameObjects[i].layer);
if (layerCount.ContainsKey(layerName))
{
layerCount[layerName]++;
}
else
{
layerCount.Add(layerName, 1);
}
}
// log to console
foreach (KeyValuePair<string, int> entry in layerCount)
{
Debug.Log(entry.Key + ": " + entry.Value);
}
// unused layers
List<string> layerNames = new List<string>();
for (int i = 8; i <= 31; i++) //user defined layers start with layer 8 and unity supports 31 layers
{
var layerN = LayerMask.LayerToName(i); //get the name of the layer
if (layerN.Length > 0) //only add the layer if it has been named (comment this line out if you want every layer)
layerNames.Add(layerN);
}
List<string> listOfKeys = layerCount.Keys.ToList();
List<string> unusedLayers = layerNames.Except(listOfKeys).ToList();
string joined = string.Join(", ", unusedLayers);
Scene scene = SceneManager.GetActiveScene();
Debug.Log("Unused layers in " + scene.name + ": " + joined);
Debug.Log("Check used layers done");
}
}