Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Window ID's Tip

Discussion in 'Immediate Mode GUI (IMGUI)' started by shaun, Jan 4, 2008.

  1. shaun


    Mar 23, 2007
    It's probably obvious to anyone using more than 3 or 4 GUI.Window's that managing the ID's is annoying. So rather than doing GUI.Window(11542,..) because you've forgotten which numbers have already been used, try this;

    Create a static arraylist:
    Code (csharp):
    1. public static ArrayList GUIWindowList = new ArrayList();
    In each window script, create a private int for the WindowID:
    Code (csharp):
    1. private int WindowID;
    Allocate a unique ID for the window (pop this in Start() or Awake())
    Code (csharp):
    1. WindowID = YourGenericUIClass.GUIWindowList.Add("MyWindowName");
    And when you call the Window, just use the WindowID int
    Code (csharp):
    1. GUI.Window(WindowID, WindowPosition, DoWindowFunction, YourGenericUIClass.GUIWindowList[WindowId].ToString());
    The neat thing is that you can find and focus a window from anywhere else in your app by looking it up in the GUIWindowList (which is good if you want to write an automated help script etc).

    Hope its useful to someone.
  2. alexander


    Mar 28, 2008
    Hi shaun

    just read this and I would propose to copy'n'paste this to the Script Reference.
    Maybe a little example for anymore clearness.