586 lines
21 KiB
C#
586 lines
21 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UVC.UI.Tooltip;
|
|
using UVC.UI.Window.PropertyWindow;
|
|
using UVC.Util;
|
|
|
|
public class PropertyWindowSample : MonoBehaviour
|
|
{
|
|
[SerializeField] private PropertyWindow propertyWindow;
|
|
|
|
[Header("Test Buttons")]
|
|
[SerializeField] private Button btnToggleBasicVisibility;
|
|
[SerializeField] private Button btnToggleBasicReadOnly;
|
|
[SerializeField] private Button btnTogglePropertyVisibility;
|
|
[SerializeField] private Button btnTogglePropertyReadOnly;
|
|
|
|
// 테스트용 상태 변수
|
|
private bool _isBasicGroupVisible = true;
|
|
private bool _isBasicGroupReadOnly = false;
|
|
private bool _isPropertyVisible = true;
|
|
private bool _isPropertyReadOnly = false;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
TooltipManager.Instance.Initialize();
|
|
|
|
// 혼용 방식 샘플: 그룹과 개별 아이템을 함께 사용
|
|
List<IPropertyEntry> entries = new List<IPropertyEntry>
|
|
{
|
|
// ========================================
|
|
// 상단: 그룹 없는 기본 정보 (Order: 0~1)
|
|
// ========================================
|
|
new StringProperty("id", "ID", "OBJ_001")
|
|
{
|
|
Order = 0,
|
|
Description = "객체 고유 식별자",
|
|
IsReadOnly = true
|
|
},
|
|
new StringProperty("name", "Name", "Sample Object")
|
|
{
|
|
Order = 1,
|
|
Tooltip = "객체 이름을 입력하세요"
|
|
},
|
|
|
|
// ========================================
|
|
// 동적 그룹 표시 테스트용 (Order: 2)
|
|
// ========================================
|
|
CreateDynamicVisibilityTestGroup(),
|
|
|
|
// ========================================
|
|
// Basic Properties 그룹 (Order: 3)
|
|
// ========================================
|
|
CreateBasicPropertiesGroup(),
|
|
|
|
// ========================================
|
|
// 중간: 그룹 없는 개별 아이템 (Order: 4)
|
|
// ========================================
|
|
new BoolProperty("locked", "Locked", false)
|
|
{
|
|
Order = 4,
|
|
Description = "잠금 시 수정 불가",
|
|
Tooltip = "객체 잠금 토글"
|
|
},
|
|
|
|
// ========================================
|
|
// Transform 그룹 (Order: 5)
|
|
// ========================================
|
|
CreateTransformGroup(),
|
|
|
|
// ========================================
|
|
// Date/Time 그룹 (Order: 6, 기본 접힘)
|
|
// ========================================
|
|
CreateDateTimeGroup(),
|
|
|
|
// ========================================
|
|
// Range 그룹 (Order: 7)
|
|
// ========================================
|
|
CreateRangeGroup(),
|
|
|
|
// ========================================
|
|
// Selection 그룹 (Order: 8)
|
|
// ========================================
|
|
CreateSelectionGroup(),
|
|
|
|
// ========================================
|
|
// 조건부 표시 그룹들 (Order: 9~11)
|
|
// ========================================
|
|
CreateConditionalGroupA(),
|
|
CreateConditionalGroupB(),
|
|
CreateConditionalGroupC(),
|
|
|
|
// ========================================
|
|
// 하단: 그룹 없는 개별 아이템 (Order: 12)
|
|
// ========================================
|
|
new StringProperty("tags", "Tags", "sample, demo")
|
|
{
|
|
Order = 12,
|
|
Description = "쉼표로 구분된 태그 목록"
|
|
}
|
|
};
|
|
|
|
propertyWindow.LoadMixedProperties(entries);
|
|
|
|
// 초기 상태: 조건부 그룹들 숨김 (Group A만 표시)
|
|
propertyWindow.SetGroupVisibility("conditional_b", false);
|
|
propertyWindow.SetGroupVisibility("conditional_c", false);
|
|
|
|
// 값 변경 이벤트 핸들러
|
|
propertyWindow.PropertyValueChanged += OnPropertyValueChanged;
|
|
|
|
// 그룹 펼침/접힘 이벤트 핸들러
|
|
propertyWindow.GroupExpandedChanged += (sender, e) =>
|
|
{
|
|
Debug.Log($"[GroupExpanded] Group:{e.Group.GroupName}, Expanded:{e.IsExpanded}");
|
|
};
|
|
|
|
// 테스트 버튼 초기화
|
|
SetupTestButtons();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 속성 값 변경 이벤트 핸들러
|
|
/// </summary>
|
|
private void OnPropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
|
|
{
|
|
Debug.Log($"[PropertyChanged] Id:{e.PropertyId}, Type:{e.PropertyType}, Value:{e.NewValue}");
|
|
|
|
// 동적 그룹 표시/비표시 테스트
|
|
if (e.PropertyId == "display_mode")
|
|
{
|
|
string selectedMode = e.NewValue as string;
|
|
HandleDisplayModeChanged(selectedMode);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 표시 모드 변경에 따른 그룹 가시성 처리
|
|
/// </summary>
|
|
private void HandleDisplayModeChanged(string mode)
|
|
{
|
|
// 모든 조건부 그룹 숨김
|
|
propertyWindow.SetGroupVisibility("conditional_a", false);
|
|
propertyWindow.SetGroupVisibility("conditional_b", false);
|
|
propertyWindow.SetGroupVisibility("conditional_c", false);
|
|
|
|
// 선택된 모드에 따라 해당 그룹만 표시
|
|
switch (mode)
|
|
{
|
|
case "Mode A":
|
|
propertyWindow.SetGroupVisibility("conditional_a", true);
|
|
Debug.Log("[DynamicVisibility] Mode A 선택 - Conditional Group A 표시");
|
|
break;
|
|
case "Mode B":
|
|
propertyWindow.SetGroupVisibility("conditional_b", true);
|
|
Debug.Log("[DynamicVisibility] Mode B 선택 - Conditional Group B 표시");
|
|
break;
|
|
case "Mode C":
|
|
propertyWindow.SetGroupVisibility("conditional_c", true);
|
|
Debug.Log("[DynamicVisibility] Mode C 선택 - Conditional Group C 표시");
|
|
break;
|
|
case "All":
|
|
propertyWindow.SetGroupVisibility("conditional_a", true);
|
|
propertyWindow.SetGroupVisibility("conditional_b", true);
|
|
propertyWindow.SetGroupVisibility("conditional_c", true);
|
|
Debug.Log("[DynamicVisibility] All 선택 - 모든 조건부 그룹 표시");
|
|
break;
|
|
case "None":
|
|
Debug.Log("[DynamicVisibility] None 선택 - 모든 조건부 그룹 숨김");
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 테스트 버튼 설정
|
|
/// </summary>
|
|
private void SetupTestButtons()
|
|
{
|
|
// 그룹 가시성 토글 버튼
|
|
if (btnToggleBasicVisibility != null)
|
|
{
|
|
btnToggleBasicVisibility.onClick.AddListener(() =>
|
|
{
|
|
_isBasicGroupVisible = !_isBasicGroupVisible;
|
|
propertyWindow.SetGroupVisibility("basic", _isBasicGroupVisible);
|
|
Debug.Log($"[Test] Basic Group Visibility: {_isBasicGroupVisible}");
|
|
});
|
|
}
|
|
|
|
// 그룹 ReadOnly 토글 버튼
|
|
if (btnToggleBasicReadOnly != null)
|
|
{
|
|
btnToggleBasicReadOnly.onClick.AddListener(() =>
|
|
{
|
|
_isBasicGroupReadOnly = !_isBasicGroupReadOnly;
|
|
propertyWindow.SetGroupReadOnly("basic", _isBasicGroupReadOnly);
|
|
Debug.Log($"[Test] Basic Group ReadOnly: {_isBasicGroupReadOnly}");
|
|
});
|
|
}
|
|
|
|
// 개별 속성 가시성 토글 버튼
|
|
if (btnTogglePropertyVisibility != null)
|
|
{
|
|
btnTogglePropertyVisibility.onClick.AddListener(() =>
|
|
{
|
|
_isPropertyVisible = !_isPropertyVisible;
|
|
propertyWindow.SetPropertyVisibility("string_normal", _isPropertyVisible);
|
|
Debug.Log($"[Test] Property 'string_normal' Visibility: {_isPropertyVisible}");
|
|
});
|
|
}
|
|
|
|
// 개별 속성 ReadOnly 토글 버튼
|
|
if (btnTogglePropertyReadOnly != null)
|
|
{
|
|
btnTogglePropertyReadOnly.onClick.AddListener(() =>
|
|
{
|
|
_isPropertyReadOnly = !_isPropertyReadOnly;
|
|
propertyWindow.SetPropertyReadOnly("int_slider", _isPropertyReadOnly);
|
|
Debug.Log($"[Test] Property 'int_slider' ReadOnly: {_isPropertyReadOnly}");
|
|
});
|
|
}
|
|
}
|
|
|
|
#region Group Factory Methods
|
|
|
|
/// <summary>
|
|
/// 동적 그룹 표시 테스트용 그룹 생성
|
|
/// </summary>
|
|
private PropertyGroup CreateDynamicVisibilityTestGroup()
|
|
{
|
|
var group = new PropertyGroup("dynamic_test", "Dynamic Visibility Test", order: 2, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new ListProperty("display_mode", "Display Mode",
|
|
new List<string> { "Mode A", "Mode B", "Mode C", "All", "None" },
|
|
"Mode A")
|
|
{
|
|
Description = "선택한 모드에 따라 아래 조건부 그룹이 표시/숨김됩니다",
|
|
Tooltip = "Mode A/B/C: 해당 그룹만 표시, All: 모두 표시, None: 모두 숨김"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 기본 타입 그룹 생성 (String, Int, Float, Bool)
|
|
/// </summary>
|
|
private PropertyGroup CreateBasicPropertiesGroup()
|
|
{
|
|
var group = new PropertyGroup("basic", "Basic Types", order: 3, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
// ---- StringProperty ----
|
|
new StringProperty("string_normal", "String (Normal)", "Hello World")
|
|
{
|
|
Description = "일반 문자열 입력",
|
|
Tooltip = "문자열을 입력하세요"
|
|
},
|
|
new StringProperty("string_readonly", "String (ReadOnly)", "Cannot Edit")
|
|
{
|
|
Description = "읽기 전용 문자열",
|
|
IsReadOnly = true
|
|
},
|
|
|
|
// ---- IntProperty ----
|
|
new IntProperty("int_normal", "Int (Normal)", 42)
|
|
{
|
|
Description = "일반 정수 입력",
|
|
Tooltip = "정수 값을 입력하세요"
|
|
},
|
|
new IntProperty("int_slider", "Int (Slider)", 50, isSlider: true, minValue: 0, maxValue: 100)
|
|
{
|
|
Description = "슬라이더로 표시되는 정수",
|
|
Tooltip = "0~100 사이의 값"
|
|
},
|
|
|
|
// ---- FloatProperty ----
|
|
new FloatProperty("float_normal", "Float (Normal)", 3.14f)
|
|
{
|
|
Description = "일반 실수 입력",
|
|
Tooltip = "실수 값을 입력하세요"
|
|
},
|
|
new FloatProperty("float_slider", "Float (Slider)", 0.5f, isSlider: true, minValue: 0f, maxValue: 1f)
|
|
{
|
|
Description = "슬라이더로 표시되는 실수",
|
|
Tooltip = "0.0~1.0 사이의 비율"
|
|
},
|
|
|
|
// ---- BoolProperty ----
|
|
new BoolProperty("bool_active", "Bool (Toggle)", true)
|
|
{
|
|
Description = "불리언 토글",
|
|
Tooltip = "활성화/비활성화 상태"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 색상 및 벡터 그룹 생성 (Color, Vector2, Vector3)
|
|
/// </summary>
|
|
private PropertyGroup CreateTransformGroup()
|
|
{
|
|
var group = new PropertyGroup("transform", "Color & Vectors", order: 5, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
// ---- ColorProperty ----
|
|
new ColorProperty("color_main", "Color", Color.red)
|
|
{
|
|
Description = "색상 선택",
|
|
Tooltip = "컬러 피커로 색상 선택"
|
|
},
|
|
new ColorProperty("color_alpha", "Color (with Alpha)", new Color(0.5f, 0.8f, 1f, 0.5f))
|
|
{
|
|
Description = "알파(투명도) 포함 색상"
|
|
},
|
|
|
|
// ---- Vector2Property ----
|
|
new Vector2Property("vec2_position", "Vector2 (Position)", new Vector2(100, 200))
|
|
{
|
|
Description = "2D 좌표",
|
|
Tooltip = "X, Y 값"
|
|
},
|
|
new Vector2Property("vec2_custom", "Vector2 (Custom Labels)", new Vector2(1920, 1080))
|
|
{
|
|
Description = "커스텀 라벨",
|
|
ChildNames = new List<string> { "Width", "Height" }
|
|
},
|
|
|
|
// ---- Vector3Property ----
|
|
new Vector3Property("vec3_position", "Vector3 (Position)", new Vector3(1, 2, 3))
|
|
{
|
|
Description = "3D 위치 좌표",
|
|
Tooltip = "X, Y, Z 값"
|
|
},
|
|
new Vector3Property("vec3_rotation", "Vector3 (Rotation)", Vector3.zero)
|
|
{
|
|
Description = "오일러 각도 (도)"
|
|
},
|
|
new Vector3Property("vec3_scale", "Vector3 (Scale)", Vector3.one)
|
|
{
|
|
Description = "로컬 스케일"
|
|
},
|
|
new Vector3Property("vec3_custom", "Vector3 (Custom Labels)", new Vector3(255, 128, 64))
|
|
{
|
|
Description = "커스텀 라벨",
|
|
ChildNames = new List<string> { "R", "G", "B" }
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 날짜/시간 그룹 생성 (Date, DateTime, DateRange, DateTimeRange)
|
|
/// </summary>
|
|
private PropertyGroup CreateDateTimeGroup()
|
|
{
|
|
var group = new PropertyGroup("datetime", "Date & Time Types", order: 6, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
// ---- DateProperty ----
|
|
new DateProperty("date_created", "Date (Created)", DateTime.Now.AddDays(-30))
|
|
{
|
|
Description = "날짜만 선택",
|
|
Tooltip = "날짜 선택",
|
|
IsReadOnly = true
|
|
},
|
|
new DateProperty("date_deadline", "Date (Deadline)", DateTime.Now.AddDays(7))
|
|
{
|
|
Description = "마감일 선택"
|
|
},
|
|
|
|
// ---- DateTimeProperty ----
|
|
new DateTimeProperty("datetime_modified", "DateTime (Modified)", DateTime.Now)
|
|
{
|
|
Description = "날짜와 시간 선택",
|
|
Tooltip = "날짜 + 시간"
|
|
},
|
|
new DateTimeProperty("datetime_schedule", "DateTime (Schedule)", DateTime.Now.AddHours(2))
|
|
{
|
|
Description = "예약 일시"
|
|
},
|
|
|
|
// ---- DateRangeProperty ----
|
|
new DateRangeProperty("daterange_period", "DateRange (Period)",
|
|
new Tuple<DateTime, DateTime>(DateTime.Now, DateTime.Now.AddMonths(1)))
|
|
{
|
|
Description = "날짜 범위 선택",
|
|
Tooltip = "시작일 ~ 종료일"
|
|
},
|
|
|
|
// ---- DateTimeRangeProperty ----
|
|
new DateTimeRangeProperty("datetimerange_hours", "DateTimeRange (Hours)",
|
|
new Tuple<DateTime, DateTime>(
|
|
DateTime.Today.AddHours(9),
|
|
DateTime.Today.AddHours(18)))
|
|
{
|
|
Description = "시간대 범위 선택",
|
|
Tooltip = "시작 시간 ~ 종료 시간"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 범위 그룹 생성 (IntRange, FloatRange)
|
|
/// </summary>
|
|
private PropertyGroup CreateRangeGroup()
|
|
{
|
|
var group = new PropertyGroup("range", "Range Types", order: 7, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
// ---- IntRangeProperty ----
|
|
new IntRangeProperty("intrange_priority", "IntRange (Priority)", new Tuple<int, int>(1, 10))
|
|
{
|
|
Description = "정수 범위",
|
|
Tooltip = "최소 ~ 최대 정수"
|
|
},
|
|
new IntRangeProperty("intrange_level", "IntRange (Level)", new Tuple<int, int>(5, 50))
|
|
{
|
|
Description = "레벨 범위"
|
|
},
|
|
|
|
// ---- FloatRangeProperty ----
|
|
new FloatRangeProperty("floatrange_temp", "FloatRange (Temperature)", new Tuple<float, float>(20.0f, 25.0f))
|
|
{
|
|
Description = "실수 범위",
|
|
Tooltip = "온도 범위 (°C)"
|
|
},
|
|
new FloatRangeProperty("floatrange_percent", "FloatRange (Percent)", new Tuple<float, float>(0.25f, 0.75f))
|
|
{
|
|
Description = "백분율 범위"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 선택 그룹 생성 (Enum, DropdownList, RadioGroup)
|
|
/// </summary>
|
|
private PropertyGroup CreateSelectionGroup()
|
|
{
|
|
var group = new PropertyGroup("selection", "Selection Types", order: 8, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
// ---- EnumProperty ----
|
|
new EnumProperty("enum_status", "Enum (Status)", SampleEnum.Option1)
|
|
{
|
|
Description = "열거형 선택",
|
|
Tooltip = "Enum 드롭다운"
|
|
},
|
|
new EnumProperty("enum_layer", "Enum (Layer)", SampleLayer.Default)
|
|
{
|
|
Description = "레이어 선택"
|
|
},
|
|
|
|
// ---- ListProperty (DropdownList) ----
|
|
new ListProperty("list_category", "DropdownList (Category)",
|
|
new List<string> { "Category A", "Category B", "Category C", "Category D" },
|
|
"Category A")
|
|
{
|
|
Description = "드롭다운 목록",
|
|
Tooltip = "문자열 목록에서 선택"
|
|
},
|
|
new ListProperty("list_country", "DropdownList (Country)",
|
|
new List<string> { "Korea", "Japan", "USA", "UK", "Germany", "France" },
|
|
"Korea")
|
|
{
|
|
Description = "국가 선택"
|
|
},
|
|
|
|
// ---- RadioGroupProperty ----
|
|
new RadioGroupProperty("radio_priority", "RadioGroup (Priority)",
|
|
new List<string> { "Low", "Medium", "High" },
|
|
"Medium")
|
|
{
|
|
Description = "라디오 버튼 그룹",
|
|
Tooltip = "하나만 선택 가능"
|
|
},
|
|
new RadioGroupProperty("radio_size", "RadioGroup (Size)",
|
|
new List<string> { "Small", "Medium", "Large", "XLarge" },
|
|
"Medium")
|
|
{
|
|
Description = "크기 선택"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 조건부 그룹 A 생성 (Mode A 선택 시 표시)
|
|
/// </summary>
|
|
private PropertyGroup CreateConditionalGroupA()
|
|
{
|
|
var group = new PropertyGroup("conditional_a", "Conditional Group A (Mode A)", order: 9, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new StringProperty("mode_a_name", "Mode A Name", "Alpha")
|
|
{
|
|
Description = "Mode A 전용 속성"
|
|
},
|
|
new IntProperty("mode_a_value", "Mode A Value", 100)
|
|
{
|
|
Description = "Mode A 전용 값"
|
|
},
|
|
new ColorProperty("mode_a_color", "Mode A Color", Color.red)
|
|
{
|
|
Description = "Mode A 전용 색상"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 조건부 그룹 B 생성 (Mode B 선택 시 표시)
|
|
/// </summary>
|
|
private PropertyGroup CreateConditionalGroupB()
|
|
{
|
|
var group = new PropertyGroup("conditional_b", "Conditional Group B (Mode B)", order: 10, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new StringProperty("mode_b_name", "Mode B Name", "Beta")
|
|
{
|
|
Description = "Mode B 전용 속성"
|
|
},
|
|
new FloatProperty("mode_b_value", "Mode B Value", 50.5f)
|
|
{
|
|
Description = "Mode B 전용 값"
|
|
},
|
|
new Vector2Property("mode_b_position", "Mode B Position", new Vector2(100, 200))
|
|
{
|
|
Description = "Mode B 전용 위치"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 조건부 그룹 C 생성 (Mode C 선택 시 표시)
|
|
/// </summary>
|
|
private PropertyGroup CreateConditionalGroupC()
|
|
{
|
|
var group = new PropertyGroup("conditional_c", "Conditional Group C (Mode C)", order: 11, isExpanded: true);
|
|
group.AddItems(new IPropertyItem[]
|
|
{
|
|
new StringProperty("mode_c_name", "Mode C Name", "Charlie")
|
|
{
|
|
Description = "Mode C 전용 속성"
|
|
},
|
|
new BoolProperty("mode_c_enabled", "Mode C Enabled", true)
|
|
{
|
|
Description = "Mode C 전용 토글"
|
|
},
|
|
new Vector3Property("mode_c_scale", "Mode C Scale", Vector3.one)
|
|
{
|
|
Description = "Mode C 전용 스케일"
|
|
}
|
|
});
|
|
return group;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Sample Enums
|
|
|
|
enum SampleEnum
|
|
{
|
|
Option1,
|
|
Option2,
|
|
Option3
|
|
}
|
|
|
|
enum SampleLayer
|
|
{
|
|
Default,
|
|
UI,
|
|
Background,
|
|
Foreground,
|
|
Effects
|
|
}
|
|
|
|
#endregion
|
|
}
|