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 Lairinus · Jul 12, 2013 at 02:51 PM · c#guitexturetexture2dguistyle

GUI Style Issue-- Texture not changing

Hello,

My code is meant to iterate through a list and set all of the components to "blank."

Blank is a blank inventory space and has its' own GUIStyle associated with it.

I know that my code DOES set everything to blank, but I do not see any changes.

My code is as follows:

      IEnumerator SetItemList_Ienum(GUIComponent arrayParent)
     {
         yield return new WaitForEndOfFrame();
 
         for (int i = 0; i < arrayParent.numberOfChildElements; i++)
         {
             if (_currentItems.Count > 0)
             {
               arrayParent.childrenComponents[i] =  _currentItems[i].GetComponent<GUIComponent>();
             }
             else
             {
                 arrayParent.childrenComponents[i] = Item_Special.instance.blankItemGUIComponent;
                 print(arrayParent.childrenComponents[i].style.normal.background);
             }
         }
     }


The current count of the _currentItems list is 0, so it's all happening in the else fragment.

Also, the print shows that the texture has indeed changed, but there is no visible difference.

The only thing I can think of is that I may have botched up calling apply. I was using this code:

 void ApplyTextures()
 {
     if (_style.normal.background)               // Apply the background Texture2D
     {
         _style.normal.background.Apply();       // Lag.
     }
     if (_style.hover.background)                // Apply the hover Texture2D
     {
         _style.hover.background.Apply();        // Lag.
     }
 }


Anyone have any suggestions on how to fix this?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jamora · Jul 12, 2013 at 06:18 PM

Calling Apply() on a texture will apply all previous SetPixel and SetPixels changes. What you need to do in order to change the background picture is just _style.normal.background = newBackgroundTexture. You can use them on any GUI or GUILayout components, by passing the name of the style as a string parameter. Refer to the API for more info. The changes take effect instantly.

Instead of changing a GUIStyle from code, I would instead create a new GUIStyle, and apply that when appropriate. In case you have a lot of GUIStyles, I hope you have read the documentation on GUISkins.

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 Lairinus · Jul 12, 2013 at 06:35 PM 0
Share

Thanks, it works!

I really thought by setting one script (named GUIComponent) = to another script of the same type, it would apply all of the values.. Every other value is applied but for some reason you need to implicitly set the Style variable.

avatar image
0

Answer by tw1st3d · Jul 12, 2013 at 05:19 PM

I did something like this:

 using System.Collections;
 using UnityEngine;
 
 class MyInventory
 {
     
     int maxInventorySpace = 0; // Set
     public GUISkin InvSkin;
     
     ItemType[] inv = new ItemType[maxInventorySpace];
 
     void OnGUI()
     {
         GUI.skin = InvSkin;
         
         int x = y = 0;
         int maxX; //Set
         int boxHeight; //Set
         int width, height; //Set
         
         foreach(ItemType i in inv)
         {
             
             if(x >= maxX)
             {
                 x = 0;
                 y = y + boxHeight;
             }
             GUI.Box(new Rect(x, y, width, height), i, "InvBox");
         }
     
     }
     
 }

Pretty much just re-create your box over and over with a specific texture. Then you can add in conditionals and set the box style to another name.

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 Lairinus · Jul 12, 2013 at 05:50 PM 0
Share

Thanks for posting the code, but this isn't really an answer to my question.

How do you make it so that the changes applied to a style variable take effect? Do you have to use some sort of texture.Apply() derivative?

avatar image tw1st3d · Jul 17, 2013 at 03:17 AM 0
Share

Sorry, I misread your question.

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to gradient-wise fill a bitmap programmatically 1 Answer

Blend 2 Textures Unity C# 0 Answers

Equivelant of GUI.DrawSprite() ? 0 Answers

Update Texture type to GUI during runtime 1 Answer

Gui.DrawTexture Working in Scene Mode, but not build or full game scene 2 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