Hi,
so i’m here, trying to save my own AnimationCurve as .asset into my unity folder.
So far i can save them into a simple ScriptableObject with one field (AnimationCurve)
but i can’t load my saved AnimationCurve into a script’s InspectorField
Here the code full code:
[CustomPropertyDrawer(typeof(AnimationCurve))]
public class AnimationCurveDrawer : PropertyDrawer
{
private T CreateAsset<T>() where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T>();
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
}
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset");
AssetDatabase.CreateAsset(asset, assetPathAndName);
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
return asset;
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return 17f;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (Event.current.type == EventType.DragExited && DragAndDrop.objectReferences.Length > 0)
{
for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
{
if (DragAndDrop.objectReferences*.GetType() == typeof(AnimationCurveCustomAsset))*
-
{*
_ Debug.Log("Hey ? " + (DragAndDrop.objectReferences as AnimationCurveCustomAsset).curve);_
_ property.animationCurveValue = (DragAndDrop.objectReferences as AnimationCurveCustomAsset).curve;
* return;
}
}
}
if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
{
GenericMenu menu = new GenericMenu();*_
* menu.AddItem(new GUIContent(“Save”), false, (q) =>*
* {*
* this.CreateAsset().curve = property.animationCurveValue;*
* }, “Save”);*
* menu.ShowAsContext();*
* }*
* property.animationCurveValue = EditorGUI.CurveField(position, label, property.animationCurveValue);*
* }*
}
Am I doing something wrong here ?
(btw: I gived up on how the MouseCursor look…)