public void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

        GUILayout.BeginHorizontal();
        GUILayout.Space(105);
        XSStyles.doLabel("1");
        GUILayout.Space(105);
        XSStyles.doLabel("2");
        GUILayout.Space(105);
        XSStyles.doLabel("3");
        GUILayout.Space(105);
        XSStyles.doLabel("4");
        GUILayout.EndHorizontal();

        XSStyles.SeparatorThin();
        GUILayout.BeginHorizontal();
        for (int i = 0; i < 4; i++)
        {
            EditorGUIUtility.labelWidth = 0.01f;
            textures[i] = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("", ""), textures[i], typeof(Texture2D), true);
        }
        GUILayout.EndHorizontal();

        float oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 40;
        GUIStyle headerStyle = EditorStyles.boldLabel;

        headerStyle.alignment    = TextAnchor.UpperLeft;
        headerStyle.fontStyle    = FontStyle.Bold;
        headerStyle.stretchWidth = true;

        XSStyles.SeparatorThin();
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Output Channel:", headerStyle);

        GUILayout.Label("R", headerStyle);
        GUILayout.Label("G", headerStyle);
        GUILayout.Label("B", headerStyle);
        GUILayout.Label("A", headerStyle);
        EditorGUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Src Texture:");
        GUILayout.Space(20);
        for (int i = 0; i < 4; i++)
        {
            pickTexture[i] = (ETextures)EditorGUILayout.EnumPopup("", pickTexture[i]);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Src Channel:");
        GUILayout.Space(17);
        for (int i = 0; i < 4; i++)
        {
            texChannels[i] = (EChannels)EditorGUILayout.EnumPopup("", texChannels[i]);
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Label("Invert Channel:");
        for (int i = 0; i < 4; i++)
        {
            invertChannel[i] = EditorGUILayout.Toggle("", invertChannel[i]);
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(20);
        EditorGUILayout.EndScrollView();

        //Button and Resolution
        GUILayout.BeginVertical();
        XSStyles.doLabel("Resolution");

        GUILayout.BeginHorizontal();
        GUILayout.Space(175);
        res = (resolutions)EditorGUILayout.EnumPopup("", res);
        GUILayout.Space(175);
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Merge Channels"))
        {
            //Set target textures to be ReadWriteable

            for (int i = 0; i < textures.Length; i++)
            {
                if (textures[i] == null)
                {
                    break;
                }

                string          texturePath = AssetDatabase.GetAssetPath(textures[i]);
                TextureImporter texture     = (TextureImporter)TextureImporter.GetAtPath(texturePath);
                if (texture != null)
                {
                    texture.isReadable = true;
                    texture.SaveAndReimport();
                }
            }

            switch (res)
            {
            case resolutions.Tiny_256x256:
                resolution = 256;
                break;

            case resolutions.Small_512x512:
                resolution = 512;
                break;

            case resolutions.Medium_1024x1024:
                resolution = 1024;
                break;

            case resolutions.Large_2048x2048:
                resolution = 2048;
                break;

            case resolutions.VeryLarge_4096x4096:
                resolution = 4096;
                break;

            case resolutions.Why_8192x8192:
                resolution = 8192;
                break;
            }

            XSStyles.findAssetPath(finalFilePath);
            finalFilePath = EditorUtility.SaveFilePanel("Save Merged Texture", finalFilePath + "/Textures/", "mergedTex.png", "png");

            Texture2D newTexture = new Texture2D(resolution, resolution, TextureFormat.RGBA32, false);

            //Get Colors textures and write them to the proper channel

            for (int y = 0; y < resolution; y++)
            {
                for (int x = 0; x < resolution; x++)
                {
                    float u = x / (float)resolution;
                    float v = y / (float)resolution;

                    // Grab out the texture values into an array for later lookup. Could probably just be done at the moment the texture color is needed.
                    for (int i = 0; i < textures.Length; i++)
                    {
                        if (textures[i] != null)
                        {
                            texColors[i] = textures[i].GetPixelBilinear(u, v);
                        }
                        else
                        {
                            texColors[i] = new Color(0, 0, 0, 1);
                        }
                    }

                    Color outputColor = new Color(0, 0, 0, 1);

                    // Iterate the output RGBA channels
                    for (int i = 0; i < 4; i++)
                    {
                        // Convert the enums to indices we can use. 'None' will turn into -1 which will be discarded as invalid.
                        int srcTexIdx     = ((int)pickTexture[i]) - 1;
                        int srcChannelIdx = ((int)texChannels[i]) - 1;

                        // Go through each channel in the output color and assign it
                        if (srcTexIdx >= 0 && srcChannelIdx >= 0)
                        {
                            outputColor[i] = texColors[srcTexIdx][srcChannelIdx];

                            //Allow you to invert specific channels.
                            if (invertChannel[i])
                            {
                                outputColor[i] = 1f - outputColor[i];
                            }
                        }
                    }

                    newTexture.SetPixel(x, y, outputColor);
                }
            }
            newTexture.Apply();
            ExportTexture(newTexture);
        }

        GUILayout.Space(10);
        GUILayout.EndVertical();

        EditorGUIUtility.labelWidth = oldLabelWidth;
    }
    public void OnGUI()
    {
        tab = GUILayout.Toolbar(tab, new string[] { "Documentation", "Updater", "Social" });
        XSStyles.SeparatorThin();
        switch (tab)
        {
        case 0:
            //show Docs from git
            XSStyles.doLabel("You can find Documentation here.");
            if (GUILayout.Button("Open Documentation"))
            {
                Application.OpenURL(docsURL);
            }

            break;

        case 1:
            EditorGUI.BeginChangeCheck();

            XSStyles.HelpBox("The currently installed version is: v" + XSStyles.ver + "\n\nTo check for updates, use the update button. If you choose to download an update, you will need to manually overwrite the old install by extracting the .zip into the project using the windows explorer. \n\nDo not drag the update directly into Unity - it won't ask to overwrite - it'll just create a duplicate and break.", MessageType.Info);
            XSStyles.SeparatorThin();
            if (GUILayout.Button("Check for Updates"))
            {
                req(updateUrl);
                EditorApplication.update += changelogEditorUpdate;
                showInfo = true;
            }

            if (showInfo)
            {
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
                Repaint();
                XSStyles.doLabelLeft("Newest version: ");
                XSStyles.doLabelSmall(curVer);
                XSStyles.SeparatorThin();

                XSStyles.doLabelLeft("Release Date: ");
                XSStyles.doLabelSmall(publishdate);
                XSStyles.SeparatorThin();

                XSStyles.doLabelLeft("Changelog: ");
                XSStyles.doLabelSmall(changelog);

                EditorGUILayout.EndScrollView();
                XSStyles.SeparatorThin();
                if (GUILayout.Button("Download"))
                {
                    Application.OpenURL(downloadLink);
                }
            }
            else
            {
                XSStyles.doLabel("Hit 'Check for Updates' to begin");
            }
            EditorGUI.EndChangeCheck();

            break;

        case 2:
            //show Patrons

            XSStyles.doLabel("Thank you to my patreon supporters, and the people who have helped me along the way, you guys are great!\n Note: You must be in the Discord server to show on this list.");
            XSStyles.SeparatorThin();
            XSStyles.doLabel("Current Patrons");
            XSStyles.SeparatorThin();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            if (!hasCalledPatronlist)
            {
                hasCalledPatronlist = true;
                req(patronsURL);
                EditorApplication.update += EditorUpdate;
            }
            for (int i = 0; i < patrons.Length; i++)
            {
                XSStyles.doLabel(" - " + patrons[i]);
            }
            EditorGUILayout.EndScrollView();

            XSStyles.SeparatorThin();
            //show social links
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            XSStyles.discordButton(70, 30);
            XSStyles.patreonButton(70, 30);
            XSStyles.githubButton(70, 30);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            break;
        }
    }