Ejemplo n.º 1
0
        internal void SetData(Color[] data)
        {
            var dataLength   = data.Length;
            var destText     = UnityTexture as UnityEngine.Texture2D;
            var dst          = destText.GetRawTextureData <uint>();
            var tmp          = new uint[dataLength];
            var textureWidth = UnityTexture.width;

            for (int i = 0; i < dataLength; i++)
            {
                int x = i % textureWidth;
                int y = i / textureWidth;
                y *= textureWidth;
                var index = y + (textureWidth - x - 1);
                var color = data[dataLength - index - 1];
                //argb -> rgba
                tmp[i] = (uint)(color.R << 24 | color.G << 16 | color.B << 8 | color.A);
            }

            dst.CopyFrom(tmp);

            destText.Apply();

            Hash = UnityTexture.GetHashCode();
        }
Ejemplo n.º 2
0
        internal void SetData(byte[] data)
        {
            Console.WriteLine("SetData with bytes is probably not working properly yet, we're not converting the bytes at all.");
            var dataLength = data.Length;
            var destText   = UnityTexture as UnityEngine.Texture2D;
            var dst        = destText.GetRawTextureData <byte>();

            dst.CopyFrom(data);
            destText.Apply();
            Hash = UnityTexture.GetHashCode();
        }
Ejemplo n.º 3
0
        internal void SetData(uint[] data, int startOffset = 0, int elementCount = 0)
        {
            var textureWidth = UnityTexture.width;

            if (elementCount == 0)
            {
                elementCount = data.Length;
            }
            else
            {
                elementCount *= textureWidth;
            }
            // startOffset *= textureWidth;

            var destText   = UnityTexture as UnityEngine.Texture2D;
            var dst        = destText.GetRawTextureData <uint>();
            var dstLength  = dst.Length;
            var tmp        = new uint[dstLength];
            var dataLength = data.Length;

            for (int i = 0; i < elementCount; i++)
            {
                int x = i % textureWidth;
                int y = i / textureWidth;
                y *= textureWidth;
                var index = y + (textureWidth - x - 1);
                if (index < elementCount && i < dstLength)
                {
                    var  u          = data[dataLength - startOffset - index - 1];
                    uint firstByte  = u & 0xff;
                    uint secondByte = (u >> 8) & 0xff;
                    uint thirdByte  = (u >> 16) & 0xff;
                    uint fourthByte = (u >> 24) & 0xff;
                    tmp[i] = thirdByte << 24 | secondByte << 16 | firstByte << 8 | fourthByte;
                }
            }

            dst.CopyFrom(tmp);

            destText.Apply();

            Hash = UnityTexture.GetHashCode();
        }
Ejemplo n.º 4
0
        internal void SetData(ushort[] data, int elementCount)
        {
            var destText     = UnityTexture as UnityEngine.Texture2D;
            var dst          = destText.GetRawTextureData <uint>();
            var tmp          = new uint[elementCount];
            var textureWidth = UnityTexture.width;

            for (int i = 0; i < elementCount; i++)
            {
                int x = i % textureWidth;
                int y = i / textureWidth;
                y *= textureWidth;
                var index = y + (textureWidth - x - 1);
                tmp[i] = (uint)u16Tou32(data[elementCount - index - 1]);
            }

            dst.CopyFrom(tmp);

            destText.Apply();

            Hash = UnityTexture.GetHashCode();
        }
Ejemplo n.º 5
0
        internal void SetData(uint[] data, int startOffset = 0, int elementCount = 0, bool invertY = false)
        {
            var textureWidth  = UnityTexture.width;
            var textureHeight = UnityTexture.height;

            if (elementCount == 0)
            {
                elementCount = data.Length;
            }

            var destText  = UnityTexture as UnityEngine.Texture2D;
            var dst       = destText.GetRawTextureData <uint>();
            var dstLength = dst.Length;
            var tmp       = new uint[dstLength];

            for (int i = 0; i < elementCount; i++)
            {
                int x = i % textureWidth;
                int y = i / textureWidth;
                if (invertY)
                {
                    y = textureHeight - y - 1;
                }
                var index = (y * textureWidth) + (textureWidth - x - 1);
                if (index < elementCount && i < dstLength)
                {
                    tmp[i] = data[elementCount + startOffset - index - 1];
                }
            }

            dst.CopyFrom(tmp);

            destText.Apply();

            Hash = UnityTexture.GetHashCode();
        }