48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEditor;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public static class MaterialChecker
|
|||
|
|
{
|
|||
|
|
[MenuItem("Tools/Check Materials in Selected Object")]
|
|||
|
|
private static void CheckSelectedObject()
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD>õ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
|
|||
|
|
GameObject selectedObject = Selection.activeGameObject;
|
|||
|
|
|
|||
|
|
if (selectedObject == null)
|
|||
|
|
{
|
|||
|
|
Debug.LogWarning("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>.");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>ڽ<EFBFBD><DABD><EFBFBD> MeshRenderer<65><72> Ȯ<><C8AE>
|
|||
|
|
MeshRenderer[] meshRenderers = selectedObject.GetComponentsInChildren<MeshRenderer>();
|
|||
|
|
if (meshRenderers.Length == 0)
|
|||
|
|
{
|
|||
|
|
Debug.Log($"'{selectedObject.name}'<27><><EFBFBD><EFBFBD> MeshRenderer<65><72> <20><><EFBFBD>Ե<EFBFBD> <20>ڽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><CDB8><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
|
HashSet<Material> uniqueMaterials = new HashSet<Material>();
|
|||
|
|
foreach (var renderer in meshRenderers)
|
|||
|
|
{
|
|||
|
|
foreach (var material in renderer.sharedMaterials)
|
|||
|
|
{
|
|||
|
|
if (material != null)
|
|||
|
|
{
|
|||
|
|
uniqueMaterials.Add(material);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD> <20>α<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
|
Debug.Log($"'{selectedObject.name}'<27><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><CDB8><EFBFBD> <20><>: {uniqueMaterials.Count}");
|
|||
|
|
int i = 0;
|
|||
|
|
foreach (var material in uniqueMaterials)
|
|||
|
|
{
|
|||
|
|
Debug.Log($"{i++} : {material.name}", material);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|