protected override void OnEditorPrefGUI(Rect position, GUIContent label)
        {
            BeginBlock(metadata, position);

            T   newValue;
            var oldValue = Convert.ToSingle(metadata.value);

            var fieldPosition = new Rect
                                (
                position.x,
                position.y,
                position.width,
                EditorGUIUtility.singleLineHeight - 2
                                );

            if (metadata.HasAttribute <InspectorRangeAttribute>())
            {
                var rangeAttribute = metadata.GetAttribute <InspectorRangeAttribute>();

                newValue = (T)Convert.ChangeType(EditorGUI.Slider(fieldPosition, label, oldValue, rangeAttribute.min, rangeAttribute.max), typeof(T));
            }
            else
            {
                newValue = (T)Convert.ChangeType(LudiqGUI.DraggableFloatField(fieldPosition, oldValue, label), typeof(T));
            }

            if (EndBlock(metadata))
            {
                metadata.RecordUndo();
                metadata.value = newValue;
            }
        }
Пример #2
0
        protected override void OnControlGUI(Rect position)
        {
            EditorGUI.BeginChangeCheck();

            T   newValue;
            var oldValue = Convert.ToSingle(accessor.value);

            if (rangeAttribute != null)
            {
                newValue = (T)Convert.ChangeType(EditorGUI.Slider(position, oldValue, rangeAttribute.min, rangeAttribute.max), typeof(T));
            }
            else
            {
                newValue = (T)Convert.ChangeType(LudiqGUI.DraggableFloatField(position, oldValue), typeof(T));
            }

            if (EditorGUI.EndChangeCheck())
            {
                accessor.RecordUndo();
                accessor.value = newValue;
            }
        }
        protected override void OnGUI(Rect position, GUIContent label)
        {
            position = BeginLabeledBlock(metadata, position, label);

            T newValue;

            var fieldPosition = new Rect
                                (
                position.x,
                position.y,
                position.width,
                EditorGUIUtility.singleLineHeight
                                );

            if (metadata.HasAttribute <InspectorRangeAttribute>())
            {
                var rangeAttribute = metadata.GetAttribute <InspectorRangeAttribute>();

                newValue = (T)Convert.ChangeType(EditorGUI.Slider(fieldPosition, Convert.ToSingle(metadata.value), rangeAttribute.min, rangeAttribute.max), typeof(T));
            }
            else
            {
                if (Is64Bits(metadata.value))
                {
                    newValue = (T)Convert.ChangeType(LudiqGUI.DraggableLongField(fieldPosition, Convert.ToInt64(metadata.value)), typeof(T));
                }
                else
                {
                    newValue = (T)Convert.ChangeType(LudiqGUI.DraggableFloatField(fieldPosition, Convert.ToSingle(metadata.value)), typeof(T));
                }
            }

            if (EndBlock(metadata))
            {
                metadata.RecordUndo();
                metadata.value = newValue;
            }
        }