using System; using System.Collections.Generic; using UnityEngine; using UVC.UI.Tooltip; using UVC.UI.Window.PropertyWindow; /// /// PropertyWindow의 그룹 기능과 혼용 방식을 테스트하는 샘플입니다. /// public class PropertyWindowGroupSample : MonoBehaviour { [Header("Sample Mode")] [SerializeField] private SampleMode _sampleMode = SampleMode.Mixed; private enum SampleMode { Legacy, // 기존 방식 (그룹 없이 flat) GroupOnly, // 그룹만 사용 Mixed // 혼용 방식 } void Start() { TooltipManager.Instance.Initialize(); switch (_sampleMode) { case SampleMode.Legacy: LoadLegacySample(); break; case SampleMode.GroupOnly: LoadGroupOnlySample(); break; case SampleMode.Mixed: LoadMixedSample(); break; } // 이벤트 핸들러 등록 PropertyWindow.Instance.PropertyValueChanged += OnPropertyValueChanged; PropertyWindow.Instance.GroupExpandedChanged += OnGroupExpandedChanged; } /// /// [기존 방식] 그룹 없이 속성 목록을 로드합니다. /// private void LoadLegacySample() { Debug.Log("[PropertyWindowGroupSample] Legacy 방식으로 로드합니다."); PropertyWindow.Instance.LoadProperties(new List { new StringProperty("name", "Name", "Object1"), new IntProperty("count", "Count", 10), new BoolProperty("active", "Active", true), new ColorProperty("color", "Color", Color.white) }); } /// /// [그룹 방식] 그룹으로만 속성을 로드합니다. /// private void LoadGroupOnlySample() { Debug.Log("[PropertyWindowGroupSample] Group 방식으로 로드합니다."); var groups = new List { CreateTransformGroup(), CreateRenderingGroup(), CreatePhysicsGroup() }; PropertyWindow.Instance.LoadGroupedProperties(groups); } /// /// [혼용 방식] 그룹과 개별 아이템을 혼용하여 로드합니다. /// private void LoadMixedSample() { Debug.Log("[PropertyWindowGroupSample] Mixed 방식으로 로드합니다."); var entries = new List { // 상단에 그룹 없는 기본 정보 (Order: 0, 1) new StringProperty("id", "ID", "OBJ_001") { Order = 0 }, new StringProperty("name", "Name", "MyGameObject") { Order = 1 }, // Transform 그룹 (Order: 2) CreateTransformGroup(2), // 중간에 그룹 없는 아이템 (Order: 3) new BoolProperty("locked", "Locked", false) { Order = 3, Description = "잠금 상태입니다. 잠금 시 수정할 수 없습니다.", Tooltip = "객체 잠금 토글" }, // Rendering 그룹 (Order: 4) CreateRenderingGroup(4), // Physics 그룹 (Order: 5, 기본적으로 접힌 상태) CreatePhysicsGroup(5, false), // 하단에 그룹 없는 아이템 (Order: 6) new StringProperty("tags", "Tags", "Player, Movable") { Order = 6, Description = "쉼표로 구분된 태그 목록" } }; PropertyWindow.Instance.LoadMixedProperties(entries); } #region Group Factory Methods private PropertyGroup CreateTransformGroup(int order = 0) { var group = new PropertyGroup("transform", "Transform", order, true); group.AddItems(new IPropertyItem[] { new Vector3Property("position", "Position", Vector3.zero) { Tooltip = "월드 좌표계에서의 위치" }, new Vector3Property("rotation", "Rotation", Vector3.zero) { Tooltip = "오일러 각도 (도)" }, new Vector3Property("scale", "Scale", Vector3.one) { Tooltip = "로컬 스케일" } }); return group; } private PropertyGroup CreateRenderingGroup(int order = 0) { var group = new PropertyGroup("rendering", "Rendering", order, true); group.AddItems(new IPropertyItem[] { new BoolProperty("visible", "Visible", true) { Tooltip = "렌더링 활성화 여부" }, new ColorProperty("color", "Color", Color.white) { Description = "메인 색상" }, new FloatProperty("alpha", "Alpha", 1.0f, true, 0f, 1f) { Tooltip = "투명도 (0: 투명, 1: 불투명)" }, new EnumProperty("layer", "Layer", RenderLayer.Default) { Description = "렌더링 레이어" } }); return group; } private PropertyGroup CreatePhysicsGroup(int order = 0, bool isExpanded = true) { var group = new PropertyGroup("physics", "Physics", order, isExpanded); group.AddItems(new IPropertyItem[] { new BoolProperty("usePhysics", "Use Physics", false) { Tooltip = "물리 시뮬레이션 사용 여부" }, new FloatProperty("mass", "Mass", 1.0f, true, 0.1f, 100f) { Description = "질량 (kg)" }, new FloatProperty("drag", "Drag", 0.0f, true, 0f, 10f) { Tooltip = "공기 저항" }, new BoolProperty("useGravity", "Use Gravity", true) }); return group; } #endregion #region Event Handlers private void OnPropertyValueChanged(object sender, PropertyValueChangedEventArgs e) { Debug.Log($"[PropertyChanged] Id: {e.PropertyId}, Type: {e.PropertyType}, Value: {e.OldValue} -> {e.NewValue}"); } private void OnGroupExpandedChanged(object sender, PropertyGroupExpandedEventArgs e) { Debug.Log($"[GroupExpanded] Group: {e.Group.GroupName}, Expanded: {e.WasExpanded} -> {e.IsExpanded}"); } #endregion #region Dynamic API Test Methods /// /// 런타임에 그룹을 추가하는 테스트 메서드입니다. /// [ContextMenu("Add Debug Group")] public void AddDebugGroup() { var debugGroup = new PropertyGroup("debug", "Debug Settings", 10, true); debugGroup.AddItems(new IPropertyItem[] { new BoolProperty("showGizmos", "Show Gizmos", false), new BoolProperty("logEnabled", "Enable Logging", true), new IntProperty("logLevel", "Log Level", 1, true, 0, 3) }); PropertyWindow.Instance.AddGroup(debugGroup); Debug.Log("[PropertyWindowGroupSample] Debug 그룹이 추가되었습니다."); } /// /// 런타임에 개별 속성을 추가하는 테스트 메서드입니다. /// [ContextMenu("Add Single Property")] public void AddSingleProperty() { var timestamp = DateTime.Now.ToString("HHmmss"); PropertyWindow.Instance.AddProperty( new StringProperty($"dynamic_{timestamp}", $"Dynamic Property ({timestamp})", "New Value") { Order = 100 } ); Debug.Log("[PropertyWindowGroupSample] 개별 속성이 추가되었습니다."); } /// /// 기존 그룹에 속성을 추가하는 테스트 메서드입니다. /// [ContextMenu("Add Property to Transform Group")] public void AddPropertyToTransformGroup() { PropertyWindow.Instance.AddPropertyToGroup( "transform", new Vector3Property("pivot", "Pivot", new Vector3(0.5f, 0.5f, 0.5f)) { Description = "피벗 포인트" }, "Transform" // 그룹이 없을 경우 생성될 이름 ); Debug.Log("[PropertyWindowGroupSample] Transform 그룹에 속성이 추가되었습니다."); } /// /// 그룹을 토글하는 테스트 메서드입니다. /// [ContextMenu("Toggle Transform Group")] public void ToggleTransformGroup() { PropertyWindow.Instance.ToggleGroupExpanded("transform"); } #endregion private void OnDestroy() { if (PropertyWindow.Instance != null) { PropertyWindow.Instance.PropertyValueChanged -= OnPropertyValueChanged; PropertyWindow.Instance.GroupExpandedChanged -= OnGroupExpandedChanged; } } /// /// 샘플용 렌더 레이어 열거형 /// private enum RenderLayer { Default, UI, Background, Foreground, Effects } }