using System; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; namespace EditorAttributes.Editor { [CustomPropertyDrawer(typeof(TimeFieldAttribute)), Obsolete] public class TimeFieldDrawer : PropertyDrawerBase { public override VisualElement CreatePropertyGUI(SerializedProperty property) { var timeFieldAttribute = attribute as TimeFieldAttribute; var timeVectorSaveKeyX = CreatePropertySaveKey(property, "TimeX"); var timeVectorSaveKeyY = CreatePropertySaveKey(property, "TimeY"); var timeVectorSaveKeyZ = CreatePropertySaveKey(property, "TimeZ"); var root = new VisualElement(); var errorBox = new HelpBox(); if (!UnitConverter.IsUnitInCategory(timeFieldAttribute.ConversionUnit, UnitCategory.Time)) { errorBox.text = $"The conversion unit {timeFieldAttribute.ConversionUnit} is not a valid time unit"; DisplayErrorBox(root, errorBox); return root; } if (property.propertyType is SerializedPropertyType.Float or SerializedPropertyType.Integer) { var timeField = new Vector3Field(property.displayName) { value = new Vector3(EditorPrefs.GetFloat(timeVectorSaveKeyX), EditorPrefs.GetFloat(timeVectorSaveKeyY), EditorPrefs.GetFloat(timeVectorSaveKeyZ)), tooltip = property.tooltip }; timeField.AddToClassList(BaseField.alignedFieldUssClassName); AddPropertyContextMenu(timeField, property); timeField.RegisterValueChangedCallback((callback) => { switch (property.propertyType) { case SerializedPropertyType.Float: property.floatValue = GetConvertedTimeValue(callback.newValue, timeFieldAttribute); break; case SerializedPropertyType.Integer: property.intValue = Mathf.RoundToInt(GetConvertedTimeValue(callback.newValue, timeFieldAttribute)); break; } EditorPrefs.SetFloat(timeVectorSaveKeyX, callback.newValue.x); EditorPrefs.SetFloat(timeVectorSaveKeyY, callback.newValue.y); EditorPrefs.SetFloat(timeVectorSaveKeyZ, callback.newValue.z); property.serializedObject.ApplyModifiedProperties(); }); root.Add(timeField); ExecuteLater(timeField, () => { var labels = timeField.Query