- Home /
Setting GUI Skin's Custom Style Size via Javascript (or any code)
is there a way for me to change the size of Custom Style via scripting?
edited:
it's not that I want to create a new skin but to expand/add some more textures and names in the custom styles and I want this done by changing the size of the custom styles as indicated by the image link
img703.imageshack.us/i/questiono.png
for instance, like with how I use the codes below to rename custome styles and add/change textures
public var skin : GUISkin ;
skin.customStyles[x].name = fileNaming;
skin.customStyles[x].normal.background = screenTexture
I was wondering if there would be something like
skin.customStyles[0].size = 20 ;
Replace the above with:
skin.customStyles = new GUIStyle [20];
If you want 20 custom styles.
Answer by robertmathew · Apr 01, 2011 at 04:45 AM
GUI.skin.button.hover.textColor = Color.blue; GUI.skin.button.active.textColor = Color.blue; GUI.skin.button.normal.textColor = Color.red;
var style1 : GUIStyle;
function OnGUI()
{
GUI.skin.font = font1; // assign the font u want here style1 = GUI.skin.box; style1.alignment = TextAnchor.MiddleCentre; GUI.Box(Rect(100,500,50,30),"button");
}
Answer by Uzquiano · Apr 01, 2011 at 05:37 AM
Hi,
If you want to create a new skin, the solution is as simple as this, code shown below (note that EsGUIskin is the name of the skin asset, you must create it before hand):
var myGUISkin : GUISkin;
function Start () { myGUISkin = Resources.Load("EsGUIskin"); }
function OnGUI () {
GUI.skin = myGUISkin;
}
Cheers
I edited my post above to better clarify what I want to happen
Answer by jahroy · Apr 12, 2011 at 09:18 PM
The "size" you're talking about is the "length" of customStyles, which is an array of GUIStyles.
Are you trying to declare how many custom styles there will be in your skin?
If so, you probably want to do this:
skin.customStyles = new GUIStyle [20];
I haven't tried it...
When you click on a GUISkin in the EDITOR it brings up the Inspector for the Skin script, in it there is a Custom Styles drop down, firts parameter is the Size, this allocates the # of custom Styles you can have. Change it to 10 and 10 appear (usually copies the last one and duplicates it) I normally have 20 or so, and I do wish I knew how to adjust the parameters of them on the fly in script. If you define a style in the code, it shows up in the inspector for the script its in, but if your already have one done in a custome styles area, you don't want to duplicate it. It helps when you move the same skin to another project, as those custom styles go with it.
Of course. That is because customStyles is an array of GUIStyles. The value of size in the inspector corresponds to the "length" of the array.
I'm about to add a new answer...
Answer by jahroy · Jun 20, 2011 at 12:45 AM
When I want to manipulate my custom styles with code, I usually just increase the size of the custom styles array in the inspector first. Then I access the newest GUIStyles in my code like you do in your question.
If for some reason you can't manually increase the size first, you'd probably have to use a dynamic array to get the job done. You could convert customStyles to a dynamic array, add some styles to the array using Push(), then convert back to a builtin array.
Something like this:
var myCustomSkin : GUISkin;
var someStyle : GUIStyle;
var anotherStyle : GUIStyle;
function Start ()
{
var styleArray = new Array(myCustomSkin.customStyles);
styleArray.Push(someStyle);
styleArray.Push(anotherStyle);
myCustomSkin.customStyles = styleArray.ToBuiltin(GUIStyle);
}