x


Making a collapsible menu in the inspector

I noticed some scripts have different options in collapsible menus in the inspector. For example there's a collapsible menu named "Resolution" and when you open it, it shows the properties.

How do they do it?

In c# preferred, but I guess I could possibly convert from js. Thanks

more ▼

asked Mar 01 '11 at 04:46 PM

Johan 4 gravatar image

Johan 4
412 81 84 97

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You can use the EditorGUILayout.Foldout control. It is basically just a special toggle control; assign it to a boolean, and if it is true then draw the controls "inside", if it is false then don't.

more ▼

answered Mar 01 '11 at 05:26 PM

Molix gravatar image

Molix
4.8k 15 27 66

That requires using unityeditor, I don't want that. I've seen this being done without unityeditor

Mar 01 '11 at 05:45 PM Johan 4

Your question does say "in the inspector". Anyway, there isn't really any magic to it; it is just a toggle that displays a little arrow icon pointing sideways or down. So if you want one at runtime, just use Toggle with a couple custom styles that contain arrows.

Mar 01 '11 at 06:06 PM Molix
(comments are locked)
10|3000 characters needed characters left

I'm sure this question is incredibly old but i stumbled upon it while looking for something else.

Based on the comments you need to make a serializable class to contain the data you want to be foldable. So in my FakeDataBehaviour as a monobehaviour, we have a FakeData class that contains something interesting. We define multiple ones inside my class. In the inspector, these will appear as foldable objects for setting the specific values.

for example:

public class FakeDataBehaviour : MonoBehaviour

{ [System.Serializable] public class Data { string name; float someValue; }

[SerializeField] Data myData1; [SerializeField] Data myData2; // do more stuff... }

more ▼

answered Aug 13 '12 at 04:45 PM

znoey gravatar image

znoey
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x463
x383

asked: Mar 01 '11 at 04:46 PM

Seen: 1294 times

Last Updated: Aug 13 '12 at 04:45 PM