Assets/Editor/RangIntDrawer.cs
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(HpMpAttribute))]
class HpMpDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
string name = ((HpMpAttribute)attribute).Name;
int min = ((HpMpAttribute)attribute).Min;
int max = ((HpMpAttribute)attribute).Max;
property.intValue = Mathf.Clamp(property.intValue, min, max);
Rect rect1 = new Rect(position.x, position.y + 5, position.width, 20);
EditorGUI.IntSlider(rect1, property, min, max, $"{name}({property.name})");
float value = ((float)property.intValue - min) / (max - min);
Rect rect2 = new Rect(position.x, position.y + 30, position.width, 20);
EditorGUI.ProgressBar(rect2, value, $"{name}:{property.intValue}");
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return 50f;
}
}