Hey,
I’m trying to animate a material property via the animation window. Ideally I’d like it to be a setter (via a custom script) so I won’t have to check in an Update to know if the value changed.
Since getter/setter aren’t displayed in the Inspector, I made a CustomEditor script but it doesn’t work via the animation window:
using UnityEditor;
[CustomEditor(typeof(BrushMaterialControl))]
public class BrushMaterialControlEditor : Editor {
SerializedProperty clip;
void OnEnable() {
clip = serializedObject.FindProperty("clip");
}
public override void OnInspectorGUI() {
EditorGUI.BeginChangeCheck();
DrawDefaultInspector();
clip.floatValue = EditorGUILayout.Slider("Clip", clip.floatValue, 0.0f, 1.0f);
if (EditorGUI.EndChangeCheck()) {
((BrushMaterialControl)target).Clip = clip.floatValue;
clip.serializedObject.ApplyModifiedProperties();
}
}
}
using UnityEngine;
[ExecuteInEditMode]
public class BrushMaterialControl : MonoBehaviour {
[SerializeField, HideInInspector]
private float clip = 0;
public float Clip {
get { return clip; }
set {
Debug.Log("ok");
if (value != clip) {
clip = value;
}
}
}
}
When I change the slider via Inspector the Debug Log is output, but not when it’s modified via the animation…
Any ideas?