Simply record
the reference article https://blog.csdn.net/duzixi/article/details/78013295
originally wanted to inherit the image, like the Sprite Swap type of Transition in the button, there is a gray image
public class SwapImage : Image
{
public Sprite graySprite;
public bool isGray;
}
But then I found that the editor does not display my public properties. After searching, I found out that I need the corresponding ImageEditor.
[CustomEditor(typeof(SwapImage))]
public class SwapImageEditor : ImageEditor
{
SerializedProperty graySprite;
SerializedProperty isGray;
protected override void OnEnable()
{
base.OnEnable();
graySprite = serializedObject.FindProperty(nameof(SwapImage.graySprite));
isGray = serializedObject.FindProperty(nameof(SwapImage.isGray));
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
// DrawDefaultInspector();
serializedObject.Update();
EditorGUILayout.PropertyField(graySprite);
EditorGUILayout.PropertyField(isGray);
serializedObject.ApplyModifiedProperties();
}
}
Finally, I would like to ask, I want to refresh the UI when changing isGray, is there an easier way besides setting the picture in OnEnable Start OnValidate?