Ejemplo n.º 1
0
    public void Refresh()
    {
        Color[] backgroundPixels = new Color[_animStripTexture.width * _animStripTexture.height];

        for (int i = 0; i < backgroundPixels.Length; i++)
        {
            backgroundPixels[i] = backgroundColor;
        }

        _animStripTexture.SetPixels(backgroundPixels);

        int y = _animStripTexture.height - thumbnailSize - 1;
        int x = 1;

        int currentIndex = spriteSheet.GetRow(currentRowKey).GetIndex(currentCellKey);

        for (int cellIndex = 0; cellIndex < spriteSheet.GetRow(currentRowKey).cells.Length; cellIndex++)
        {
            int   showIndex   = cellIndex;
            Color borderColor = Color.white;

            if (dragTargetIndex >= 0)
            {
                if (dragTargetIndex == cellIndex && dragTargetIndex != currentIndex)
                {
                    showIndex   = currentIndex;
                    borderColor = new Color(0.8f, 0.8f, 0f, 1f);
                }
                else if (cellIndex < currentIndex && cellIndex < dragTargetIndex || cellIndex > currentIndex && cellIndex > dragTargetIndex)
                {
                    //noop
                }
                else if (cellIndex >= currentIndex && cellIndex < dragTargetIndex)
                {
                    showIndex = cellIndex + 1;
                }
                else if (cellIndex <= currentIndex && cellIndex > dragTargetIndex)
                {
                    showIndex = cellIndex - 1;
                }
            }

            Color[] thumbnail =
                spriteSheet.getPreviewImage(
                    spriteSheet.GetIndex(currentRowKey),
                    showIndex,
                    thumbnailSize - 2,
                    thumbnailSize - 2,
                    currentCellKey == spriteSheet.GetRow(currentRowKey).cells[showIndex].key,
                    borderColor);

            _animStripTexture.SetPixels(x + 1, y + 1, thumbnailSize - 2, thumbnailSize - 2, thumbnail);

            x += thumbnailSize;
            if (x + thumbnailSize > _animStripTexture.width - 1)
            {
                x  = 1;
                y -= thumbnailSize;
            }
        }

        Color emptyFrameBackgroundColor =
            backgroundColor + new Color(0.02f, 0.02f, 0.02f, 1f);

        Color[] emptySprite = new Color[(thumbnailSize - 2) * (thumbnailSize - 2)];

        for (int i = 0; i < emptySprite.Length; i++)
        {
            emptySprite[i] = emptyFrameBackgroundColor;
        }

        if (x > 1)
        {
            while (x < pixelWidth - thumbnailSize)
            {
                _animStripTexture.SetPixels(x + 1, y + 1, thumbnailSize - 2, thumbnailSize - 2, emptySprite);
                x += thumbnailSize;
            }
        }

        //RagePixelUtil.drawPixelBorder(_animStripTexture, new Color(0.1f, 0.1f, 0.1f, 1f));
        RagePixelUtil.drawPixelBorder(_animStripTexture, new Color(0f, 0f, 0f, 1f));

        _animStripTexture.Apply();
    }
    public void Refresh()
    {
        if (spriteSheet != null)
        {
            Color[] backgroundPixels = new Color[_spriteSheetTexture.width * _spriteSheetTexture.height];

            for (int i = 0; i < backgroundPixels.Length; i++)
            {
                backgroundPixels[i] = backgroundColor;
            }

            _spriteSheetTexture.SetPixels(backgroundPixels);

            int y            = _spriteSheetTexture.height - thumbnailSize - 1;
            int x            = 1;
            int currentIndex = spriteSheet.GetIndex(currentRowKey);

            for (int rowIndex = 0; rowIndex < spriteSheet.rows.Length; rowIndex++)
            {
                int   showIndex   = rowIndex;
                Color borderColor = Color.white;

                if (dragTargetIndex >= 0)
                {
                    if (dragTargetIndex == rowIndex && dragTargetIndex != currentIndex)
                    {
                        showIndex   = currentIndex;
                        borderColor = new Color(0.8f, 0.8f, 0f, 1f);
                    }
                    else if (rowIndex < currentIndex && rowIndex < dragTargetIndex || rowIndex > currentIndex && rowIndex > dragTargetIndex)
                    {
                        //noop
                    }
                    else if (rowIndex >= currentIndex && rowIndex < dragTargetIndex)
                    {
                        showIndex = rowIndex + 1;
                    }
                    else if (rowIndex <= currentIndex && rowIndex > dragTargetIndex)
                    {
                        showIndex = rowIndex - 1;
                    }
                }

                showIndex = Mathf.Clamp(showIndex, 0, spriteSheet.rows.Length - 1);

                Color[] thumbnail =
                    spriteSheet.getPreviewImage(
                        showIndex,
                        0,
                        thumbnailSize - 2,
                        thumbnailSize - 2,
                        spriteSheet.GetKey(showIndex) == currentRowKey,
                        borderColor
                        );

                _spriteSheetTexture.SetPixels(x + 1, y + 1, thumbnailSize - 2, thumbnailSize - 2, thumbnail);

                x += thumbnailSize;
                if (x + thumbnailSize > _spriteSheetTexture.width - 1)
                {
                    x  = 1;
                    y -= thumbnailSize;
                }
            }

            Color emptySpriteBackgroundColor =
                (PlayerSettings.advancedLicense) ?
                new Color(0.22f, 0.22f, 0.22f, 1f) :
                new Color(0.53f, 0.53f, 0.53f, 1f);

            Color[] emptySprite = new Color[(thumbnailSize - 2) * (thumbnailSize - 2)];

            for (int i = 0; i < emptySprite.Length; i++)
            {
                emptySprite[i] = emptySpriteBackgroundColor;
            }

            if (x > 1)
            {
                while (x < pixelWidth - thumbnailSize)
                {
                    _spriteSheetTexture.SetPixels(x + 1, y + 1, thumbnailSize - 2, thumbnailSize - 2, emptySprite);
                    x += thumbnailSize;
                }
            }

            RagePixelUtil.drawPixelBorder(_spriteSheetTexture, new Color(0.1f, 0.1f, 0.1f, 1f));
            _spriteSheetTexture.Apply();
        }
    }