Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mugenl00p · Apr 01, 2011 at 03:10 AM · sizecustomstyle

Setting GUI Skin's Custom Style Size via Javascript (or any code)

alt text

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 ;

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jahroy · Jun 20, 2011 at 12:55 AM 0
Share

Replace the above with:

 skin.customStyles = new GUIStyle [20];

If you want 20 custom styles.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

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");

    }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertmathew · Apr 01, 2011 at 05:22 AM 0
Share

is the answer you r looking for

avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mugenl00p · Apr 01, 2011 at 06:30 AM 0
Share

I edited my post above to better clarify what I want to happen

avatar image
0

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...

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wkmccoy · Jun 20, 2011 at 12:18 AM 0
Share

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.

avatar image jahroy · Jun 20, 2011 at 12:35 AM 0
Share

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...

avatar image
0

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);
 }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Font size and style overrides are only supported for dynamic fonts 2 Answers

Windows Player Behavior 1 Answer

Change the size of a custom font in a Canvas text 1 Answer

Is there a way to get the size of text? 1 Answer

How to keep same player settings from the scene in the .exe file 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges