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
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;
}
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...
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...
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);
}
Replace the above with: skin.customStyles = new GUIStyle [20]; If you want 20 custom styles.
– jahroy