Can I custom inspector in this condition

Hi
I would like to see when I change a enum’s value my inspector will change too I can do this if I use the script directly but when I use through others script I not change

Example

I have 2 Class

[System.Serializable]
public class TestA
    {
    public enum Type
        {
        Test1, Test2
        };
    public Type type;
    public bool Test1;
    public bool Test2;
    }

public class TestB : MonoBehaviour
    {
    public TestA a;
    }

Edit1. Add figures
Ok I’m sorry for my english
I mean when I change the enum in TestB the inspector will change too
Ex.
when change TestB.a.type to Test1 in the inspector this inspector will show only bool Test1 ,
when I change TestB.a.type to Test2 in the inspector this inspector will show only bool Test2

a first figure when I change the enum to Test1 in TestB.cs
a second figure when I change the enum to Test2 in TestB.cs

If I wrote unclear please let me know

Yeah, I can’t tell what you want here.

Enums can be shown in custom inspectors with the Popup. If you want class B to have stuff in it then extend a new editor for it and draw the base inspector before drawing class B’s inspector. They’ll stack normally.

I don’t know what those bools are for. You need to be more specific.

perhaps you should show the editor scripting you are using. my hunch is that you are not calling serializedObject.Update(). thus when the Enum is changed the class data has changed but the inspector’s data has not.

it can also be a repaint issue. The Inspector repaints only under specific times. most mouse events (except for mouse move) and keyboard events (when the inspector is selected) will repaint the inspector. Calling Repaint() inside the Editor class will force a repaint. However if you want to update the inspector from a different window (or propertyDrawer) you can manually set the target object dirty to trigger a Repaint.

EditorUtility.SetDirty(targetObject);

This is all guesswork. your post was very unclear, so please elaborate.

I have edited my post.

So… you want to conditionally show properties in the inspector based on the current Enum value?

You mean like this?

using UnityEngine;
using UnityEditor;

[CustomEdtior(typeof(TestA))]
public class TestAEditor: Editor
{

    private static readonly string k_type  = "type";
    private static readonly string k_Test1 = "Test1";
    private static readonly string k_Test2 = "Test2";

    private SerializableProperty p_type;
    private SerializableProperty p_Test1;
    private SerializableProperty p_Test2;

    public void OnInspectorGUI()
    {
        serializableObject.Update();

        p_type  = serializableObject.FindProperty(k_type);
        p_Test1 = serializableObject.FindProperty(k_Test1);
        p_Test2 = serializableObject.FindProperty(k_Test2);

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.PropertyField(p_type);

        switch(p_type.enumValueIndex)
        {
            case 0:
                EditorGUILayout.PropertyField(p_Test1);
                break;
            case 1:
                EditorGUILayout.PropertyField(p_Test2);
                break;
        }

        if(EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }

}
1 Like

Yes
but incase I use TestA.cs as a instance in TestB.cs when I change the enum value in TestB my inspector not change
Can I change the enum value in TestB my inspector change too ?