public static Uni2DTextureAtlas AtlasPopup(Uni2DTextureAtlas a_rTextureAtlas, IEnumerable <string> a_rTextureGUIDs, params GUILayoutOption[] a_rGUILayoutOptions)
    {
        // Get button control ID
        int iControlID = GUIUtility.GetControlID(FocusType.Passive);

        // Get selected value for our control
        // If no PopupCallbackInfo instance exists, the returned value is a_rTextureAtlas
        a_rTextureAtlas = PopupCallbackInfo <Uni2DTextureAtlas> .GetSelectedValueForControl(iControlID, a_rTextureAtlas);

        // Create a new generic menu
        // Each item menu will use AtlasPopupCallback as callback
        // AtlasPopupCallback will perform the logic and save the selected atlas to
        // the PopupCallbackInfo instance.
        string oPopupSelected = EditorGUI.showMixedValue ? "-" : (a_rTextureAtlas != null ? a_rTextureAtlas.name : "(None)");

        if (GUILayout.Button(oPopupSelected, EditorStyles.popup, a_rGUILayoutOptions))
        {
            string rAtlasGUID = Uni2DEditorUtils.GetUnityAssetGUID(a_rTextureAtlas);

            // Create a new popup callback info (control ID) and save it as current instance
            PopupCallbackInfo <Uni2DTextureAtlas> .instance = new PopupCallbackInfo <Uni2DTextureAtlas>(iControlID, a_rTextureAtlas);

            // Create our generic menu
            GenericMenu oPopupMenu = new GenericMenu( );

            if (a_rTextureAtlas != null)
            {
                oPopupMenu.AddItem(new GUIContent(a_rTextureAtlas.name), true, AtlasPopupCallback, rAtlasGUID);
                oPopupMenu.AddSeparator("");
            }

            // "None" special item menu
            oPopupMenu.AddItem(new GUIContent("(None)", "No atlasing"), a_rTextureAtlas == null, AtlasPopupCallback, "");

            oPopupMenu.AddSeparator("");

            // "Create" special item menu
            oPopupMenu.AddItem(new GUIContent("Create a new atlas...", "Creates a new Uni2D atlas and add the texture(s) right away"), false, AtlasPopupCallback, "NEW");

            Uni2DEditorAssetTable rAssetTable = Uni2DEditorAssetTable.Instance;

            // List atlases containing the texture(s)
            Dictionary <string, string> oAtlasesReadyToUse = rAssetTable.GetAtlasNamesUsingTheseTextures(a_rTextureGUIDs);

            if (!string.IsNullOrEmpty(rAtlasGUID))
            {
                oAtlasesReadyToUse.Remove(rAtlasGUID);
            }

            if (oAtlasesReadyToUse.Count > 0)
            {
                oPopupMenu.AddSeparator("");

                // Add an item menu for each ready to use atlas
                foreach (KeyValuePair <string, string> rAtlasNameGUIDPair in oAtlasesReadyToUse)
                {
                    oPopupMenu.AddItem(new GUIContent(rAtlasNameGUIDPair.Value), rAtlasNameGUIDPair.Key == rAtlasGUID, AtlasPopupCallback, rAtlasNameGUIDPair.Key);
                }
            }

            // List all available atlases
            Dictionary <string, string> oAvailableAtlases = rAssetTable.GetAllAtlasNames( );
            if (oAvailableAtlases.Count > 0)
            {
                oPopupMenu.AddSeparator("");

                // Add an item menu for each available atlas, in a submenu
                foreach (KeyValuePair <string, string> rAtlasNameGUIDPair in oAvailableAtlases)
                {
                    oPopupMenu.AddItem(new GUIContent("All atlases/" + rAtlasNameGUIDPair.Value), rAtlasNameGUIDPair.Key == rAtlasGUID, AtlasPopupCallback, rAtlasNameGUIDPair.Key);
                }
            }

            // Finally show up the menu
            oPopupMenu.ShowAsContext( );
        }

        return(a_rTextureAtlas);
    }