호우동의 개발일지

Today :

article thumbnail

썸네일


1. EditorGUILayout 함수

<csharp />
using UnityEngine; using UnityEditor; public class TestEditorWindow : EditorWindow { int intValue; float floatValue; Color colorValue; Gradient gradientValue = new Gradient(); Rect rectValue; Vector3 vector3Value; Vector3Int vectorInt3Value; UnityEngine.Object objectValue; string passwordValue; string tagValue; UnityEngine.ParticleSystemCollisionType enumValue; private void OnGUI() { // int 값 변경 intValue = EditorGUILayout.IntField("int value", intValue); // float 값 변경 floatValue = EditorGUILayout.FloatField("Float value", floatValue); // 컬러 변경 colorValue = EditorGUILayout.ColorField("Color value", colorValue); // 그라데이션 변경 gradientValue = EditorGUILayout.GradientField("Gridient Value", gradientValue); // Rect 변경 rectValue = EditorGUILayout.RectField("rect value", rectValue); // Vecter 변경 vector3Value = EditorGUILayout.Vector3Field("Vector3 value", vector3Value); // VectorInt 변경 vectorInt3Value = EditorGUILayout.Vector3IntField("vector3Int value", vectorInt3Value); // (게임)오브젝트 변경 objectValue = EditorGUILayout.ObjectField("object value", objectValue,typeof(UnityEngine.Object),false); // 패스워드 변경 passwordValue = EditorGUILayout.PasswordField("password Value", passwordValue); // 태그 변경 tagValue = EditorGUILayout.TagField("tag Value", tagValue); // 줄 띄우기 EditorGUILayout.Space(30); // 열거형 enumValue = (UnityEngine.ParticleSystemCollisionType)EditorGUILayout.EnumFlagsField("Enum value", enumValue); } // 선 긋기 EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); }

 

1.0.1. 기본적인 형식

기본적인 형식으로 EditorGUILayout은 ~타입 Field("text", 변수);
의 형식으로 이뤄진다.

간단히 말해서 해당 타입의 값을 직접 수정하여 경신하는 것이다.

여기서 기본적인 형식에 해당하는 것은
object, enumValue를 제외한 나머지들이다.

만들어둔 myTool

공통적으로 이미 정의된 각 데이터 값을 경신하는 기능을 한다.
여기서 Gradient는 처음에 객체의 생성자를 호출해줘야 한다.

 

1.0.2. object

EditorGUILayout.ObjectFiel()는 기본적인 형식과는
다르게 세 번째 인자가 들어간다는 것이 차이점이다.

세 번째 인자는 오브젝트의 타입을 한정시키는 것이다.
true면 필드에서 선언한 타입만 쓸 수 있다.

object value

오브젝트 필드를 만들면 해당 object Value에
게임 오브젝트를 할당할 수 있게 된다.

 

1.0.3. Enum(열거형)

enum의 데이터 타입은
UnityEngine.ParticleSystemCollisionType이다.

이건 크게 신경 안 써도 되는 게 그냥
유니티 엔진 상에 있는 Enum 중 하나를 아무거나 하나 가져온 것이다.


중요한 것은 EnumFlagsField() 호출 후
해당 enum 데이터 타입으로 형변환을 무조건 해줘야 한다는 것이다.

열거형

 

 


2. GUILayout 함수

<csharp />
string[] stringArr = new string[] { "a", "b", "c", "d", "e" }; int selectionValue; private void OnGUI() { // ToolBar selectionValue = GUILayout.Toolbar(selectionValue, stringArr); // 차이를 보여주기 위해 공간을 띄움 EditorGUILayout.Space(50); // Selection Grid selectionValue = GUILayout.SelectionGrid(selectionValue, stringArr, 2); }

대표적으로 많이 사용하년 GUILayout 요소 그룹은
ToolBar와 Selection Grid 이 두 가지이다.

이 2가지는 비슷한듯하면서 다르다.

ToolBar는 요소들을 가로로 배열하여 하나씩 선택하게 하고
Grid는 세 번째 인자로 들어온 수만큼 가로로 짝을 짓는다.

그림으로 보는 게 빠르니까 그림으로 보겠다.

가로로 배열된 버튼

 

2.1. EditorGUIUtility

EditorGUIUtility에서 많이 쓰이는 요소 그룹은 Box이다.
Box는 이미지를 삽입하는 것이다.

<csharp />
GUILayout.Box(EditorGUIUtility.IconContent("Animation.Record"));

여기서 "Animation Record"는 특정 이미지이다.
이게 바뀌면 이미지가 바뀐다.

Animation Record

이런 문자열을 외워서 써야 할까?

이런 문자열은 이미 약속되어 있는 것이기 때문에
아래 링크에서 찾아서 쓰면 된다.

https://github.com/halak/Unity-editor-icons

표에 나와있는 Name을 쓰면 된다.