Z
Z
Zefirot2021-11-02 12:19:37
Unity
Zefirot, 2021-11-02 12:19:37

How to hide unnecessary fields in the editor?

I have a prefab, it has several subtypes, so to speak

[Range(1, 3)] public byte TypePrefab = 1;
[Range(0, 100)] public byte CountType1 = 10;
[Range(0, 100)] public byte CountType2 = 10;
[Range(0, 100)] public byte CountType3 = 10;

in the editor, of course, all 3 CountTypeN fields are displayed, I need to see only the corresponding field when switching the TypePrefab field, that is, if TypePrefab = 2, then only CountType2 was visible in the editor and the rest were hidden, but when this variable was changed, the stealth also changed other fields.
Is it possible at all? If so, how?
It would be very convenient to edit prefabs like that then...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
freeExec, 2021-11-02
@Zefirot

Uuuu, at the moment there are three systems for custom inspectors.
Old ancient OnGUI
Mediocre EditorGUILayout
And newfangled UIElements
The main thing is not to get confused and not create a vigorous hodgepodge of them.
https://docs.unity3d.com/Manual/editor-CustomEdito...

G
Griboks, 2021-11-02
@Griboks

The HideInInspector attribute.

A
antares4045, 2021-11-02
@antares4045

I have experience and the unit is a couple of hours, so I can’t say for specialized tools, but I can’t help but notice that all your counters are of the same type: you can roll them all into private, create one separate public counter, and in the method start to prescribe the assignment of the counter value depending on the selected type.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question