internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue)
{
// AnimProp can be called from other classes so styes have not necessarily been inited yet.
InitStyles();
if (prop.hasMultipleDifferentValues)
{
EditorGUILayout.TargetChoiceField(prop, label);
return;
}
AnimationCurve curve = prop.animationCurveValue;
if (curve == null)
{
Debug.LogError(label.text + " curve is null!");
return;
}
else if (curve.length == 0)
{
Debug.LogError(label.text + " curve has no keys!");
return;
}
Rect position = EditorGUILayout.GetControlRect();
EditorGUI.BeginProperty(position, label, prop);
if (curve.length != 1)
{
using (new EditorGUI.DisabledScope(true))
{
EditorGUI.LabelField(position, label.text, ms_Styles.controlledByCurveLabel);
}
}
else
{
float f = useNormalizedValue ? Mathf.Lerp(min, max, curve.keys[0].value) : curve.keys[0].value;
f = MathUtils.DiscardLeastSignificantDecimal(f);
EditorGUI.BeginChangeCheck();
if (max > min)
{
f = EditorGUI.Slider(position, label, f, min, max);
}
else
{
f = EditorGUI.Slider(position, label, f, max, min);
}
if (EditorGUI.EndChangeCheck())
{
Keyframe kf = curve.keys[0];
kf.time = 0.0f;
kf.value = useNormalizedValue ? Mathf.InverseLerp(min, max, f) : f;
curve.MoveKey(0, kf);
}
}
EditorGUI.EndProperty();
prop.animationCurveValue = curve;
}