- Home /
Singleton & Inspector
Hi,
I have a popup-manager singleton, which creates itself first time you want to show a popup. It has some settings, which I would like to set in the inspector, but they don't show up (except for one, but that one is reset to it's default when the singleton object is created).
I have to following code:
static UnityGrowl m_Instance;
static readonly object padlock = new object(); //For thread safety
//Creates the Popup Object only once, the first time it is needed
public static UnityGrowl Instance
{
get
{
lock (padlock)
{
if(!m_Instance)
m_Instance = (new GameObject("Unity Growl")).AddComponent<UnityGrowl>();
return m_Instance;
}
}
}
//GUISkin shows up in the inspector, but is Null in the object in the scene
//The other stuff doesn't even show up in the inspector
public GUISkin m_GUISkin;
GUIStyle m_Style;
public int m_Width = 240;
public int m_XOffset = 5;
public int m_YOffset = 5;
public enum position{TopLeft, TopRight, BottomLeft, BottomRight}
public position m_Position = position.TopRight;
When I say "doesn't show up in the inspector" I mean it doesn't for the script (when not attached to an object), when I make my first popup and look at the 'Unity Growl' object it does show the settings.
Is it possible to make it so that the settings do show up for the script itself, and they don't get reset ?
Thanks !
-P
Answer by aldonaletto · Sep 04, 2011 at 11:49 AM
The Inspector only shows and allows modification of variables for scripts assigned to objects - they are independent instances of the original script. If not attached to any object, the only way to modify the variables is editing the script, what isn't so bad at all (values modified in the Inspector survive even when you make extensive modifications in your script, and continue plaguing your life until you reset them with the Inspector "gear" button!).
Ok thanks :P Didn't think it was possible but was worth the effort to ask :D