using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace SzafaKitEditor.VisualElements { public class CVarPropertyField : VisualElement { readonly SerializedProperty _cvarProperty; readonly SerializedProperty _defaultValueKindProperty; readonly SerializedProperty _defaultValueNumberProperty; readonly SerializedProperty _defaultValueProperty; readonly SerializedProperty _defaultValueStringProperty; VisualElement _details; bool _expand; readonly SerializedProperty _nameProperty; public CVarPropertyField(SerializedProperty cvarProperty) { _cvarProperty = cvarProperty; _nameProperty = _cvarProperty.FindPropertyRelative("Name"); _defaultValueProperty = _cvarProperty.FindPropertyRelative("DefaultValue"); _defaultValueKindProperty = _defaultValueProperty.FindPropertyRelative("Kind"); _defaultValueNumberProperty = _defaultValueProperty.FindPropertyRelative("NumberValue"); _defaultValueStringProperty = _defaultValueProperty.FindPropertyRelative("StringValue"); CreateInlineField(); CreateDetailsBox(); } void CreateInlineField() { VisualElement box = new() { style = { height = 48 } }; Label nameLabel = new("NAME") { style = { unityFontStyleAndWeight = FontStyle.Bold, backgroundColor = new Color(0.1f, 0.1f, 0.1f, 1.0f) } }; box.Add(nameLabel); Button button = new(ToggleDetails) { text = "...", style = { width = new StyleLength(new Length(64.0f, LengthUnit.Pixel)), height = new StyleLength(new Length(64.0f, LengthUnit.Pixel)) } }; box.Add(button); Add(box); } void ToggleDetails() { _expand = !_expand; _details.visible = _expand; _details.style.display = DisplayStyle.None; } void CreateDetailsBox() { PropertyField nameField = new(_nameProperty); PropertyField defaultValueKindField = new(_defaultValueKindProperty); PropertyField numberField = new(_defaultValueNumberProperty); PropertyField stringField = new(_defaultValueStringProperty); _details = new VisualElement { style = { backgroundColor = new Color(0.1f, 0.1f, 0.1f, 1.0f) } }; _details.Add(nameField); _details.Add(defaultValueKindField); _details.Add(numberField); _details.Add(stringField); _details.visible = false; _details.style.display = DisplayStyle.None; Add(_details); } } }