샘플 코드 개선. UTKHelpBox 개선

This commit is contained in:
logonkhi
2026-01-26 20:00:21 +09:00
parent 99f9c3b26d
commit 097436a8b0
18 changed files with 1321 additions and 81 deletions

View File

@@ -13,6 +13,147 @@ public partial class UTKStyleGuideSample
{
#region Button Initializers
private void InitializeCheckBoxSample(VisualElement root)
{
SetCodeSamples(root,
csharpCode: @"// 기본 체크박스
var checkbox = new UTKCheckBox();
checkbox.Text = ""약관에 동의합니다"";
checkbox.OnValueChanged += (isChecked) => Debug.Log($""체크: {isChecked}"");
// 상태 설정
checkbox.IsChecked = true;
checkbox.IsIndeterminate = true; // 부분 선택 상태
// 생성자로 생성
var acceptCheckbox = new UTKCheckBox(""이메일 수신 동의"", true);
// 비활성화
checkbox.IsEnabled = false;
// 상태 확인
if (checkbox.IsChecked)
{
Debug.Log(""체크되어 있습니다"");
}
// 토글
checkbox.IsChecked = !checkbox.IsChecked;",
uxmlCode: @"<!-- 네임스페이스 선언 -->
<ui:UXML xmlns:utk=""UVC.UIToolkit"">
<!-- 기본 체크박스 -->
<utk:UTKCheckBox text=""이메일 수신 동의"" />
<!-- 기본값 체크됨 -->
<utk:UTKCheckBox text=""자동 로그인"" is-checked=""true"" />
<!-- 불확정 상태 -->
<utk:UTKCheckBox text=""부분 선택"" is-indeterminate=""true"" />
<!-- 비활성화 -->
<utk:UTKCheckBox text=""필수 동의"" is-enabled=""false"" is-checked=""true"" />
</ui:UXML>");
}
private void InitializeToggleSample(VisualElement root)
{
SetCodeSamples(root,
csharpCode: @"// 기본 토글
var toggle = new UTKToggle();
toggle.label = ""알림 받기""; // Unity Toggle의 label 프로퍼티 (소문자)
toggle.IsOn = true;
toggle.OnValueChanged += (isOn) => Debug.Log($""토글: {isOn}"");
// 생성자로 생성
var darkModeToggle = new UTKToggle(""다크 모드"");
// 상태 설정 (알림 없이)
toggle.SetOn(true, notify: false);
// 상태 설정 (알림 포함)
toggle.SetOn(false, notify: true);
// 비활성화
toggle.IsEnabled = false;
// 상태 확인
if (toggle.IsOn)
{
Debug.Log(""켜져 있습니다"");
}",
uxmlCode: @"<!-- 네임스페이스 선언 -->
<ui:UXML xmlns:utk=""UVC.UIToolkit"">
<!-- 기본 토글 -->
<utk:UTKToggle label=""다크 모드"" />
<!-- 기본값 켜짐 -->
<utk:UTKToggle label=""자동 저장"" is-on=""true"" />
<!-- 비활성화 (꺼짐) -->
<utk:UTKToggle label=""프리미엄 기능"" is-enabled=""false"" />
<!-- 비활성화 (켜짐) -->
<utk:UTKToggle label=""필수 기능"" is-on=""true"" is-enabled=""false"" />
</ui:UXML>");
}
private void InitializeRadioButtonSample(VisualElement root)
{
SetCodeSamples(root,
csharpCode: @"// 라디오 버튼 그룹
var group = new RadioButtonGroup();
var radio1 = new UTKRadioButton { text = ""옵션 1"" };
var radio2 = new UTKRadioButton { text = ""옵션 2"" };
var radio3 = new UTKRadioButton { text = ""옵션 3"" };
group.Add(radio1);
group.Add(radio2);
group.Add(radio3);
// 선택 이벤트
radio1.OnValueChanged += (isSelected) =>
{
if (isSelected) Debug.Log(""옵션 1 선택됨"");
};
// 생성자로 생성
var optionA = new UTKRadioButton(""옵션 A"");
// 프로그램으로 선택
radio2.SetChecked(true, notify: true);
// 비활성화
radio3.IsEnabled = false;
// 현재 선택 확인
if (radio1.IsChecked)
{
Debug.Log(""라디오 1이 선택됨"");
}",
uxmlCode: @"<!-- 네임스페이스 선언 -->
<ui:UXML xmlns:utk=""UVC.UIToolkit"">
<!-- 라디오 버튼 그룹 -->
<ui:RadioButtonGroup>
<utk:UTKRadioButton text=""소형"" />
<utk:UTKRadioButton text=""중형"" is-checked=""true"" />
<utk:UTKRadioButton text=""대형"" />
</ui:RadioButtonGroup>
<!-- 비활성화 옵션 포함 -->
<ui:RadioButtonGroup>
<utk:UTKRadioButton text=""옵션 A"" is-checked=""true"" />
<utk:UTKRadioButton text=""옵션 B"" />
<utk:UTKRadioButton text=""옵션 C"" />
<utk:UTKRadioButton text=""비활성화"" is-enabled=""false"" />
</ui:RadioButtonGroup>
</ui:UXML>");
}
private void InitializeButtonSample(VisualElement root)
{
// Icon Only 버튼 추가
@@ -202,9 +343,12 @@ group1.AddButton(""Option 2"");
group1.AddButton(""Option 3"");
// 선택 이벤트
group1.OnSelectionChanged += (index) =>
group1.OnSelectionChanged += (indices) =>
{
Debug.Log($""선택된 버튼: {index}"");
foreach (var index in indices)
{
Debug.Log($""선택된 버튼: {index}"");
}
};
// Multiple Selection
@@ -214,18 +358,15 @@ group2.AddButton(""B"");
group2.AddButton(""C"");
group2.AddButton(""D"");
group2.OnSelectionChanged += (index) =>
group2.OnSelectionChanged += (indices) =>
{
Debug.Log($""토글된 버튼: {index}"");
Debug.Log($""토글된 버튼: {indices.Count()}"");
};
// 선택된 인덱스 가져오기
var selectedIndex = group1.SelectedIndex; // Single
var selectedIndices = group2.SelectedIndices; // Multiple
// 프로그램으로 선택
group1.SelectButton(1); // 두 번째 버튼 선택
group2.ToggleButton(0); // 첫 번째 버튼 토글
// 선택된 인덱스 가져오기 (Unity 기본 API)
var state = group1.value;
var buffer = new int[state.length];
var activeOptions = state.GetActiveOptions(buffer);
// Disabled
var group3 = new UTKToggleButtonGroup { IsEnabled = false };