custom editor for variable

lets assume we have our class

[System.Serializable]
public class OurClass
{
   int a = 0;
   string b = "blabla"
}

in the test script we describe a variable of our class

public class Test : MonoBehaviour
{
  public OurClass ourClass = new OurClass();
}

As a default we see in inspector a foldout with int and string variables
But what if I want my variable look different? Is it any possible? For example AnimationCurve has its own presence in inspector…
So, any ideas? :face_with_spiral_eyes:

Hi,

You can implement a custom inspector for your type.

Drop this script in to your Assets/Editor folder and you’re good to go:

[CustomEditor(typeof(OurClass))]
public class OurClassInspector : Editor
{
	public override void OnInspectorGUI()
	{
		// Set up your GUI here
		target.a = EditorGUILayout.Slider(target.a, 0, 100);
	}
}

Read more here: Unity - Scripting API: Editor

But OurClass is not derived from MonoBehaviour, so it cannot be used as component.
I’d like to use it as a type for a variable and see custom inspector only for this variable - when it’s declared in another script.

up :frowning:

you will need a custom editor for the monobehaviour that includes them so you can expose whatever you want.

but what if such variables can be in different scripts? custom editor for each script with this var - great pain in the ass )))

Might be, but you will have to cope with it if you want it to look different or you will just see what they are and what comes out due to the serialization.
Don’t use an int, float or string if you want it to be an animation curve

Also its a 1 time work per class basically so not a problem.