- Home /
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