Hello~ I would like to resize toggle checkbox. I set the width = 200 and height = 200. but the check box size is not changed. Code is following. bool Value = false; void OnGUI() { bool val; Rect Position = new Rect(100, 350, 200, 200);// width = 200, height = 200 string str = "Toggle"; val = UnityEngine.GUI.Toggle(Position, Value, str); if (val != Value) { Value = val; } } how to scale up the checkbox itself. thanks.
Unless I am mistaken, the rect argument is for the optional text next to it. I doubt you can resize checkboxes...
AkilaeTribe is more or less right; the Rect you pass to GUI.Toggle defines the area that the checkbox and label take up together. The checkbox part itself wont scale with the toggle control. You may be able to make that bigger by passing GUI.Toggle a GUIStyle with a larger checkbox image (I haven't checked the GUIStyle/GUISkin docs though...)
http://unity3d.com/support/documentation/ScriptReference/GUIStyle.html Interesting theory, but I don't see any variable related to toggles. Unless they fall in the onNormal and onActive category ?
It'd be the 'background' property of the onNormal/onHover/onActive states, yes. There wouldn't be anything specifically related to toggles in GUIStyle/GUIStyleState, since those classes are used across all GUI controls; there is a GUIStyle for toggles in each GUISkin though.
! If there is already a section for toggle in GUISkin, why are we bothering ourselves with GUIStyle ?
Perhaps I wasn't very clear. the GUIStyle API doesn't mention toggles, because it's a general interface used by all control types to determine style information. Rather, a GUISkin contains an *instance* of GUIStyle that is specific to toggles. Thus: * GUI.skin is the current default GUI skin * GUI.skin.toggle is the GUIStyle used by toggles in that skin If you want to change the appearance of a toggle control, you can: * pass your own GUIStyle instance into GUI.Toggle (to alter the appearance of just that toggle) * modify GUI.skin.toggle (to alter the appearance of all toggles rendered with that skin) * set GUI.skin to a different skin (to alter the apperance of all controls, of all types, that you don't override the styles for) Hopefully that makes it clearer
In other words, GUIStyles inherit of some values of his parent GUISkin, so even if we give an empty GUIStyle to a GUI.Toggle, as long as the parent GUISkin has the correct images, the GUI.Toggle will get them ?
No, GUI styles don't inherit anything from anywhere, and a GUI skin doesn't contain any style information by itself; it's just a collection of GUIStyle objects. If you call GUI.Toggle (or any GUI control) and pass it a GUI style, it will draw using the setting in that style, and only that style. If you don't pass a style, it'll draw using the settings from the appropriate style in the current skin. Code (csharp): GUI.Toggle(rect, val, text); // draw using style 'GUI.skin.toggle' GUI.Toggle(rect, val, text, style); // draw using style 'style' It's one or the other.
I reread the manual on Gui : http://unity3d.com/support/documentation/Components/gui-Customization.html And I understand a little more your explanation. Thanks you :wink:
This thread is ancient, but I came across it while searching for a way to do this and thought I'd share the result - inspired by smithlim's "solved" post, I found that by making the following changes to the "toggle" style I can scale the background image. - set all four "border" values to zero - set all four "overflow" values to zero - set "image position" to "image only", and render the label as a separate GUI element instead - set "padding.right" and "padding.bottom" to zero - set "padding.left" and "padding.top" to the minimum width and height you want the background scaled to The first few changes make the background image scale over the whole control's size; getting rid of the label removes that complication. Then the padding settings define a minimum control size, and for most purposes this is enough. If you turn off "expand width" and "expand height" then the toggle button will always appear at the size you've specified in the padding settings. If you want GUILayout toggles to be able to expand to fill space, for some reason, then turn on "expand width" and/or "expand height". The background image will be scaled across the whole control thanks to the "border" settings. You can probably get the same effect by using the GUILayoutOption variants on the actual GUILayout.Toggle call.