📌 기본적인 인스펙터 속성
[Header("제목")] - 섹션 구분
[Header("Experiment Process Settings")]
public float DenaturationTemp = 94f;
✔ 그룹별로 구분 가능
[Space(n)] - 간격 추가
[Space(10)] // 위 속성과 10픽셀 간격 추가
public float AnnealingTemp = 65f;
✔ 가독성을 위해 여백을 추가
[Tooltip("설명")] - 마우스 오버 시 설명 표시
[Tooltip("현재 실행 중인 실험 사이클입니다.")]
public int CurrentCycle = 1;
✔ 마우스를 올리면 설명 툴팁 표시
[Range(min, max)] - 슬라이더 UI 제공
[Range(1, 50)]
public int MaxCycles = 30;
✔ 직관적인 슬라이더 조절 가능
[SerializeField] - private 변수 노출
[SerializeField] private bool isExperimentRunning = false;
✔ private 변수를 인스펙터에서 수정 가능
📌 추가적으로 사용 가능한 속성들
[TextArea] - 여러 줄 텍스트 입력
[TextArea(3, 5)]
public string ExperimentNotes;
✔ 텍스트 입력을 위한 여러 줄 필드 추가
[Multiline] - 여러 줄 텍스트 입력 (간략 버전)
[Multiline(5)]
public string ExperimentLogs;
✔ [TextArea]보다 기본 크기가 작음
[HideInInspector] - 인스펙터에서 숨기기
[HideInInspector]
public int HiddenValue = 10;
✔ 스크립트에서는 사용하지만 인스펙터에서는 숨길 때 사용
[Min(n)] / [Max(n)] - 값 제한
[Min(10)]
public int MinValue = 10;
[Max(100)]
public int MaxValue = 100;
✔ 최소/최대값을 제한하여 실수 방지
[ContextMenu("함수 실행")] - 인스펙터에서 버튼 클릭으로 함수 실행
[ContextMenu("Reset Experiment")]
void ResetExperiment()
{
Debug.Log("Experiment Reset!");
}
✔ 인스펙터에서 마우스 오른쪽 클릭 → 함수 실행 가능
[ContextMenuItem("설명", "함수이름")] - 변수 옆 버튼 추가
[ContextMenuItem("Reset Value", "ResetCounter")]
public int counter = 0;
void ResetCounter()
{
counter = 0;
}
✔ 변수 옆에 "Reset Value" 버튼이 추가됨
[RequireComponent(typeof(컴포넌트))] - 자동으로 특정 컴포넌트 추가
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour { }
✔ 게임 오브젝트에 Rigidbody가 자동으로 추가됨 (없으면 추가됨)
[ExecuteInEditMode] - 에디터에서도 스크립트 실행
[ExecuteInEditMode]
public class ExampleScript : MonoBehaviour
{
void Update()
{
Debug.Log("This runs in the editor too!");
}
}
✔ 게임이 실행되지 않아도 에디터에서 Update() 실행
[ExecuteAlways] - 씬 편집 중에도 실행
[ExecuteAlways]
public class ExampleScript : MonoBehaviour
{
void Update()
{
Debug.Log("Runs even when not in Play mode!");
}
}
✔ 씬을 편집할 때도 Update() 실행됨
[DisallowMultipleComponent] - 중복 추가 방지
[DisallowMultipleComponent]
public class ExperimentManager : MonoBehaviour { }
✔ 같은 컴포넌트를 한 개 이상 추가할 수 없게 막음
[DefaultExecutionOrder(n)] - 스크립트 실행 순서 지정
[DefaultExecutionOrder(-10)]
public class FirstScript : MonoBehaviour { }
✔ 다른 스크립트보다 먼저 실행되도록 조정
[HelpURL("https://docs.unity3d.com")] - 인스펙터에 문서 링크 추가
[HelpURL("https://docs.unity3d.com")]
public class ExampleScript : MonoBehaviour { }
✔ 인스펙터에서 클릭하면 Unity 공식 문서로 이동
🔥 최종 추천 코드
using UnityEngine;
[HelpURL("https://example.com/docs")]
[RequireComponent(typeof(Rigidbody))]
[DisallowMultipleComponent]
public class ExperimentSettings : MonoBehaviour
{
[Header("Experiment Process Settings")]
[Tooltip("DNA 이중 나선을 풀기 위한 변성 온도입니다.")]
[Range(90, 98)]
public float DenaturationTemp = 94f;
[Tooltip("프라이머가 DNA 가닥에 결합하는 온도입니다.")]
[Range(50, 70)]
public float AnnealingTemp = 65f;
[Tooltip("DNA 중합효소가 새로운 가닥을 합성하는 온도입니다.")]
[Range(70, 75)]
public float ExtensionTemp = 72f;
[Space(10)]
[Header("Cycle Control")]
[Tooltip("현재 실행 중인 실험 사이클입니다.")]
public int CurrentCycle = 1;
[Tooltip("PCR 반응이 몇 번 반복될지 설정합니다.")]
[Range(1, 50)]
public int MaxCycles = 30;
[Space(10)]
[Header("Internal Variables (Hidden)")]
[SerializeField] private bool isExperimentRunning = false;
[ContextMenu("Reset Experiment")]
void ResetExperiment()
{
Debug.Log("Experiment Reset!");
}
[ContextMenuItem("Reset Counter", "ResetCounter")]
public int counter = 0;
void ResetCounter()
{
counter = 0;
}
}
💡 정리
속성 기능
[Header("제목")] | 제목 추가 |
[Space(n)] | 간격 추가 |
[Tooltip("설명")] | 설명 툴팁 표시 |
[Range(min, max)] | 슬라이더 UI |
[SerializeField] | private 변수 노출 |
[TextArea] | 여러 줄 입력 |
[HideInInspector] | 인스펙터에서 숨기기 |
[ContextMenu("함수 실행")] | 인스펙터에서 버튼 클릭 실행 |
[RequireComponent(typeof(X))] | 필수 컴포넌트 추가 |
[DisallowMultipleComponent] | 중복 추가 방지 |
[ExecuteInEditMode] | 에디터에서도 실행 |
[DefaultExecutionOrder(n)] | 스크립트 실행 순서 지정 |
[HelpURL("링크")] | 인스펙터에 문서 링크 추가 |