반응형
Notice
Recent Posts
Recent Comments
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Do Something IT

[Unity] menuItem 여러번 실행 막기 본문

Unity3D/Editor

[Unity] menuItem 여러번 실행 막기

아낙시만더 2016. 10. 31. 14:18
반응형
  1. How to execute MenuItem for multiple objects once.


여러개의 오브젝트 선택후 MenuItem을 실행 하면 오브젝트 수만큼 해당 함수가 실행 되는데
이를 아래와 같이 막을수있다.


  1. static public void MethodName(MenuCommand menuCommand)
  2. {
  3. //Prevent executing multiple times when right-clicking.
  4. if (Selection.objects.Length > 1)
  5. {
  6. if (menuCommand.context != Selection.objects[0])
  7. {
  8. return;
  9. }
  10. }
  11. }


윗코드에선 두개의 오브젝트를 선택했을때 첫번째 인덱스 0의 오브젝트와 같으면 패스하게 되고 나머지 오브젝트들을 다실행하는데 하나만 실행 되게 하기 위해선 아래와 같이 수정이 필요 했다.



        if (Selection.objects.Length > 0)
        {
            if (menuCommand.context == Selection.objects[0])
            {
                    return;
            }
        }
반응형
Comments