Beispiel #1
0
        public override void Apply()
        {
            if (SpriteRects != null && SpriteRects.Length > 0)
            {
                List <AseFileSpriteImportData> newImportData = new List <AseFileSpriteImportData>();

                foreach (SpriteRect spriteRect in SpriteRects)
                {
                    AseFileSpriteImportData data = new AseFileSpriteImportData()
                    {
                        alignment = spriteRect.alignment,
                        border    = spriteRect.border,
                        name      = spriteRect.name,
                        pivot     = spriteRect.pivot,
                        rect      = spriteRect.rect,
                        spriteID  = spriteRect.spriteID.ToString()
                    };

                    AseFileSpriteImportData current = Array.Find <AseFileSpriteImportData>(SpriteImportData, d => d.spriteID == spriteRect.spriteID.ToString());

                    if (current != null)
                    {
                        data.outline            = current.outline;
                        data.tessellationDetail = current.tessellationDetail;
                    }
                    else
                    {
                        data.outline            = SpriteAtlasBuilder.GenerateRectOutline(data.rect);
                        data.tessellationDetail = 0;
                    }

                    newImportData.Add(data);
                }

                SpriteRects = new SpriteRect[0];

                SpriteImportData = newImportData.ToArray();
                EditorUtility.SetDirty(Importer);
            }

            AssetDatabase.WriteImportSettingsIfDirty(AssetPath);
            //SaveAndReimport();

            AssetDatabase.Refresh();
            AssetDatabase.LoadAllAssetsAtPath(AssetPath);
            EditorApplication.RepaintProjectWindow();
        }
Beispiel #2
0
        public Texture2D GenerateAtlas(Texture2D[] sprites, int cols, int rows, out AseFileSpriteImportData[] spriteImportData, bool baseTwo = false)
        {
            spriteImportData = new AseFileSpriteImportData[sprites.Length];

            var width  = cols * spriteSize.x;
            var height = rows * spriteSize.y;

            if (baseTwo)
            {
                var baseTwoValue = CalculateNextBaseTwoValue(Math.Max(width, height));
                width  = baseTwoValue;
                height = baseTwoValue;
            }

            var atlas = Texture2DUtil.CreateTransparentTexture(width, height);
            var index = 0;

            for (var row = 0; row < rows; ++row)
            {
                for (var col = 0; col < cols; ++col)
                {
                    Rect    spriteRect = new Rect(col * spriteSize.x, atlas.height - ((row + 1) * spriteSize.y), spriteSize.x, spriteSize.y);
                    Color[] colors     = sprites[index].GetPixels();
                    atlas.SetPixels((int)spriteRect.x, (int)spriteRect.y, (int)spriteRect.width, (int)spriteRect.height, sprites[index].GetPixels());
                    atlas.Apply();

                    List <Vector2[]> outline = GenerateRectOutline(spriteRect);
                    spriteImportData[index] = CreateSpriteImportData(index.ToString(), spriteRect, outline);

                    index++;
                    if (index >= sprites.Length)
                    {
                        break;
                    }
                }
                if (index >= sprites.Length)
                {
                    break;
                }
            }

            return(atlas);
        }
Beispiel #3
0
        public void SetSingleSpriteImportData()
        {
            Rect spriteRect = new Rect(0, 0, textureWidth, textureHeight);

            SpriteImportData = new AseFileSpriteImportData[]
            {
                new AseFileSpriteImportData()
                {
                    alignment          = SpriteAlignment.Center,
                    border             = Vector4.zero,
                    name               = name,
                    outline            = SpriteAtlasBuilder.GenerateRectOutline(spriteRect),
                    pivot              = new Vector2(0.5f, 0.5f),
                    rect               = spriteRect,
                    spriteID           = GUID.Generate().ToString(),
                    tessellationDetail = 0
                }
            };

            AnimationSettings = null;
        }