Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tarelome · Sep 08, 2017 at 12:43 AM · scripting problemguibugbooleanguiskin

GUI.skin Does not persist on next loop through is this a bug?

So I'm trying to make sure i don't change the GUI.skin on each loop through in case my GUISkin gets to large or i simply have to many Skins in my list bogging the process down in my Editor script.

but it seams like for each OnGUI loop the script goes through it simply resets the GUI.skin to the default skin is this a bug or did i do something wrong here??

Code:

 using UnityEditor;
 using UnityEngine;
 using System.Collections.Generic;
 
 namespace KuntekiWeb.ItemSystem.Editor
 {
     public class ISDataBaseEditor : EditorWindow
     {
         //temp variables
         private int Counter = 0; //here for Debug purposes, lets me increment per OnGui() run
 
         public List<GUISkin> MyGUISkin = new List<GUISkin>(); //List of available GUISkin's in Assets/KuntekiWeb/Skins 
         
         private int SkinIndex = 0; //Defaulted to 0 for the first skin in the List later on havent Implemented the switch in GUI yet
         
         public const float X = 500; //the X size of the Menu Window
         public const float Y = 400; // the Y..
         
 
         [MenuItem("KuntekiWeb/Settings %#o")] //Menu for the Test
         public static void Init()
         {
             ISDataBaseEditor MainWindow = EditorWindow.GetWindow<ISDataBaseEditor>();
             MainWindow.minSize = new Vector2(X, Y);
             MainWindow.maxSize = MainWindow.minSize;
             MainWindow.titleContent.text = "testing Main Window";
             MainWindow.Show();
         }
 
         public void GUILoadSkin() //my Method for setting GUI.skin
         {
             if (MyGUISkin.Count == 0) //if the MyGUISkin List is emty do stuff
             {
                 string[] paths = new string[1];             //FindAssets needs an Array of Paths to look in
                 paths[0] = "Assets/KuntekiWeb/Skins";       //populate said Array
                 foreach (var guid in AssetDatabase.FindAssets("t:GUISkin", paths)) //Loop through all files at paths for GUISkin files and output GUID's
                 {
                     Debug.Log("trying to load Skin: " + AssetDatabase.GUIDToAssetPath(guid));   //show in console the files found Using GUIToAssetPath to do so
                     if(AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid),typeof(GUISkin)) as GUISkin)   //makeing sure that it's an actual GUISkin
                     {
                         MyGUISkin.Add(AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(GUISkin)) as GUISkin); //Add said GUISkin to the list of Skin's
                         Debug.Log("should have added Skin :§");     //Showing in console that it actually added
                     }  
                 }
 
                 if (MyGUISkin.Count >= 1) //makeing sure that we now have a list of Useable skins in the list
                 {
                     foreach (GUISkin Skin in MyGUISkin) //the loop through
                     {
                         Debug.Log("listing: " + Skin.name); //just posting the names here 
                     }
                 }
                 else if (MyGUISkin.Count == 0) //if the list is somehow still emty tell me
                 {
                     //output the Error messege
                     Debug.LogError("Could not load a skin!!!" + System.Environment.NewLine + "Did you remove the Skins from the KuntekiWeb/Skins folder??");
                 }
                 else Debug.LogError(MyGUISkin.Count);  //if we get here shit kinda hit the fan
             }
 
             Debug.Log("before set: "+ GUI.skin.name); //some output to make sure that we are actually changeing the GUI.skin.name
             if (MyGUISkin[SkinIndex] != null)   //makeing sure that the first entry in the list is not emty
             {
                 Debug.Log("loading: " + MyGUISkin[SkinIndex].name); //info message telling what GUISkin we are loading
                 GUI.skin = MyGUISkin[SkinIndex]; //the actual loading..
             }
             else Debug.Log(MyGUISkin[SkinIndex].name); //output to show what might be the reason we can't get the first skin, using the name for simplicity 
             Debug.Log("After set: " + GUI.skin.name); //output to show what GUI.skin we have now, again useing name for simplicity
         }
 
         public bool IsCurrentSkinDefault //my Bolean for the if statement to make sure we don't keep reaplying the Selected skin
         {
             get  //starting the getter ^^
             {
                 //Debug.Log("ICSD 1: " + GUI.skin.name); first thought it might be in this code but nope so added stepping output to make sure it
                 //didn't F up everything.
                 GUISkin current = GUI.skin;             //putting current skin into a Temp variable so i can reasign it later
                 //Debug.Log("ICSD 2: " + GUI.skin.name); again stepping output
                 GUI.skin = null;                        //Reset GUI.skin to default
                 //Debug.Log("ICSD 3: " + GUI.skin.name); and another
                 if (current == GUI.skin)                //returns true if the current Skin is the same as Default skin
                 {
                     //Debug.Log("ICSD 4: " + GUI.skin.name); yup even more of them
                     GUI.skin = current;                 //resetting the skin back to the current (redundant i know ^^)
                     //Debug.Log("ICSD 5: " + GUI.skin.name); i REALY wanted to make sure 
                     return true;                        //actually returning true :P
                 } 
                 else                                    //so if it isn't true then it must be false right
                 {
                     //Debug.Log("ICSD 6: " + GUI.skin.name); yup here too
                     GUI.skin = current;                 //this one is actually needed since we reset to the original earlier
                     //Debug.Log("ICSD 7: " + GUI.skin.name); last one i swear ^^
                     return false;                       //and Returning false
                 }
             }
         }
 
         private void OnGUI()
         {
             Debug.Log(IsCurrentSkinDefault.ToString() + " Counter: " + Counter); // "true or false" is the current skin Default, + the Counter for number of times the GUI has Looped through
             
             if(IsCurrentSkinDefault)    //using that true or false statement
             {
                 GUILoadSkin();          //call all the Checks to see if the List is emty and then change the GUI.skin
             }
             else Debug.Log("We have a non Default Skin Equipped Huzzar!!");             //we should hopefully get here after GUILoadSkin() has run once but sadly never do
             Debug.Log("counter now: " + Counter + " : After check: " + GUI.skin.name);  //makeing sure after all that the the check when't to it's completion, reshowing the counter and the hopefully newly applied or left alone GUI.skin.name
             Counter++;                                                                  //incrementing the Counter after the check
         }
     }
 }

 
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

0 Replies

· Add your reply
  • Sort: 

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

158 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add a Gui skin to script 0 Answers

Disable script on 2. object by boolean from 1. object. 0 Answers

GUI Windows not being removed properly in a network 1 Answer

Level Select screen Messed Up - Please help! 0 Answers

C# Boolean Doesn't Change Value 1 Answer


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