Unique id numbers for GUI.Window

Hallo, community. Is there any simple way to generate for sure unique id numbers for GUI windows? MonoBehavior Instantiate ID is not suitable here, because I have to call several windows for one object.

I’m not sure I understand your question right.

How about just using a list of ints? If you want to generate a new ID, check if the list contains that one, and if yes, generate another one.

The easiest way is to use a “windowID manager” like this:

// C#
public static class WindowIdManager
{
    private static int m_NextId = 2222; // I just start a bit higher to keep space for hardcoded window ids.
    public static int GetWindowId()
    {
        return m_NextId++;
    }
}

In all your scripts where you need a window ID you just declare a member variable for each window you need like this:

// C#
public class SomeScript : MonoBehaviour
{
    private int m_WindowId1 = WindowIdManager.GetWindowId();
    private int m_WindowId2 = WindowIdManager.GetWindowId();
}

GUIUtility.GetControlID(FocusType.Passive)

Rect WindowRect = GUI.Window(GUIUtility.GetControlID(FocusType.Passive), WindowRect, Window, " ");