private void SpritePreview(SVGUIAtlas uiAtlas, Canvas canvas, SVGSpriteAssetFile spriteAsset)
    {
        SVGUIWidgetType widgetType;
        Sprite          sprite     = spriteAsset.SpriteData.Sprite;
        Texture2D       texture    = sprite.texture;
        Rect            spriteRect = sprite.textureRect;
        Rect            uv         = new Rect(spriteRect.x / texture.width, spriteRect.y / texture.height, spriteRect.width / texture.width, spriteRect.height / texture.height);

        GUILayoutOption[] spriteTextureOptions = new GUILayoutOption[2] {
            GUILayout.Width(uiAtlas.SpritesPreviewSize), GUILayout.Height(uiAtlas.SpritesPreviewSize)
        };

        EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(uiAtlas.SpritesPreviewSize + 5));
        {
            EditorGUILayout.LabelField(sprite.name, GUILayout.MinWidth(10));
            // reserve space for drawing sprite
            EditorGUILayout.LabelField("", spriteTextureOptions);
            Rect  guiRect       = GUILayoutUtility.GetLastRect();
            float maxSpriteDim  = Math.Max(spriteRect.width, spriteRect.height);
            float previewWidth  = (spriteRect.width / maxSpriteDim) * uiAtlas.SpritesPreviewSize;
            float previewHeight = (spriteRect.height / maxSpriteDim) * uiAtlas.SpritesPreviewSize;
            float previewX      = (uiAtlas.SpritesPreviewSize - previewWidth) / 2;
            float previewY      = 0;
            Rect  previewRect   = new Rect(guiRect.xMin + previewX, guiRect.yMin + previewY, previewWidth, previewHeight);
            GUI.DrawTextureWithTexCoords(previewRect, texture, uv, true);
            EditorGUILayout.Space();
            // sprite dimensions
            EditorGUILayout.LabelField("[" + spriteRect.width + " x " + spriteRect.height + "]", GUILayout.MaxWidth(120));

            if (GUILayout.Button("Edit", EditorStyles.miniButton))
            {
                // show pivot editor
                SVGPivotEditor.Show(spriteAsset, this.OnSpriteEdited);
            }

            widgetType = (SVGUIWidgetType)EditorGUILayout.EnumPopup("", spriteAsset.InstantiatedWidgetType, new GUILayoutOption[] { GUILayout.Width(80) });

            // instantiate
            if (GUILayout.Button("Instantiate", EditorStyles.miniButton))
            {
                GameObject gameObj = uiAtlas.InstantiateWidget(canvas, spriteAsset.SpriteRef, widgetType);
                // set the created instance as selected
                if (gameObj != null)
                {
                    Selection.objects = new UnityEngine.Object[1] {
                        gameObj as UnityEngine.Object
                    };
                }
            }

            EditorGUILayout.Space();
        }
        EditorGUILayout.EndHorizontal();

        if (widgetType != spriteAsset.InstantiatedWidgetType)
        {
            spriteAsset.InstantiatedWidgetType = widgetType;
        }
    }
    private void SpritePreview(SVGAtlas atlas, SVGSpriteAssetFile spriteAsset)
    {
        Sprite    sprite     = spriteAsset.SpriteData.Sprite;
        Texture2D texture    = sprite.texture;
        Rect      spriteRect = sprite.textureRect;
        Rect      uv         = new Rect(spriteRect.x / texture.width, spriteRect.y / texture.height, spriteRect.width / texture.width, spriteRect.height / texture.height);

        GUILayoutOption[] spriteTextureOptions = new GUILayoutOption[2] {
            GUILayout.Width(atlas.SpritesPreviewSize), GUILayout.Height(atlas.SpritesPreviewSize)
        };

        EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(atlas.SpritesPreviewSize + 5));
        {
            EditorGUILayout.LabelField(sprite.name, GUILayout.MinWidth(10));
            // reserve space for drawing sprite
            EditorGUILayout.LabelField("", spriteTextureOptions);
            Rect  guiRect       = GUILayoutUtility.GetLastRect();
            float maxSpriteDim  = Math.Max(spriteRect.width, spriteRect.height);
            float previewWidth  = (spriteRect.width / maxSpriteDim) * atlas.SpritesPreviewSize;
            float previewHeight = (spriteRect.height / maxSpriteDim) * atlas.SpritesPreviewSize;
            float previewX      = (atlas.SpritesPreviewSize - previewWidth) / 2;
            //float previewY = (SVGAtlasEditor.SPRITE_PREVIEW_DIMENSION - previewHeight) / 2;
            //float previewY = (previewWidth > previewHeight) ? 0 : ((SVGAtlasEditor.SPRITE_PREVIEW_DIMENSION - previewHeight) / 2);
            float previewY    = 0;
            Rect  previewRect = new Rect(guiRect.xMin + previewX, guiRect.yMin + previewY, previewWidth, previewHeight);
            GUI.DrawTextureWithTexCoords(previewRect, texture, uv, true);
            EditorGUILayout.Space();
            // sprite dimensions
            EditorGUILayout.LabelField("[" + spriteRect.width + " x " + spriteRect.height + "]", GUILayout.MaxWidth(100));
            EditorGUILayout.Space();
            // current pivot
            EditorGUILayout.LabelField("Pivot [" + string.Format("{0:0.00}", spriteAsset.SpriteData.Pivot.x) + " , " + string.Format("{0:0.00}", spriteAsset.SpriteData.Pivot.y) + "]", GUILayout.Width(120));
            EditorGUILayout.Space();
            // edit pivot
            if (GUILayout.Button("Edit", EditorStyles.miniButton))
            {
                // show pivot editor
                SVGPivotEditor.Show(spriteAsset, this.OnPivotEdited);
            }
            // instantiate
            if (GUILayout.Button("Instantiate", EditorStyles.miniButton, GUILayout.Width(80)))
            {
                GameObject gameObj = atlas.InstantiateSprite(spriteAsset.SpriteRef);
                // set the created instance as selected
                if (gameObj != null)
                {
                    Selection.objects = new UnityEngine.Object[1] {
                        gameObj as UnityEngine.Object
                    };
                }
            }
            EditorGUILayout.Space();
        }
        EditorGUILayout.EndHorizontal();
    }
    private void DrawInspector()
    {
        bool resizeOnStart;

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.PrefixLabel("Resize on Start()");
            resizeOnStart = EditorGUILayout.Toggle(this.m_EditedLoader.ResizeOnStart);
        }
        EditorGUILayout.EndHorizontal();

        SVGUIAtlas uiAtlas = this.m_EditedLoader.UIAtlas;

        if ((uiAtlas != null) && (this.m_EditedLoader.SpriteReference != null))
        {
            SVGSpriteAssetFile spriteAsset = uiAtlas.GetGeneratedSprite(this.m_EditedLoader.SpriteReference);
            string             buttonText  = (spriteAsset != null) ? spriteAsset.SpriteData.Sprite.name : "<select>";

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Sprite");
                if (GUILayout.Button(buttonText, "DropDown"))
                {
                    SVGSpriteSelector.Show(uiAtlas, "", this.OnSpriteSelect);
                }
                if (GUILayout.Button("Edit", GUILayout.Width(80)))
                {
                    // show pivot editor
                    SVGPivotEditor.Show(spriteAsset, this.OnSpriteEdited);
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        if (this.m_EditedLoader.ResizeOnStart != resizeOnStart)
        {
            this.m_EditedLoader.ResizeOnStart = resizeOnStart;
            SVGUtils.MarkObjectDirty(this.m_EditedLoader);
        }
    }