private bool InstancesGroupWrap(SVGAssetInput svgAsset, int spritesCount)
    {
        int rangeLo = svgAsset.InstanceBaseIdx;
        int rangeHi = rangeLo + spritesCount;

        return((rangeHi >= SPRITES_SORTING_MAX_INSTANCES) ? true : false);
    }
    private int SortingOrderGenerate(SVGSpriteAssetFile spriteAsset)
    {
        if (spriteAsset != null)
        {
            SVGSpriteRef  spriteRef  = spriteAsset.SpriteRef;
            SVGSpriteData spriteData = spriteAsset.SpriteData;

            int svgIndex = this.SvgAssetIndexGet(spriteRef.TxtAsset);
            if (svgIndex >= 0)
            {
                SVGSpritesList spritesList;
                SVGAssetInput  svgAsset = this.m_SvgList[svgIndex];

                // if needed, advance in the instances group
                if (spriteData.InCurrentInstancesGroup)
                {
                    // get the list of sprites (references) relative to the SVG input asset
                    if (this.m_GeneratedSpritesLists.TryGetValue(svgAsset.TxtAsset.GetInstanceID(), out spritesList))
                    {
                        // advance instances group, telling that we are going to instantiate one sprite only
                        this.NextInstancesGroup(svgAsset, spritesList, 1);
                    }
                }
                return(SVGAtlas.SortingOrderCalc(svgIndex, svgAsset.InstanceBaseIdx, spriteData.ZOrder));
            }
        }
        return(-1);
    }
 public void SvgAssetSeparateGroupsSet(SVGAssetInput svgAsset, bool separateGroups)
 {
     if ((svgAsset != null) && (svgAsset.SeparateGroups != separateGroups))
     {
         svgAsset.SeparateGroups = separateGroups;
         // recalculate atlas hash
         this.UpdateAtlasHash();
     }
 }
 public void SvgAssetScaleAdjustmentSet(SVGAssetInput svgAsset, float scale)
 {
     if ((svgAsset != null) && (svgAsset.Scale != scale))
     {
         svgAsset.Scale = scale;
         // recalculate atlas hash
         this.UpdateAtlasHash();
     }
 }
    private void SortingOrdersCompact(SVGAssetInput svgAsset)
    {
        List <SpriteRenderer> spriteRenderers = new List <SpriteRenderer>();
        // get the list of instantiated sprites relative to this atlas generator
        List <GameObject> spritesInstances = new List <GameObject>();

        this.GetSpritesInstances(spritesInstances);

        foreach (GameObject gameObj in spritesInstances)
        {
            SVGSpriteLoaderBehaviour spriteLoader = (SVGSpriteLoaderBehaviour)gameObj.GetComponent <SVGSpriteLoaderBehaviour>();
            SVGSpriteRef             spriteRef    = spriteLoader.SpriteReference;
            // if the sprite belongs to the specified SVG asset input, keep track of it
            if (spriteRef.TxtAsset == svgAsset.TxtAsset)
            {
                SpriteRenderer renderer = (SpriteRenderer)gameObj.GetComponent <SpriteRenderer>();
                if (renderer != null)
                {
                    spriteRenderers.Add(renderer);
                }
            }
        }

        if (spriteRenderers.Count > 0)
        {
            // order the list by current sorting order
            spriteRenderers.Sort(delegate(SpriteRenderer renderer1, SpriteRenderer renderer2) {
                if (renderer1.sortingOrder < renderer2.sortingOrder)
                {
                    return(-1);
                }
                if (renderer1.sortingOrder > renderer2.sortingOrder)
                {
                    return(1);
                }
                return(0);
            });

            int j = spriteRenderers.Count;
            for (int i = 0; i < j; ++i)
            {
                SpriteRenderer renderer     = spriteRenderers[i];
                int            currentOrder = renderer.sortingOrder;
                // isolate high part
                int svgIndex = currentOrder & SPRITES_SORTING_DOCUMENTS_MASK;
                // assign the new order
                renderer.sortingOrder = SVGAtlas.SortingOrderCalc(svgIndex, i);
            }
            svgAsset.InstanceBaseIdx = j;
        }
        else
        {
            // there are no sprite instances relative to the specified SVG, so we can start from 0
            svgAsset.InstanceBaseIdx = 0;
        }
    }
    public override bool SvgAssetMove(SVGAssetInput svgAsset, int toIndex)
    {
        int  fromIndex = this.SvgAssetIndexGet(svgAsset.TxtAsset);
        bool moved     = this.SvgAssetMove(svgAsset, fromIndex, toIndex);

        if (moved)
        {
            // recalculate sorting orders of instantiated sprites
            this.SortingOrdersUpdateSvgIndex();
        }
        return(moved);
    }
 protected int SvgAssetIndexGet(TextAsset txtAsset)
 {
     if (txtAsset != null)
     {
         // find the SVG index inside the SvgList
         int j = this.m_SvgList.Count;
         for (int i = 0; i < j; ++i)
         {
             SVGAssetInput svgAsset = this.m_SvgList[i];
             if (svgAsset.TxtAsset == txtAsset)
             {
                 return(i);
             }
         }
     }
     // if we have not found the svg index, return -1 as error
     return(-1);
 }
 protected bool SvgAssetMove(SVGAssetInput svgAsset, int fromIndex, int toIndex)
 {
     if (fromIndex >= 0)
     {
         // clamp the destination index
         toIndex = SVGUtils.Clamp(toIndex, 0, this.m_SvgList.Count);
         // check if movement has sense
         if (fromIndex != toIndex)
         {
             // perform the real movement
             this.m_SvgList.Insert(toIndex, this.m_SvgList[fromIndex]);
             if (toIndex <= fromIndex)
             {
                 ++fromIndex;
             }
             this.m_SvgList.RemoveAt(fromIndex);
             return(true);
         }
     }
     return(false);
 }
    private bool SvgInputAssetDraw(SVGBasicAtlas atlas, int index, out Rect rowRect)
    {
        bool          isDirty;
        SVGAssetInput svgAsset  = atlas.SvgAsset(index);
        bool          highlight = (this.m_DragInfo.Dragging && this.m_DragInfo.DraggedObject == svgAsset) ? true : false;

        if (this.m_DragInfo.InsertIdx == index && this.m_DragInfo.InsertBefore)
        {
            // draw a separator before the row
            GUILayout.Box(GUIContent.none, this.m_BlueLine, GUILayout.ExpandWidth(true), GUILayout.Height(2));
        }

        // if the SVG row is the dragged one, change colors
        if (highlight)
        {
            EditorGUILayout.BeginHorizontal(this.m_HighlightRow);
            // a row: asset name, separate groups checkbox, remove button, instantiate button
            EditorGUILayout.LabelField(svgAsset.TxtAsset.name, this.m_HighlightRow, GUILayout.MinWidth(10));
        }
        else
        {
            EditorGUILayout.BeginHorizontal();
            // a row: asset name, separate groups checkbox, remove button, instantiate button
            EditorGUILayout.LabelField(svgAsset.TxtAsset.name, GUILayout.MinWidth(10));
        }

        isDirty = this.SvgInputAssetDrawImplementation(atlas, svgAsset, index);

        EditorGUILayout.EndHorizontal();
        rowRect = GUILayoutUtility.GetLastRect();

        if (this.m_DragInfo.InsertIdx == index && (!this.m_DragInfo.InsertBefore))
        {
            // draw a separator after the row
            GUILayout.Box(GUIContent.none, this.m_BlueLine, GUILayout.ExpandWidth(true), GUILayout.Height(2));
        }

        return(isDirty);
    }
    private void NextInstancesGroup(SVGAssetInput svgAsset, SVGSpritesList spritesList, int instantiationCount)
    {
        int spritesCount = spritesList.Sprites.Count;

        svgAsset.InstanceBaseIdx += spritesCount;
        if (this.InstancesGroupWrap(svgAsset, spritesCount))
        {
            // try to compact used sorting orders (looping game objects that reference this svg)
            this.SortingOrdersCompact(svgAsset);

            // after compaction, if the instantiation of one or all sprites belonging to the new instances group will wrap
            // we have two options:
            //
            // 1. to instantiate sprites in the normal consecutive way, wrapping aroung SPRITES_SORTING_MAX_INSTANCES: in this case a part of sprites will
            // result (sortingOrder) consistent, but the whole sprites group won't
            //
            // 2. to reset the base index to 0 and generate the sprites according to their natural z-order: in this case the whole sprites group will
            // be (sortingOrder) consistent, but it is not granted to be totally (z)separated from other sprites/instances
            //

            if (this.InstancesGroupWrap(svgAsset, spritesCount))
            {
                svgAsset.InstanceBaseIdx = 0;

                /*
                 * // option 2
                 * if (instantiationCount > 1)
                 *  packedSvg.InstanceBaseIdx = 0;
                 * // for single sprite instantiation we implicitly use option 1
                 */
            }
        }

        // now we can unflag sprites
        this.ResetGroupFlags(spritesList);
    }
 public abstract bool SvgAssetMove(SVGAssetInput svgAsset, int toIndex);
    public GameObject[] InstantiateGroups(SVGAssetInput svgAsset)
    {
        SVGSpritesList spritesList;

        if (svgAsset != null && this.m_GeneratedSpritesLists.TryGetValue(svgAsset.TxtAsset.GetInstanceID(), out spritesList))
        {
            int spritesCount = spritesList.Sprites.Count;
            int svgIndex     = this.SvgAssetIndexGet(svgAsset.TxtAsset);
            if (svgIndex >= 0 && spritesCount > 0)
            {
                // list of sprite assets (file) relative to the specified SVG; in this case we can set the right list capacity
                List <SVGSpriteAssetFile> spriteAssets = new List <SVGSpriteAssetFile>(spritesCount);

                bool advanceInstancesGroup = false;
                // now we are sure that at least one valid sprite box exists
                float xMin = float.MaxValue;
                float yMin = float.MaxValue;
                float xMax = float.MinValue;
                float yMax = float.MinValue;

                foreach (SVGSpriteRef spriteRef in spritesList.Sprites)
                {
                    SVGSpriteAssetFile spriteAsset;
                    if (this.m_GeneratedSpritesFiles.TryGetValue(spriteRef, out spriteAsset))
                    {
                        SVGSpriteData spriteData = spriteAsset.SpriteData;
                        Sprite        sprite     = spriteData.Sprite;
                        //float scl = 1 / spriteData.Scale;
                        float scl        = 1;
                        float ox         = (float)spriteData.OriginalX;
                        float oy         = (float)spriteData.OriginalY;
                        float spriteMinX = ox * scl;
                        float spriteMinY = oy * scl;
                        float spriteMaxX = (ox + sprite.rect.width) * scl;
                        float spriteMaxY = (oy + sprite.rect.height) * scl;

                        // update min corner
                        if (spriteMinX < xMin)
                        {
                            xMin = spriteMinX;
                        }
                        if (spriteMinY < yMin)
                        {
                            yMin = spriteMinY;
                        }
                        // update max corner
                        if (spriteMaxX > xMax)
                        {
                            xMax = spriteMaxX;
                        }
                        if (spriteMaxY > yMax)
                        {
                            yMax = spriteMaxY;
                        }
                        // if there is a single sprite already instantiated in the current group, we have to advance in the next instances group
                        if (spriteData.InCurrentInstancesGroup)
                        {
                            advanceInstancesGroup = true;
                        }
                        // keep track of this sprite asset
                        spriteAssets.Add(spriteAsset);
                    }
                }

                if (spriteAssets.Count > 0)
                {
                    // because at least one valid sprite box exists, now we are sure that a valid "global" box has been calculated
                    float             centerX   = (xMin + xMax) / 2;
                    float             centerY   = (yMin + yMax) / 2;
                    float             boxHeight = yMax - yMin;
                    List <GameObject> instances = new List <GameObject>();

                    if (advanceInstancesGroup)
                    {
                        // advance in the instances group, telling that we are going to instantiate N sprites
                        this.NextInstancesGroup(svgAsset, spritesList, spriteAssets.Count);
                    }

                    foreach (SVGSpriteAssetFile spriteAsset in spriteAssets)
                    {
                        SVGSpriteData spriteData = spriteAsset.SpriteData;
                        Sprite        sprite     = spriteData.Sprite;
                        Vector2       pivot      = spriteData.Pivot;
                        //float scl = 1 / spriteData.Scale;
                        float   scl      = 1;
                        float   px       = (sprite.rect.width * pivot.x + (float)spriteData.OriginalX) * scl - centerX;
                        float   py       = boxHeight - (sprite.rect.height * (1 - pivot.y) + (float)spriteData.OriginalY) * scl - centerY;
                        Vector2 worldPos = new Vector2(px / SVGBasicAtlas.SPRITE_PIXELS_PER_UNIT, py / SVGBasicAtlas.SPRITE_PIXELS_PER_UNIT);
                        // instantiate the object
                        int sortingOrder = SVGAtlas.SortingOrderCalc(svgIndex, svgAsset.InstanceBaseIdx, spriteData.ZOrder);
                        //instances.Add(this.InstantiateSprite(spriteAsset, worldPos, sortingOrder));
                        GameObject newObj = this.InstantiateSprite(spriteAsset, worldPos, sortingOrder);
                        newObj.transform.localScale        = new Vector3(scl, scl, 1);
                        spriteData.InCurrentInstancesGroup = true;
                    }
                    // return the created instances
                    return(instances.ToArray());
                }
            }
        }
        return(null);
    }
    protected override bool SvgInputAssetDrawImplementation(SVGBasicAtlas basicAtlas, SVGAssetInput svgAsset, int svgAssetIndex)
    {
        SVGUIAtlas uiAtlas = basicAtlas as SVGUIAtlas;
        bool       isDirty = false;

        // scale adjustment for this SVG
        EditorGUILayout.LabelField(new GUIContent("Scale adjustment", "An additional scale factor used to adjust this SVG content only"), GUILayout.Width(105));
        float offsetScale = EditorGUILayout.FloatField(svgAsset.Scale, GUILayout.Width(45));

        EditorGUILayout.LabelField("", GUILayout.Width(5));
        if (offsetScale != svgAsset.Scale)
        {
            uiAtlas.SvgAssetScaleAdjustmentSet(svgAsset, Math.Abs(offsetScale));
            isDirty = true;
        }

        // 'explode groups' flag
        bool separateGroups = EditorGUILayout.Toggle("", svgAsset.SeparateGroups, GUILayout.Width(14));

        EditorGUILayout.LabelField("Separate groups", GUILayout.Width(105));
        // if group explosion flag has been changed, update it
        if (separateGroups != svgAsset.SeparateGroups)
        {
            uiAtlas.SvgAssetSeparateGroupsSet(svgAsset, separateGroups);
            isDirty = true;
        }

        // if 'Remove' button is clicked, remove the SVG entry
        if (GUILayout.Button("Remove", EditorStyles.miniButton, GUILayout.Width(70)))
        {
            uiAtlas.SvgAssetRemove(svgAssetIndex);
            isDirty = true;
        }
        return(isDirty);
    }
    private bool DrawInspector(SVGUIAtlas uiAtlas, Canvas canvas)
    {
        Rect scollRect;
        bool isDirty = false;
        // get current event
        Event currentEvent = Event.current;

        // show current options
        EditorGUILayout.LabelField("Canvas scale factor", uiAtlas.CanvasScaleFactor.ToString());
        float offsetScale          = EditorGUILayout.FloatField(this.m_OffsetScaleContent, uiAtlas.OffsetScale);
        bool  pow2Textures         = EditorGUILayout.Toggle(this.m_Pow2TexturesContent, uiAtlas.Pow2Textures);
        int   maxTexturesDimension = EditorGUILayout.IntField(this.m_MaxTexturesDimensionContent, uiAtlas.MaxTexturesDimension);
        int   border             = EditorGUILayout.IntField(this.m_SpritesPaddingContent, uiAtlas.SpritesBorder);
        Color clearColor         = EditorGUILayout.ColorField(this.m_ClearColorContent, uiAtlas.ClearColor);
        bool  fastUpload         = EditorGUILayout.Toggle(this.m_FastUploadContent, uiAtlas.FastUpload);
        float spritesPreviewSize = (float)EditorGUILayout.IntField(this.m_SpritesPreviewSizeContent, (int)uiAtlas.SpritesPreviewSize);

        // output folder
        this.OutputFolderDraw(uiAtlas);

        // draw the list of input SVG files / assets
        isDirty |= this.SvgInputAssetsDraw(uiAtlas, currentEvent, out scollRect);

        // update button
        if (this.UpdateButtonDraw(uiAtlas))
        {
            // regenerate/update sprites
            uiAtlas.UpdateEditorSprites();
            isDirty = true;
        }

        GUILayout.Space(10);

        if (uiAtlas.SvgAssetsCount() > 0)
        {
            // list of sprites, grouped by SVG document
            //Vector2 spritesScrollPos = EditorGUILayout.BeginScrollView(this.m_SvgSpritesScrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            Vector2 spritesScrollPos = EditorGUILayout.BeginScrollView(this.m_SvgSpritesScrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinHeight(uiAtlas.SpritesPreviewSize * 5));
            bool    separatorNeeded  = false;

            for (int i = 0; i < uiAtlas.SvgAssetsCount(); ++i)
            {
                SVGAssetInput             svgAsset      = uiAtlas.SvgAsset(i);
                List <SVGSpriteAssetFile> spritesAssets = uiAtlas.GetGeneratedSpritesByDocument(svgAsset.TxtAsset);
                if (spritesAssets != null && spritesAssets.Count > 0)
                {
                    // line separator
                    if (separatorNeeded)
                    {
                        EditorGUILayout.Separator();
                        GUILayout.Box(GUIContent.none, this.m_GreyLine, GUILayout.ExpandWidth(true), GUILayout.Height(1));
                        EditorGUILayout.Separator();
                    }
                    // display sprites list
                    foreach (SVGSpriteAssetFile spriteAsset in spritesAssets)
                    {
                        this.SpritePreview(uiAtlas, canvas, spriteAsset);
                    }
                    // we have displayed some sprites, next time a line separator is needed
                    separatorNeeded = true;
                }
            }
            EditorGUILayout.EndScrollView();

            if (this.m_SvgSpritesScrollPos != spritesScrollPos)
            {
                this.m_SvgSpritesScrollPos = spritesScrollPos;
            }
        }

        // events handler
        isDirty |= this.HandleDragEvents(uiAtlas, currentEvent, scollRect);

        // a negative value is not allowed for texture max dimension
        maxTexturesDimension = (maxTexturesDimension < 0) ? 1024 : maxTexturesDimension;
        // a negative value is not allowed for border
        border = (border < 0) ? 0 : border;
        // if offset additional scale has been changed, update it
        if (uiAtlas.OffsetScale != offsetScale)
        {
            uiAtlas.OffsetScale = Math.Abs(offsetScale);
            isDirty             = true;
        }
        // if power-of-two forcing flag has been changed, update it
        if (uiAtlas.Pow2Textures != pow2Textures)
        {
            uiAtlas.Pow2Textures = pow2Textures;
            isDirty = true;
        }
        // if desired maximum texture dimension has been changed, update it
        if (uiAtlas.MaxTexturesDimension != maxTexturesDimension)
        {
            uiAtlas.MaxTexturesDimension = maxTexturesDimension;
            isDirty = true;
        }
        // if border between each packed SVG has been changed, update it
        if (uiAtlas.SpritesBorder != border)
        {
            uiAtlas.SpritesBorder = border;
            isDirty = true;
        }
        // if surface clear color has been changed, update it
        if (uiAtlas.ClearColor != clearColor)
        {
            uiAtlas.ClearColor = clearColor;
            isDirty            = true;
        }
        // if "fast upload" flag has been changed, update it
        if (uiAtlas.FastUpload != fastUpload)
        {
            uiAtlas.FastUpload = fastUpload;
            isDirty            = true;
        }
        // if sprites preview size has been changed, update it
        if (uiAtlas.SpritesPreviewSize != spritesPreviewSize)
        {
            uiAtlas.SpritesPreviewSize = spritesPreviewSize;
            isDirty = true;
        }

        return(isDirty);
    }
 // Constructor.
 public PackedSvgAssetDocLink(SVGAssetInput svgAsset, SVGDocument document)
 {
     this.m_Asset    = svgAsset;
     this.m_Document = document;
 }
 protected abstract bool SvgInputAssetDrawImplementation(SVGBasicAtlas atlas, SVGAssetInput svgAsset, int svgAssetIndex);
    protected override bool SvgInputAssetDrawImplementation(SVGBasicAtlas basicAtlas, SVGAssetInput svgAsset, int svgAssetIndex)
    {
        SVGAtlas atlas   = basicAtlas as SVGAtlas;
        bool     isDirty = false;

        // scale adjustment for this SVG
        EditorGUILayout.LabelField(new GUIContent("Scale adjustment", "An additional scale factor used to adjust this SVG content only"), GUILayout.Width(105));
        float offsetScale = EditorGUILayout.FloatField(svgAsset.Scale, GUILayout.Width(45));

        EditorGUILayout.LabelField("", GUILayout.Width(5));
        if (offsetScale != svgAsset.Scale)
        {
            atlas.SvgAssetScaleAdjustmentSet(svgAsset, Math.Abs(offsetScale));
            isDirty = true;
        }

        // 'explode groups' flag
        bool separateGroups = EditorGUILayout.Toggle("", svgAsset.SeparateGroups, GUILayout.Width(14));

        EditorGUILayout.LabelField("Separate groups", GUILayout.Width(105));
        // if group explosion flag has been changed, update it
        if (separateGroups != svgAsset.SeparateGroups)
        {
            atlas.SvgAssetSeparateGroupsSet(svgAsset, separateGroups);
            isDirty = true;
        }
        // if 'Remove' button is clicked, remove the SVG entry
        if (GUILayout.Button("Remove", EditorStyles.miniButton, GUILayout.Width(70)))
        {
            atlas.SvgAssetRemove(svgAssetIndex);
            isDirty = true;
        }
        // instantiate all groups
        GUI.enabled = ((svgAsset.Instantiable && (!Application.isPlaying)) ? true : false);
        if (GUILayout.Button("Instantiate", EditorStyles.miniButton, GUILayout.Width(80)))
        {
            GameObject[] gameObjs = atlas.InstantiateGroups(svgAsset);
            // set the created instances as selected
            if (gameObjs != null)
            {
                Selection.objects = gameObjs;
            }
        }
        GUI.enabled = !Application.isPlaying;
        return(isDirty);
    }
    private bool DrawInspector(SVGAtlas atlas)
    {
        Rect  scollRect;
        float match   = atlas.Match;
        bool  isDirty = false;
        // get current event
        Event currentEvent = Event.current;
        // show current options
        int refWidth                 = EditorGUILayout.IntField(new GUIContent("Reference width", "The resolution the SVG files content is designed for. If the screen resolution is larger, SVG contents will be scaled up, and if it’s smaller, it will be scaled down."), atlas.ReferenceWidth);
        int refHeight                = EditorGUILayout.IntField(new GUIContent("Reference height", "The resolution the SVG files content is designed for. If the screen resolution is larger, SVG contents will be scaled up, and if it’s smaller, it will be scaled down."), atlas.ReferenceHeight);
        int deviceTestWidth          = EditorGUILayout.IntField("Device test width", atlas.DeviceTestWidth);
        int deviceTestHeight         = EditorGUILayout.IntField("Device test height", atlas.DeviceTestHeight);
        SVGScalerMatchMode scaleType = (SVGScalerMatchMode)EditorGUILayout.EnumPopup(new GUIContent("Screen match mode", "A mode used to scale (i.e. generate) SVG sprites if the aspect ratio of the current resolution doesn’t fit the reference resolution."), atlas.ScaleType);

        if (scaleType == SVGScalerMatchMode.MatchWidthOrHeight)
        {
            Rect r = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + 12);
            match = this.MatchSlider(r, atlas.Match);
        }
        float offsetScale          = EditorGUILayout.FloatField(this.m_OffsetScaleContent, atlas.OffsetScale);
        bool  pow2Textures         = EditorGUILayout.Toggle(this.m_Pow2TexturesContent, atlas.Pow2Textures);
        int   maxTexturesDimension = EditorGUILayout.IntField(this.m_MaxTexturesDimensionContent, atlas.MaxTexturesDimension);
        int   border             = EditorGUILayout.IntField(this.m_SpritesPaddingContent, atlas.SpritesBorder);
        Color clearColor         = EditorGUILayout.ColorField(this.m_ClearColorContent, atlas.ClearColor);
        bool  fastUpload         = EditorGUILayout.Toggle(this.m_FastUploadContent, atlas.FastUpload);
        float spritesPreviewSize = (float)EditorGUILayout.IntField(this.m_SpritesPreviewSizeContent, (int)atlas.SpritesPreviewSize);

        // output folder
        this.OutputFolderDraw(atlas);

        // draw the list of input SVG files / assets
        isDirty |= this.SvgInputAssetsDraw(atlas, currentEvent, out scollRect);

        // update button
        if (this.UpdateButtonDraw(atlas))
        {
            // regenerate/update sprites
            atlas.UpdateEditorSprites(true);
            isDirty = true;
        }
        GUILayout.Space(10);

        if (atlas.SvgAssetsCount() > 0)
        {
            // list of sprites, grouped by SVG document
            Vector2 spritesScrollPos = EditorGUILayout.BeginScrollView(this.m_SvgSpritesScrollPos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            bool separatorNeeded = false;
            for (int i = 0; i < atlas.SvgAssetsCount(); ++i)
            {
                SVGAssetInput             svgAsset      = atlas.SvgAsset(i);
                List <SVGSpriteAssetFile> spritesAssets = atlas.GetGeneratedSpritesByDocument(svgAsset.TxtAsset);
                if (spritesAssets != null && spritesAssets.Count > 0)
                {
                    // line separator
                    if (separatorNeeded)
                    {
                        EditorGUILayout.Separator();
                        GUILayout.Box(GUIContent.none, this.m_GreyLine, GUILayout.ExpandWidth(true), GUILayout.Height(1));
                        EditorGUILayout.Separator();
                    }
                    // display sprites list
                    foreach (SVGSpriteAssetFile spriteAsset in spritesAssets)
                    {
                        this.SpritePreview(atlas, spriteAsset);
                    }
                    // we have displayed some sprites, next time a line separator is needed
                    separatorNeeded = true;
                }
            }
            EditorGUILayout.EndScrollView();

            if (this.m_SvgSpritesScrollPos != spritesScrollPos)
            {
                this.m_SvgSpritesScrollPos = spritesScrollPos;
            }
        }

        // events handler
        isDirty |= this.HandleDragEvents(atlas, currentEvent, scollRect);

        // negative values are not allowed for reference resolution
        refWidth         = (refWidth <= 0) ? Screen.currentResolution.width : refWidth;
        refHeight        = (refHeight <= 0) ? Screen.currentResolution.height : refHeight;
        deviceTestWidth  = (deviceTestWidth <= 0) ? refWidth : deviceTestWidth;
        deviceTestHeight = (deviceTestHeight <= 0) ? refHeight : deviceTestHeight;
        // a negative value is not allowed for texture max dimension
        maxTexturesDimension = (maxTexturesDimension < 0) ? 1024 : maxTexturesDimension;
        // a negative value is not allowed for border
        border = (border < 0) ? 0 : border;

        // if reference resolution has been changed, update it
        if (atlas.ReferenceWidth != refWidth)
        {
            atlas.ReferenceWidth = refWidth;
            isDirty = true;
        }
        if (atlas.ReferenceHeight != refHeight)
        {
            atlas.ReferenceHeight = refHeight;
            isDirty = true;
        }
        // if device (test) resolution has been changed, update it
        if (atlas.DeviceTestWidth != deviceTestWidth)
        {
            atlas.DeviceTestWidth = deviceTestWidth;
            isDirty = true;
        }
        if (atlas.DeviceTestHeight != deviceTestHeight)
        {
            atlas.DeviceTestHeight = deviceTestHeight;
            isDirty = true;
        }
        // if scale adaption method has been changed, update it
        if (atlas.ScaleType != scaleType)
        {
            atlas.ScaleType = scaleType;
            isDirty         = true;
        }
        if (atlas.Match != match)
        {
            atlas.Match = match;
            isDirty     = true;
        }
        // if offset additional scale has been changed, update it
        if (atlas.OffsetScale != offsetScale)
        {
            atlas.OffsetScale = Math.Abs(offsetScale);
            isDirty           = true;
        }
        // if power-of-two forcing flag has been changed, update it
        if (atlas.Pow2Textures != pow2Textures)
        {
            atlas.Pow2Textures = pow2Textures;
            isDirty            = true;
        }
        // if desired maximum texture dimension has been changed, update it
        if (atlas.MaxTexturesDimension != maxTexturesDimension)
        {
            atlas.MaxTexturesDimension = maxTexturesDimension;
            isDirty = true;
        }
        // if border between each packed SVG has been changed, update it
        if (atlas.SpritesBorder != border)
        {
            atlas.SpritesBorder = border;
            isDirty             = true;
        }
        // if surface clear color has been changed, update it
        if (atlas.ClearColor != clearColor)
        {
            atlas.ClearColor = clearColor;
            isDirty          = true;
        }
        // if "fast upload" flag has been changed, update it
        if (atlas.FastUpload != fastUpload)
        {
            atlas.FastUpload = fastUpload;
            isDirty          = true;
        }
        // if sprites preview size has been changed, update it
        if (atlas.SpritesPreviewSize != spritesPreviewSize)
        {
            atlas.SpritesPreviewSize = spritesPreviewSize;
            isDirty = true;
        }

        return(isDirty);
    }
Example #19
0
    public override bool SvgAssetMove(SVGAssetInput svgAsset, int toIndex)
    {
        int fromIndex = this.SvgAssetIndexGet(svgAsset.TxtAsset);

        return(this.SvgAssetMove(svgAsset, fromIndex, toIndex));
    }