본문 바로가기
개발/Unity

Unity) OnGUI Attribute 작업하기

by 테샤르 2025. 2. 18.

OnGUI Attribute 작업하기

반응형

 

개발과정에서 필요한 데이터를 확인하는 과정에서 매번 GUI를 가지고 만들기에는 부담스러워서 Manager 클래스와 함께 언제든지 필요하면 사용 가능하도록 Attribute로 만들었다.

 

< 테스트 코드>

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

public class MonitorTest : MonitorBehaviour
{

	[Monitor(MonitorAttribute.MonitorAttributeType.Label, MonitorAttribute.AlignType.BottomRight, "BottomLeft Label")]
public string bottomLeftLabel = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Button, MonitorAttribute.AlignType.BottomRight, "BottomLeft Button")]
public string bottomLeftButton = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Button, MonitorAttribute.AlignType.BottomRight, "BottomLeft Button2")]
public string bottomLeftButton2 = default;
[Monitor(MonitorAttribute.MonitorAttributeType.Slider, MonitorAttribute.AlignType.BottomRight, 0, 5, 100)]
public float topLeftSlider = 25;
[Monitor(MonitorAttribute.MonitorAttributeType.Toggle, MonitorAttribute.AlignType.BottomRight, "flagCheck-a-b-c")]
public bool flagCheck = false;

void flagCheckClicked()
{
	Debug.Log($"[flagCheckClicked] {flagCheck}");
}

[Monitor(MonitorAttribute.MonitorAttributeType.Toggle, MonitorAttribute.AlignType.BottomRight, "t")]
public bool flagCheck4 = false;
[Monitor(MonitorAttribute.MonitorAttributeType.Toggle, MonitorAttribute.AlignType.BottomRight, "flagCheck")]
public bool flagCheck3 = false;

[Monitor(MonitorAttribute.MonitorAttributeType.TextFieldWithButton, MonitorAttribute.AlignType.BottomRight, "Login")]
public string playerName = "Player1";

[Monitor(MonitorAttribute.MonitorAttributeType.Button, MonitorAttribute.AlignType.BottomRight, "BottomLeft Button3")]
public string bottomLeftButton3 = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Toggle, MonitorAttribute.AlignType.BottomLeft, "flagCheck2")]
public bool flagCheck2 = false;

void flagCheck2Clicked()
{
	Debug.Log($"[flagCheck2Clicked] {flagCheck2}");
}

[Monitor(MonitorAttribute.MonitorAttributeType.Stepper, MonitorAttribute.AlignType.BottomLeft, "Change", 0, 1, 10)]
public int playerSpeed = 5;

public void playerSpeedChange()
{
	Debug.Log($"playerSpeedChange : {playerSpeed}");
}

[Monitor(MonitorAttribute.MonitorAttributeType.Stepper, MonitorAttribute.AlignType.BottomRight, "Change", 0.0f, 0.5f, 5.0f)]
public float volumeLevel = 2.5f;
public void volumeLevelChange()
{
	Debug.Log($"volumeLevelChange : {volumeLevel}");
}
[Monitor(MonitorAttribute.MonitorAttributeType.Label, MonitorAttribute.AlignType.TopLeft, "TopLeft Label")]
public string topLeftLabel = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Button, MonitorAttribute.AlignType.TopLeft, "TopLeft Button")]
public string topLeftButton = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Label, MonitorAttribute.AlignType.TopRight, "TopRight Label")]
public string topRightLabel = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Button, MonitorAttribute.AlignType.TopRight, "TopRight Button")]
public string topRightButton = default;


[Monitor(MonitorAttribute.MonitorAttributeType.Label, MonitorAttribute.AlignType.BottomRight, "BottomRight Label")]
public string bottomRightLabel = default;



[Monitor(MonitorAttribute.MonitorAttributeType.Button, MonitorAttribute.AlignType.BottomRight, "BottomRight Button")]
public string bottomRightButton = default;

[Monitor(MonitorAttribute.MonitorAttributeType.Toggle, MonitorAttribute.AlignType.BottomLeft, "flagCheck1")]
public bool flagCheck1 = false;




void playerNameLogin()
{
	Debug.Log($"<color=white>[playerNameSubmit]</color> Login Action Test <color=red> : {playerName} </color>");
}

}

 

반응형

 

<설정 >

위치를 지정이 가능하고 상하좌우 각  필요에따라 위치를 처리하도록 했다. 

 

 

이제 간단히 해당 기능으로 테스트코드나 확인하는 작업을 간단학게 할수 있게 되어서 편리해졌다.

 

★★★☆☆

 

[Unity -Top Paid Package]

[Unity -Top Free Package]

[Unity -New Asset Package]

 

 

 

반응형

댓글