internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue)
{
InitStyles();
if (prop.hasMultipleDifferentValues)
{
EditorGUILayout.TargetChoiceField(prop, label, new GUILayoutOption[0]);
}
else
{
AnimationCurve animationCurveValue = prop.animationCurveValue;
if (animationCurveValue == null)
{
Debug.LogError(label.text + " curve is null!");
}
else if (animationCurveValue.length == 0)
{
Debug.LogError(label.text + " curve has no keys!");
}
else
{
if (animationCurveValue.length != 1)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.LabelField(label.text, ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]);
EditorGUI.EndDisabledGroup();
}
else
{
float v = !useNormalizedValue ? animationCurveValue.keys[0].value : Mathf.Lerp(min, max, animationCurveValue.keys[0].value);
v = MathUtils.DiscardLeastSignificantDecimal(v);
EditorGUI.BeginChangeCheck();
if (max > min)
{
v = EditorGUILayout.Slider(label, v, min, max, new GUILayoutOption[0]);
}
else
{
v = EditorGUILayout.Slider(label, v, max, min, new GUILayoutOption[0]);
}
if (EditorGUI.EndChangeCheck())
{
Keyframe key = animationCurveValue.keys[0];
key.time = 0f;
key.value = !useNormalizedValue ? v : Mathf.InverseLerp(min, max, v);
animationCurveValue.MoveKey(0, key);
}
}
prop.animationCurveValue = animationCurveValue;
}
}
}