Unity3D/Editor
[Unity] menuItem 여러번 실행 막기
아낙시만더
2016. 10. 31. 14:18
반응형
How to execute MenuItem for multiple objects once.
여러개의 오브젝트 선택후 MenuItem을 실행 하면 오브젝트 수만큼 해당 함수가 실행 되는데
이를 아래와 같이 막을수있다.
static public void MethodName(MenuCommand menuCommand)
{
//Prevent executing multiple times when right-clicking.
if (Selection.objects.Length > 1)
{
if (menuCommand.context != Selection.objects[0])
{
return;
}
}
}
윗코드에선 두개의 오브젝트를 선택했을때 첫번째 인덱스 0의 오브젝트와 같으면 패스하게 되고 나머지 오브젝트들을 다실행하는데 하나만 실행 되게 하기 위해선 아래와 같이 수정이 필요 했다.
if (Selection.objects.Length > 0) { if (menuCommand.context == Selection.objects[0]) { return; } }
반응형