Example #1
0
 void PackVerticalSpriteInfo(int tilePerColumn, int minTileY, int tileSize, TileSpriteInfo tileSpriteInfo, int id, int subId, ref int tileX, ref int tileY, ref int spriteInd, ref SpriteMetaData[] sprites, ref Texture2D texture)
 {
     if (tileSpriteInfo.importedSprites != null)
     {
         for (int i = 0; i < tileSpriteInfo.importedSprites.Length; i++)
         {
             if (tileSpriteInfo.importedSprites [i] != null)
             {
                 PackVerticalSprite(tilePerColumn, minTileY, tileSize, tileSpriteInfo.importedSprites [i], id, subId, i + 2, ref tileX, ref tileY, ref spriteInd, ref sprites, ref texture);
             }
         }
     }
 }
Example #2
0
        void TriangleSpriteChooser(TileInfo tile, TileSpriteInfo spriteInfo, int subId)
        {
            TileAtlas atlas = target as TileAtlas;

            GUILayout.BeginVertical("HelpBox");

            Sprite sprite = (Sprite)EditorGUILayout.ObjectField("Main sprite size=1", spriteInfo.importedSprite, typeof(Sprite), false);

            if (spriteInfo.importedSprite != sprite)
            {
                spriteInfo.importedSprite = sprite;

                atlas.BumpMinor();
            }

            if (spriteInfo.importedSprites != null)
            {
                for (int i = 0; i < spriteInfo.importedSprites.Length; i++)
                {
                    sprite = (Sprite)EditorGUILayout.ObjectField(
                        "Main sprite size=" + (i + 2),
                        spriteInfo.importedSprites [i],
                        typeof(Sprite),
                        false
                        );

                    if (spriteInfo.importedSprites [i] != sprite)
                    {
                        spriteInfo.importedSprites [i] = sprite;

                        atlas.BumpMinor();
                    }
                }
            }

            if (GUILayout.Button("Add sprite size"))
            {
                tile.AddSpriteSize(subId);

                atlas.BumpMinor();
            }
            if (GUILayout.Button("Remove sprite size"))
            {
                tile.RemoveSpriteSize(subId);

                atlas.BumpMinor();
            }

            GUILayout.EndVertical();
        }
Example #3
0
        /// <summary>
        /// For a given subId, removes a the sprite slot with the greatest size.
        /// </summary>
        public void RemoveSpriteSize(int subId)
        {
            TileSpriteInfo spriteInfo = null;

            if (subId == 0)
            {
                if (idSpriteInfo != null)
                {
                    spriteInfo = idSpriteInfo;
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (subIdSpriteInfo != null && (subId - 1) < subIdSpriteInfo.Length)
                {
                    spriteInfo = subIdSpriteInfo [subId - 1];
                }
                else
                {
                    return;
                }
            }

            if (spriteInfo.importedSprites != null)
            {
                if (spriteInfo.importedSprites.Length == 1)
                {
                    spriteInfo.importedSprites = null;
                }
                else
                {
                    Sprite[] sprites = spriteInfo.importedSprites;

                    spriteInfo.importedSprites = new Sprite[sprites.Length - 1];
                    for (int i = 0; i < spriteInfo.importedSprites.Length; i++)
                    {
                        spriteInfo.importedSprites [i] = sprites [i];
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Adds a subId to the tile.
        /// </summary>
        public void AddSubId()
        {
            if (subIdSpriteInfo == null)
            {
                subIdSpriteInfo = new TileSpriteInfo[1];
            }
            else
            {
                int length = subIdSpriteInfo.Length;

                TileSpriteInfo[] newSprites = new TileSpriteInfo[length + 1];
                for (int i = 0; i < length; i++)
                {
                    newSprites [i] = subIdSpriteInfo [i];
                }
                subIdSpriteInfo = newSprites;
            }
        }
Example #5
0
        void PackHorizontalSpriteInfo(int tilePerRow, int tileSize, TileSpriteInfo tileSpriteInfo, bool isVertical, int id, int subId, ref int tileX, ref int tileY, ref int spriteInd, ref SpriteMetaData[] sprites, ref Texture2D texture)
        {
            if (tileSpriteInfo.importedSprite != null)
            {
                PackHorizontalSprite(tilePerRow, tileSize, tileSpriteInfo.importedSprite, id, subId, 1, ref tileX, ref tileY, ref spriteInd, ref sprites, ref texture);
            }

            // ONLY FOR TRIANGLES
            if (!isVertical && tileSpriteInfo.importedSprites != null)
            {
                for (int i = 0; i < tileSpriteInfo.importedSprites.Length; i++)
                {
                    if (tileSpriteInfo.importedSprites [i] != null)
                    {
                        PackHorizontalSprite(tilePerRow, tileSize, tileSpriteInfo.importedSprites[i], id, subId, i + 2, ref tileX, ref tileY, ref spriteInd, ref sprites, ref texture);
                    }
                }
            }
        }
Example #6
0
        int TileSpriteCountInTileSpriteInfo(TileSpriteInfo info)
        {
            int count = 0;

            if (info != null)
            {
                if (info.importedSprite != null)
                {
                    count++;
                }

                if (info.importedSprites != null)
                {
                    count += info.importedSprites.Length;
                }
            }

            return(count);
        }
Example #7
0
        /// <summary>
        /// Removes the last subId of the tile.
        /// </summary>
        public void RemoveSubId()
        {
            if (subIdSpriteInfo != null)
            {
                if (subIdSpriteInfo.Length == 1)
                {
                    subIdSpriteInfo = null;
                }
                else
                {
                    int length = subIdSpriteInfo.Length;

                    TileSpriteInfo[] newSprites = new TileSpriteInfo[length - 1];
                    for (int i = 0; i < length - 1; i++)
                    {
                        newSprites [i] = subIdSpriteInfo [i];
                    }
                    subIdSpriteInfo = newSprites;
                }
            }
        }
Example #8
0
        int TileTextureCountInTileSpriteInfo(TileSpriteInfo info)
        {
            int count = 0;

            if (info != null)
            {
                if (info.importedSprite != null)
                {
                    count++;
                }

                if (info.importedSprites != null)
                {
                    for (int i = 0; i < info.importedSprites.Length; i++)
                    {
                        count += i + 2;
                    }
                }
            }

            return(count);
        }