본문 바로가기

Programming/유니티

유니티 EditorWindow 를 이용하여 유용한 툴을 만들어보자 - 2

edit button

오늘은 버튼을 만들어 영역과 색을 넣는 예제와 완성 화면을 표시하겠습니다.

유니티 EditorWindow 를 이용하여 유용한 툴을 만들어보자 - 1
유니티 EditorWindow 를 이용하여 유용한 툴을 만들어보자 - 2
유니티 EditorWindow 를 이용하여 유용한 툴을 만들어보자 - 3
유니티 EditorWindow 를 이용하여 유용한 툴을 만들어보자 - 4

----

----

영역 만들기

//영역시작

NGUIEditorTools.BeginContents();

 

//이 사이에 들어가는 UI는 영역안에 들어오게 된다.

if (GUILayout.Button("버튼_1")){

}

 

//영역 끝

NGUIEditorTools.EndContents();

 

 

//결과화면

 

//영역을 설정하지 않은 결과 -- 버튼 테두리가 없는것을 확인할 수 있다.

 

영역에 색 넣기

//색을 정하고

GUI.Color = Color.yellow;

 

//영역시작

NGUIEditorTools.BeginContents();

 

//색 복구

GUI.Color = Color.white;        <-- 넣지 않으면 버튼 색도 노란색으로

 

//이 사이에 들어가는 UI는 영역안에 들어오게 된다.

if (GUILayout.Button("버튼_1", GUILayout.Width(100f))){

}

 

//영역 끝

NGUIEditorTools.EndContents();

 

 

//결과화면

 

영역 공간설정

GUILayout.Space (30);        <- 상단 공간

GUILayout.BeginHorizontal (); <- 좌측 공간을 위해 

GUILayout.Space (30); <- horizontal 이후에 불려지면 좌측 공간을 의미하는 듯하다.

 

//영역에 색 넣기 코드와 동일

GUI.color = Color.yellow;

NGUIEditorTools.BeginContents ();

GUI.color = Color.white;

 

if (GUILayout.Button ("버튼_1", GUILayout.Width(100f))) {

}

 

NGUIEditorTools.EndContents ();

 

GUILayout.EndHorizontal ();

 

//결과화면

 

 

주의 점

만약 영역에 버튼_2를 넣게되면 어떻게 될까

GUILayout.BeginHorizontal (); 이 호출되어있는 상태이니 나란히 출력되야하겠지?

 

 

//결과화면 -- 예상과는 다른 결과가 출력되었다.

 

 

이럴때는 GUILayout.BeginHorizontal (); 을 한번더 호출해 줘야한다.

 

//코드

GUILayout.Space (30);

 

GUILayout.BeginHorizontal ();

 

GUILayout.Space (30);

GUI.color = Color.yellow;

NGUIEditorTools.BeginContents ();

GUI.color = Color.white;

 

GUILayout.BeginHorizontal ();            <-- 추가 코드

 

if (GUILayout.Button ("버튼_1", GUILayout.Width(100f))) {

}

if (GUILayout.Button ("버튼_2", GUILayout.Width(100f))) {

}

GUILayout.EndHorizontal ();            <-- 추가 코드

 

NGUIEditorTools.EndContents ();

 

GUILayout.EndHorizontal ();

 

//결과화면