// border editing callback
    private void OnSpriteEdited(PivotEditingResult result, SVGSpriteAssetFile spriteAsset, Vector2 editedPivot, Vector4 editedBorder)
    {
        SVGCanvasBehaviour svgCanvas = target as SVGCanvasBehaviour;

        if ((svgCanvas != null) && (result == PivotEditingResult.Ok))
        {
            SVGUIAtlas uiAtlas = svgCanvas.UIAtlas;
            if (uiAtlas != null)
            {
                // assign the new border
                uiAtlas.UpdateBorder(spriteAsset, editedBorder);
                SVGUtils.MarkObjectDirty(uiAtlas);
                SVGUtils.MarkSceneDirty();

                // get the list of instantiated SVG sprites that reference the edited one
                List <GameObject> spritesInstances = new List <GameObject>();
                uiAtlas.GetSpritesInstances(spritesInstances, spriteAsset.SpriteRef);
                foreach (GameObject gameObj in spritesInstances)
                {
                    Image uiImage = (Image)gameObj.GetComponent <Image>();
                    if (uiImage != null)
                    {
                        // the Image component won't recognize the change of sprite border, so in order to refresh
                        // instantiated objects we have to unset-set the sprite property
                        uiImage.sprite = null;
                        uiImage.sprite = spriteAsset.SpriteData.Sprite;
                    }
                }
            }
        }
    }
    private void DrawInspector(GameCardBehaviour card)
    {
        bool          needSpriteUpdate = false;
        bool          active           = EditorGUILayout.Toggle(new GUIContent("Active", ""), card.Active);
        bool          backSide         = EditorGUILayout.Toggle(new GUIContent("Back side", ""), card.BackSide);
        GameCardType  animalType       = (GameCardType)EditorGUILayout.EnumPopup("Animal type", card.AnimalType);
        GameBehaviour game             = EditorGUILayout.ObjectField("Game manager", card.Game, typeof(GameBehaviour), true) as GameBehaviour;

        // update active flag, if needed
        if (active != card.Active)
        {
            card.Active = active;
            SVGUtils.MarkSceneDirty();
            if (card.Game != null)
            {
                if (card.Active)
                {
                    card.Game.ShowCard(card);
                }
                else
                {
                    card.Game.HideCard(card);
                }
            }
        }
        // update back side flag, if needed
        if (backSide != card.BackSide)
        {
            card.BackSide = backSide;
            SVGUtils.MarkSceneDirty();
            needSpriteUpdate = true;
        }
        // update animal/card type, if needed
        if (animalType != card.AnimalType)
        {
            card.AnimalType = animalType;
            SVGUtils.MarkSceneDirty();
            needSpriteUpdate = true;
        }
        // update game manager, if needed
        if (game != card.Game)
        {
            card.Game = game;
            SVGUtils.MarkSceneDirty();
        }

        if (needSpriteUpdate && (card.Game != null))
        {
            card.Game.UpdateCardSprite(card);
        }
    }
    public override void OnInspectorGUI()
    {
        // get the target object
        SVGCanvasBehaviour canvasBehaviour = target as SVGCanvasBehaviour;

        if ((canvasBehaviour != null) && (canvasBehaviour.UIAtlas != null))
        {
            Canvas canvas = canvasBehaviour.GetComponent <Canvas>();
            if (canvas != null)
            {
                base.OnInspectorGUI();
                // maintain the canvas scale factor synched between Canvas an SVGUIAtlas!
                canvasBehaviour.EnsureCanvasAssigned();
                bool isDirty = this.DrawInspector(canvasBehaviour.UIAtlas, canvas);
                if (isDirty)
                {
                    SVGUtils.MarkObjectDirty(canvasBehaviour.UIAtlas);
                    SVGUtils.MarkSceneDirty();
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        if (SVGAtlasEditor.m_Styles == null)
        {
            SVGAtlasEditor.m_Styles = new Styles();
        }

        // get the target object
        SVGAtlas atlas = target as SVGAtlas;

        if (atlas != null)
        {
            base.OnInspectorGUI();
            // we assign the Name property, so we can check if the user has renamed the atlas asset file
            atlas.Name = atlas.name;
            bool isDirty = this.DrawInspector(atlas);
            if (isDirty)
            {
                SVGUtils.MarkObjectDirty(atlas);
                SVGUtils.MarkSceneDirty();
            }
        }
    }
    private void DrawInspector(SVGBackgroundBehaviour svgBackground)
    {
        SVGBackgroundScaleType scaleAdaption = SVGBackgroundScaleType.Vertical;
        int       size         = 256;
        int       slicedWidth  = 256;
        int       slicedHeight = 256;
        bool      needUpdate   = false;
        bool      fullUpdate   = false;
        TextAsset svgFile      = EditorGUILayout.ObjectField("SVG file", svgBackground.SVGFile, typeof(TextAsset), true) as TextAsset;
        bool      sliced       = EditorGUILayout.Toggle(new GUIContent("Sliced", "Check if you want to slice the background in order to fit specified width/height"), svgBackground.Sliced);

        if (sliced)
        {
            slicedWidth  = EditorGUILayout.IntField(new GUIContent("Width", "Sliced width, in pixels"), svgBackground.SlicedWidth);
            slicedHeight = EditorGUILayout.IntField(new GUIContent("Height", "Sliced height, in pixels"), svgBackground.SlicedHeight);
        }
        else
        {
            scaleAdaption = (SVGBackgroundScaleType)EditorGUILayout.EnumPopup("Scale adaption", svgBackground.ScaleAdaption);
            size          = EditorGUILayout.IntField(new GUIContent("Size", "Size in pixels"), svgBackground.Size);
        }
        Color clearColor      = EditorGUILayout.ColorField("Clear color", svgBackground.ClearColor);
        bool  generateOnStart = EditorGUILayout.Toggle(new GUIContent("Generate on Start()", "Generate the background texture/sprite on Start()"), svgBackground.GenerateOnStart);
        bool  fastUpload      = EditorGUILayout.Toggle(new GUIContent("Fast upload", "Use the fast native method (OpenGL/DirectX) to upload the texture to the GPU"), svgBackground.FastUpload);

        // show dimensions in pixel and world units
        EditorGUILayout.LabelField("Width (pixel unit)", svgBackground.PixelWidth.ToString());
        EditorGUILayout.LabelField("Height (pixel units)", svgBackground.PixelHeight.ToString());
        EditorGUILayout.LabelField("Width (world units)", svgBackground.WorldWidth.ToString());
        EditorGUILayout.LabelField("Height (world units)", svgBackground.WorldHeight.ToString());

        // update svg file, if needed
        if (svgFile != svgBackground.SVGFile)
        {
            svgBackground.SVGFile = svgFile;
            SVGUtils.MarkSceneDirty();
            needUpdate = true;
            // in this case we must destroy the current document and load the new one
            fullUpdate = true;
        }

        if (sliced != svgBackground.Sliced)
        {
            svgBackground.Sliced = sliced;
            SVGUtils.MarkSceneDirty();
            needUpdate = true;
        }

        if (sliced)
        {
            // update sliced width (in pixels), if needed
            if (slicedWidth != svgBackground.SlicedWidth)
            {
                svgBackground.SlicedWidth = slicedWidth;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
            // update sliced height (in pixels), if needed
            if (slicedHeight != svgBackground.SlicedHeight)
            {
                svgBackground.SlicedHeight = slicedHeight;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
        }
        else
        {
            // update scale adaption, if needed
            if (scaleAdaption != svgBackground.ScaleAdaption)
            {
                svgBackground.ScaleAdaption = scaleAdaption;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
            // update size (in pixels), if needed
            if (size != svgBackground.Size)
            {
                svgBackground.Size = size;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
        }
        // update clear color, if needed
        if (clearColor != svgBackground.ClearColor)
        {
            svgBackground.ClearColor = clearColor;
            SVGUtils.MarkSceneDirty();
            needUpdate = true;
        }
        // update "update on start" flag, if needed
        if (generateOnStart != svgBackground.GenerateOnStart)
        {
            svgBackground.GenerateOnStart = generateOnStart;
            SVGUtils.MarkSceneDirty();
        }
        // update "fast upload" flag, if needed
        if (fastUpload != svgBackground.FastUpload)
        {
            svgBackground.FastUpload = fastUpload;
            SVGUtils.MarkSceneDirty();
        }
        // update the background, if needed
        if (needUpdate)
        {
            svgBackground.UpdateBackground(fullUpdate);
        }
    }