MenuItem (Check Menu)

Unity Editor에 Custom Menu를 사용하다가 Toogle 형태의 Menu가 필요한 상황이 생겼다.
따로 Custom EditorWindow를 만들어도 되지만 Unity의 기능이 있어서 해당 기능으로 간단하게 사용했다.
Menu.SetChecked / Menu.GetChecked 를 통해서 생성이 가능하다.
반응형
예시는 다음과 같다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
public class NewScript | |
{ | |
[MenuItem("CustomMenu/Example")] | |
static void Example() | |
{ | |
var menuPath = "CustomMenu/Example"; | |
var checkFlag = Menu.GetChecked(menuPath); | |
Menu.SetChecked(menuPath, !checkFlag); | |
} | |
} |
'Menu.SetCheck'를 여러개로 처리를 해서 Toggle 처럼 단일 선택도 가능하다.
Unity Editor Menu : [링크]
Unity - Scripting API: Menu
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
Customising Unity Menu Bar : [링크]
Customising Unity’s Menu Bar using MenuItem
Sharing Unity tips to help others (and myself) learn!
hugecalf-studios.github.io
★☆☆☆☆
반응형
'개발 > Unity' 카테고리의 다른 글
Unity)Unity 에서 C# Version 확인방법 (0) | 2023.01.20 |
---|---|
Unity) UPM (UnityPackageManager) : Custom Package 만들기 (2) | 2023.01.16 |
Unity) #unitytips (0) | 2023.01.06 |
Unity) 객체 복사 시 이름 규칙 (GameObject Copy Naming Scheme) (0) | 2023.01.04 |
문제해결)Unity)an attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type (0) | 2023.01.04 |
댓글