Пример #1
0
        internal VisualElement CreateGUI(
            ValueChangedCallback valueChangedCallback,
            Vector2 fieldToDraw,
            string labelName,
            out VisualElement propertyVec2Field,
            int indentLevel = 0)
        {
            var vector2Field = new Vector2Field {
                value = fieldToDraw
            };

            var inputFields = vector2Field.Query("unity-text-input").ToList();

            foreach (var inputField in inputFields)
            {
                inputField.RegisterCallback <KeyDownEvent>(m_KeyDownCallback, TrickleDown.TrickleDown);
                inputField.RegisterCallback <FocusOutEvent>(m_FocusOutCallback, TrickleDown.TrickleDown);
            }
            // Bind value changed event to callback to handle dragger behavior before actually settings the value
            vector2Field.RegisterValueChangedCallback(evt =>
            {
                // Only true when setting value via FieldMouseDragger
                // Undo recorded once per dragger release
                if (mUndoGroup == -1)
                {
                    preValueChangeCallback?.Invoke();
                }

                valueChangedCallback(evt.newValue);
                postValueChangeCallback?.Invoke();
            });

            propertyVec2Field = vector2Field;

            var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));

            defaultRow.Add(propertyVec2Field);
            defaultRow.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow"));
            return(defaultRow);
        }