87 lines
2.7 KiB
C#
87 lines
2.7 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class MaterialObjectSelector : EditorWindow
|
|
{
|
|
[MenuItem("Tools/Select Objects Using Material")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<MaterialObjectSelector>("Material Object Selector");
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
GUILayout.Label("Material Object Selector", EditorStyles.boldLabel);
|
|
GUILayout.Space(10);
|
|
|
|
GUILayout.Label("선택한 머티리얼을 사용하는 모든 오브젝트를 선택합니다.");
|
|
GUILayout.Space(5);
|
|
|
|
if (GUILayout.Button("Select Objects Using Selected Material", GUILayout.Height(30)))
|
|
{
|
|
SelectObjectsUsingSelectedMaterial();
|
|
}
|
|
}
|
|
|
|
void SelectObjectsUsingSelectedMaterial()
|
|
{
|
|
Object[] selectedObjects = Selection.objects;
|
|
|
|
if (selectedObjects == null || selectedObjects.Length == 0)
|
|
{
|
|
EditorUtility.DisplayDialog("Error", "머티리얼을 선택해주세요.", "OK");
|
|
return;
|
|
}
|
|
|
|
List<Material> selectedMaterials = new List<Material>();
|
|
|
|
foreach (Object obj in selectedObjects)
|
|
{
|
|
if (obj is Material material)
|
|
{
|
|
selectedMaterials.Add(material);
|
|
}
|
|
}
|
|
|
|
if (selectedMaterials.Count == 0)
|
|
{
|
|
EditorUtility.DisplayDialog("Error", "선택된 오브젝트 중 머티리얼이 없습니다.", "OK");
|
|
return;
|
|
}
|
|
|
|
List<GameObject> objectsWithMaterial = new List<GameObject>();
|
|
GameObject[] allGameObjects = FindObjectsOfType<GameObject>();
|
|
|
|
foreach (GameObject go in allGameObjects)
|
|
{
|
|
Renderer renderer = go.GetComponent<Renderer>();
|
|
if (renderer != null)
|
|
{
|
|
Material[] materials = renderer.sharedMaterials;
|
|
|
|
foreach (Material mat in materials)
|
|
{
|
|
if (mat != null && selectedMaterials.Contains(mat))
|
|
{
|
|
objectsWithMaterial.Add(go);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (objectsWithMaterial.Count > 0)
|
|
{
|
|
Selection.objects = objectsWithMaterial.ToArray();
|
|
Debug.Log($"선택된 머티리얼을 사용하는 {objectsWithMaterial.Count}개의 오브젝트를 선택했습니다.");
|
|
|
|
SceneView.FrameLastActiveSceneView();
|
|
}
|
|
else
|
|
{
|
|
EditorUtility.DisplayDialog("Info", "선택된 머티리얼을 사용하는 오브젝트가 없습니다.", "OK");
|
|
}
|
|
}
|
|
} |