UnityEngine.Texture2D.SetPixels C# (CSharp) Méthode

SetPixels() public méthode

Set a block of pixel colors.

public SetPixels ( Color colors, [ miplevel ) : void
colors Color The array of pixel colours to assign (a 2D image flattened to a 1D array).
miplevel [ The mip level of the texture to write to.
Résultat void
        public void SetPixels(Color[] colors, [DefaultValue("0")] int miplevel)
        {
            int blockWidth = this.width >> miplevel;
            if (blockWidth < 1)
            {
                blockWidth = 1;
            }
            int blockHeight = this.height >> miplevel;
            if (blockHeight < 1)
            {
                blockHeight = 1;
            }
            this.SetPixels(0, 0, blockWidth, blockHeight, colors, miplevel);
        }

Same methods

Texture2D::SetPixels ( Color colors ) : void
Texture2D::SetPixels ( int x, int y, int blockWidth, int blockHeight, Color colors ) : void
Texture2D::SetPixels ( int x, int y, int blockWidth, int blockHeight, Color colors, [ miplevel ) : void

Usage Example

    public void CalculateWidget()
    {
        int canvasWidth = FullHeart.width * (_playerHealthSystem.MaxHP / 2);
        int fullHearts = _playerHealthSystem.HP / 2;
        int halfHearts = _playerHealthSystem.HP % 2;
        int deadHearts = (_playerHealthSystem.MaxHP / 2) - (_playerHealthSystem.HP / 2);

        Texture2D tex = new Texture2D(canvasWidth, FullHeart.height);

        int i = 0;

        for(int counter = 0; counter < fullHearts; counter++)
        {
            tex.SetPixels(i, 0, FullHeart.width, FullHeart.height, FullHeart.GetPixels());
            i += FullHeart.width;
        }

        for(int counter = 0; counter < halfHearts; counter++)
        {
            tex.SetPixels(i, 0, FullHeart.width, FullHeart.height, HalfHeart.GetPixels());
            i += FullHeart.width;
        }

        for(int counter = 0; counter < deadHearts; counter++)
        {
            tex.SetPixels(i, 0, FullHeart.width, FullHeart.height, NoHeart.GetPixels());
            i += FullHeart.width;
        }

        tex.Apply();

        _fullUiWidget = tex;
        UiWidget.Image = _fullUiWidget;
    }
All Usage Examples Of UnityEngine.Texture2D::SetPixels