Unity custom editor create new mesh if values change

212 Views Asked by At

I have a script that inherits from Graphics class to draw a mesh. I created a custom editor script (see example below) it. However, when values get changed in the custom editor, OnPopulateMesh is not called, but without the custom editor the mesh was always drawn new when the variables changed. How can I trigger the mesh script to create a new one and achieve the same behaviour as before?

This is how my custom editor script looks like:

public override void OnInspectorGUI()
{
    MeshScript ms = (MeshScript) target;

    ms.positionType = (MeshScript.PositionType)EditorGUILayout.EnumPopup("Positioning", ms.positionType);

    if (ms.positionType == MeshScript.PositionType.RectTransform)
    {
        ms.point1Transform = EditorGUILayout.ObjectField("Transform 1", ms.point1Transform, typeof(RectTransform), true) as RectTransform;
        ms.point2Transform = EditorGUILayout.ObjectField("Transform 2", ms.point2Transform, typeof(RectTransform), true) as RectTransform;
    }
    else if(ms.positionType == MeshScript.PositionType.Vector)
    {
        ms.point1Vector = EditorGUILayout.Vector2Field("Vector 1", ms.point1Vector);
        ms.point2Vector = EditorGUILayout.Vector2Field("Vector 2", ms.point2Vector);
    }
}

I hope you can help me, thanks for your help in advance!

0

There are 0 best solutions below