- Home /
How to hide/show serialized class object in the inspector with boolean value change?
I don't know if I worded it correctly but I hope you get it. I have a Dialogue class that among other things contains boolean value 'isOptionDialogue' and array of serialized DialogOption class objects that contain int and string value. Code looks like so:
public class Dialogue : MonoBehaviour
{
//some other stuff
public bool isOptionDialogue;
public DialogOption[] dialogOptions;
}
[Serializable]
public class DialogOption
{
public int targetIndex;
public string optionSentence;
}
and it shows in the inspectior like so:
But I want to make it so it only shows Dialog Options when bool IsOptionDialogue is set to true.
Is false:
Is true:
I am really bad with UnityEditor stuff. I followed some sample code I found and tried doing something by overriding OnInspectorGUI() and drawing things with EditorGUILayout but I only got it to work with simple variables. I have no idea how to draw an array of serialized class objects. Please help
Answer by hexagonius · Oct 07, 2018 at 09:47 AM
unity answers usually has all the answers already available, it's just a matter of searching the right way. I found this for your case:
https://answers.unity.com/questions/26207/how-can-i-recreate-the-array-inspector-element-for.html
A lot of thing used in this post are depracated. I tried playing around with it anyway and all I got is 'multi-object editing not supported' message in the inspector (don't know what causes that). As I said, I'm pretty bad at UnityEditor stuff and I don't feel like spending too much time on learning UnityEditor just to achieve one little thing.
Your answer
Follow this Question
Related Questions
How to play mecanim animations in Editor mode? 2 Answers
Undo.RecordObject and Constructor of Serializable Class 0 Answers
Initialising List array for use in a custom Editor 1 Answer
Rider 2018.3.1 Editor Package Missing Symbols 1 Answer
Confused about custom GameObjects,Custom GameObject confusion 0 Answers