private void RefreshState()
    {
        // Check if atlas name list changed
        string[] atlasNames = Packer.atlasNames;
        if (!atlasNames.SequenceEqual(m_AtlasNames))
        {
            if (atlasNames.Length == 0)
            {
                Reset();
                return;
            }
            else
            {
                OnAtlasNameListChanged();
            }
        }

        if (m_AtlasNames.Length == 0)
        {
            SetNewTexture(null);
            return;
        }

        // Validate selections
        if (m_SelectedAtlas >= m_AtlasNames.Length)
        {
            m_SelectedAtlas = 0;
        }
        string curAtlasName = m_AtlasNames[m_SelectedAtlas];

        Texture2D[] textures = Packer.GetTexturesForAtlas(curAtlasName);
        if (m_SelectedPage >= textures.Length)
        {
            m_SelectedPage = 0;
        }

        SetNewTexture(textures[m_SelectedPage]);

        // check if the atlas has alpha as an external texture (as in ETC1 atlases with alpha)
        Texture2D[] alphaTextures        = Packer.GetAlphaTexturesForAtlas(curAtlasName);
        Texture2D   selectedAlphaTexture = (m_SelectedPage < alphaTextures.Length) ? alphaTextures[m_SelectedPage] : null;

        SetAlphaTextureOverride(selectedAlphaTexture);
    }