コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】AnimationCurve の設定範囲を 0 から 1 に制限できるエディタ拡張

ソースコード

using UnityEngine;
 
public sealed class Curve01Attribute : PropertyAttribute
{
}
using UnityEditor;
using UnityEngine;

[CustomPropertyDrawer( typeof( Curve01Attribute ) )]
public sealed class Curve01Drawer : PropertyDrawer
{
    public override void OnGUI
    (
        Rect               position,
        SerializedProperty property,
        GUIContent         label
    )
    {
        if ( property.propertyType != SerializedPropertyType.AnimationCurve ) return;

        var ranges = new Rect( 0, 0, 1, 1 );

        EditorGUI.CurveField
        (
         position: position,
         property: property,
         color: Color.cyan,
         ranges: ranges
        );
    }
}

参考サイト様