private void OnSaveTextureClicked()
        {
            if (!TextureRef)
            {
                ExplorerCore.LogWarning("Ref Texture is null, maybe it was destroyed?");
                return;
            }

            if (string.IsNullOrEmpty(textureSavePathInput.Text))
            {
                ExplorerCore.LogWarning("Save path cannot be empty!");
                return;
            }

            var path = textureSavePathInput.Text;

            if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
            {
                ExplorerCore.LogWarning("Desired save path must end with '.png'!");
                return;
            }

            path = IOUtility.EnsureValidDirectory(path);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var tex = TextureRef;

            if (!TextureUtilProvider.IsReadable(tex))
            {
                tex = TextureUtilProvider.ForceReadTexture(tex);
            }

            byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex);

            File.WriteAllBytes(path, data);

            if (tex != TextureRef)
            {
                // cleanup temp texture if we had to force-read it.
                GameObject.Destroy(tex);
            }
        }
        internal void ConstructTextureViewerArea(GameObject parent)
        {
            constructedTextureViewer = true;

            var tex = Target.Cast(typeof(Texture2D)) as Texture2D;

            if (!tex)
            {
                ExplorerCore.LogWarning("Could not cast the target instance to Texture2D! Maybe its null or destroyed?");
                return;
            }

            // Save helper

            var saveRowObj = UIFactory.CreateHorizontalGroup(parent, "SaveRow", true, true, true, true, 2, new Vector4(2, 2, 2, 2),
                                                             new Color(0.1f, 0.1f, 0.1f));

            var saveBtn = UIFactory.CreateButton(saveRowObj, "SaveButton", "Save .PNG", null, new Color(0.2f, 0.2f, 0.2f));

            UIFactory.SetLayoutElement(saveBtn.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);

            var inputObj = UIFactory.CreateInputField(saveRowObj, "SaveInput", "...");

            UIFactory.SetLayoutElement(inputObj, minHeight: 25, minWidth: 100, flexibleWidth: 9999);
            var inputField = inputObj.GetComponent <InputField>();

            var name = tex.name;

            if (string.IsNullOrEmpty(name))
            {
                name = "untitled";
            }

            inputField.text = Path.Combine(ConfigManager.Default_Output_Path.Value, $"{name}.png");

            saveBtn.onClick.AddListener(() =>
            {
                if (tex && !string.IsNullOrEmpty(inputField.text))
                {
                    var path = inputField.text;
                    if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        ExplorerCore.LogWarning("Desired save path must end with '.png'!");
                        return;
                    }

                    var dir = Path.GetDirectoryName(path);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    if (!TextureUtilProvider.IsReadable(tex))
                    {
                        tex = TextureUtilProvider.ForceReadTexture(tex);
                    }

                    byte[] data = TextureUtilProvider.Instance.EncodeToPNG(tex);

                    File.WriteAllBytes(path, data);
                }
            });

            // Actual texture viewer

            var imageObj = UIFactory.CreateUIObject("TextureViewerImage", parent);
            var image    = imageObj.AddComponent <Image>();
            var sprite   = TextureUtilProvider.Instance.CreateSprite(tex);

            image.sprite = sprite;

            var fitter = imageObj.AddComponent <ContentSizeFitter>();

            fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            var imageLayout = imageObj.AddComponent <LayoutElement>();

            imageLayout.preferredHeight = sprite.rect.height;
            imageLayout.preferredWidth  = sprite.rect.width;
        }