Example #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            Begin(position, property, label);

            float min = ((SliderAttribute)attribute).min;
            float max = ((SliderAttribute)attribute).max;

            EditorGUI.BeginChangeCheck();

            currentPosition.height = 16;
            object value = property.GetValue();

            if (value is int) {
                property.SetValue(EditorGUI.IntSlider(currentPosition, label, (int)value, (int)min, (int)max));
            }
            else if (value is float) {
                property.SetValue(EditorGUI.Slider(currentPosition, label, (float)value, min, max));
            }
            else if (value is double) {
                property.SetValue(EditorGUI.Slider(currentPosition, label, (float)(double)value, min, max));
            }
            else {
                EditorGUI.HelpBox(currentPosition, "The type of the field must be numerical.", MessageType.Error);
            }

            if (EditorGUI.EndChangeCheck()) {
                property.Clamp(min, max);
            }

            End();
        }
Example #2
0
		public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
			drawPrefixLabel = false;
			
			Begin(position, property, label);
			
			float min = ((ClampAttribute)attribute).min;
			float max = ((ClampAttribute)attribute).max;
		
			EditorGUI.BeginChangeCheck();
			EditorGUI.PropertyField(currentPosition, property, label, true);
			if (EditorGUI.EndChangeCheck()) {
				property.Clamp(min, max);
			}
			
			End();
		}