11/03

이우석·2023년 11월 3일
0

SBS 국기수업

목록 보기
69/120

인스펙터 창 파라미터 정리 기능 확인

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[AddComponentMenu("SampleUI/TestParam")] // 컴포넌트 메뉴에 본 스크립트를 생성함
public class testParamScript : MonoBehaviour
{
    [Range(1, 10)] public int _number1 = 2; //범위지정
    [Range(1, 10)] public float _number2 = 1.2f;
    [Range(1, 20)] public long _number3 = 20;

    [Space(30)] //위쪽에 30px의 마진 생성
    [Multiline(3)] public string _story;

    // 우클릭 시 특정 기능 실행
    [ContextMenuItem("무작위", "RandomNum")]
    [ContextMenuItem("기본값", "ResetNum")]
    public int _number;

    void RandomNum()
    {
        _number = Random.Range(1, 101);
    }

    void ResetNum()
    {
        _number = 1;
    }
    
    [Space(30)]
    [Tooltip("기본 컬러")] // 마우스 오버시 툴팁
    public Color _color1;

    [Tooltip("알파값 없는 컬러")]
    [ColorUsage(false)] public Color _color2;

    [Tooltip("HDR 컬러")]
    [ColorUsage(true, true, 0f, 1.0f, 0.125f, 3)] public Color _color3;

    [HideInInspector] // 인스펙터 창에서 파라미터 숨기기
    [Space(30)] public string _message;
}
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEngine.Events;

public class SampleEditorWindow : EditorWindow
{
	[MenuItem("Window/Sample/DisplayWindow1")]
	static void Open()
	{
		GetWindow<SampleEditorWindow>();
	}

	// 변수
	bool _enable1;
	bool _enable2;
	bool _toggleVal1;
	bool _toggleVal2;
	int _value1;
	int _value2;
	float[] _axis2d = new float[2] { 0, 0 };
	float[] _axis3d = new float[3] { 0, 0, 0 };
	float _angle = 0;
	int _selectNumber;
	int _menuNumber;
	AnimFloat _animValue = new AnimFloat(0.001f);
	Texture _sampler;
	//Stack<bool> stack = new Stack<bool>();

	// 필드 Format
	GUIContent[] content2d = new GUIContent[2] { new GUIContent("X"), new GUIContent("Y") };
	GUIContent[] content3d = new GUIContent[3] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") };



	void Display(ref bool toggle, ref int value)
	{
		toggle = EditorGUILayout.ToggleLeft("Toggle", false);
		value = EditorGUILayout.IntSlider("값", 1, 0, 10);
		GUILayout.Button("버튼");
	}

	void ShowView()
	{
		EditorGUILayout.BeginVertical();
		var squareSize = new[] { GUILayout.Width(128), GUILayout.Height(128) };
		_sampler = (Texture)EditorGUILayout.ObjectField(_sampler, typeof(Texture), false, squareSize);

		EditorGUILayout.EndVertical();
	}

	private void OnGUI()
	{
		//_enable1 = EditorGUILayout.ToggleLeft("Group1", _enable1);
		//_enable2 = EditorGUILayout.ToggleLeft("Group2", _enable2);
		_enable1 = GUILayout.Toggle(_enable1, _enable1 ? "Enable" : "Disable", "button");
		_enable2 = GUILayout.Toggle(_enable2, _enable2 ? "Enable" : "Disable", "button");

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		if (_enable1)
		{
			GUI.enabled = true;
		}
		else
		{
			GUI.enabled = false;
		}
		Display(ref _toggleVal1, ref _value1);

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		
		if (_enable2)
		{
			GUI.enabled = true;
		}
		else
		{
			GUI.enabled = false;
		}
		Display(ref _toggleVal2, ref _value2);

		EditorGUILayout.Space();
		EditorGUILayout.Space();
		EditorGUILayout.Space();
		EditorGUILayout.Space();


		GUI.enabled = true;
		var squareSize = new[] { GUILayout.Width(64), GUILayout.Height(64) };
		EditorGUILayout.ObjectField(null, typeof(Object), false);
		EditorGUILayout.ObjectField(null, typeof(Material), false);
		EditorGUILayout.ObjectField(null, typeof(AudioClip), false);
		EditorGUILayout.ObjectField(null, typeof(Texture), false, squareSize);
		EditorGUILayout.ObjectField(null, typeof(Sprite), false, squareSize);

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		EditorGUILayout.LabelField("Root");
		EditorGUI.indentLevel++;
		EditorGUILayout.LabelField("Branch1");
		EditorGUI.indentLevel++;
		EditorGUILayout.LabelField("Reaf1");
		EditorGUILayout.LabelField("Reaf2");
		EditorGUI.indentLevel--;
		EditorGUILayout.LabelField("Branch2");
		EditorGUI.indentLevel++;
		EditorGUILayout.LabelField("Reaf3");
		EditorGUI.indentLevel--;
		EditorGUILayout.LabelField("Branch3");

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		_angle = EditorGUILayout.Knob(Vector2.one * 64, _angle, 0, 360, "도", Color.black, Color.red, true);

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		_selectNumber = GUILayout.Toolbar(_selectNumber, new string[] { "1", "2", "3", "4" });

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		_menuNumber = GUILayout.SelectionGrid(_menuNumber, new string[3] { "1. 떡볶이", "2.닭꼬치", "3.튀김" }, 1, "PreferencesKeysElement");

		EditorGUILayout.Space();
		EditorGUILayout.Space();

		bool start = _animValue.value == 1;
		if(GUILayout.Button(start ? "End" : "Start", GUILayout.Width(64)))
		{
			_animValue.target = start ? 0.001f : 1;
			_animValue.speed = 0.01f;

			UnityEvent myEvent = new UnityEvent();
			myEvent.AddListener(() => Repaint());
			_animValue.valueChanged = myEvent;
		}
		EditorGUILayout.BeginHorizontal();
		EditorGUILayout.BeginFadeGroup(_animValue.value);

		//그리기
		ShowView();
		EditorGUILayout.EndFadeGroup();
		//그리기
		ShowView();
		EditorGUILayout.EndHorizontal();

		EditorGUI.MultiFloatField(new Rect(0, 910, 200, EditorGUIUtility.singleLineHeight), new GUIContent("2D 좌표"), content2d, _axis2d);
		EditorGUI.MultiFloatField(new Rect(0, 950, 200, EditorGUIUtility.singleLineHeight), new GUIContent("3D 좌표"), content3d, _axis3d);
	}

	//private void OnGUI()
	//{
	//    EditorGUILayout.LabelField("Example Label");

	//    stack.Push(GUI.changed);
	//    GUI.changed = false;
	//    _toggleVal = EditorGUILayout.ToggleLeft("Toggle", _toggleVal);

	//    bool changed = GUI.changed;
	//    GUI.changed |= stack.Pop();

	//    //if (EditorGUI.EndChangeCheck())
	//    {
	//        //if (_toggleVal)
	//        if (changed)
	//        {
	//            Debug.Log("_toggleVal 값이 변경되었습니다 : " + _toggleVal);
	//        }
	//    }
	//}

}
using UnityEditor;
using UnityEngine;

public class CustomUserScope : GUI.Scope
{
    readonly Color _color;

    public CustomUserScope(Color color)
    {
        EditorGUILayout.BeginHorizontal();
        _color = GUI.backgroundColor;
        GUI.backgroundColor = color;
    }

    public CustomUserScope()
    {
        GUI.backgroundColor = _color;
        EditorGUILayout.BeginHorizontal();
    }

    protected override void CloseScope()
    {
        EditorGUILayout.EndHorizontal();
    }
}

public class TestEditorWindow : EditorWindow
{
    [MenuItem("Window/Sample/DisplayWindow2")]
    static void Open()
    {
        GetWindow<TestEditorWindow>();
    }

    private void OnGUI()
    {
        //using (new EditorGUILayout.HorizontalScope()) // 좌우분할
        using (new CustomUserScope(Color.yellow)) // 좌우분할 커스텀
        {
            GUILayout.Button("Btn1");
        }

        using (new CustomUserScope(Color.cyan)) // 좌우분할 커스텀
        {
            GUILayout.Button("Btn2");
        }
    }
}
profile
게임 개발자 지망생, 유니티 공부중!

0개의 댓글