Код: Выделить всё
public class Parser : MonoBehaviour
публичный мат MeshRenderer;
Код: Выделить всё
public int bitsInPlane;
public int minX;
public int minY;
public int maxX;
public int maxY;
public int horzDPI;
public int vertDPI;
public int numColorPlanes;
public int bytesPerColorPlane;
public int horzSourceScreen;
public int vertSourceScreen;
public int startingPoint;
void Start()
{
Application.targetFrameRate = 24;
List byteStream = new List();
byteStream = readImageData();
printBytes(byteStream);
readBytesHeader(byteStream);
drawTexture(byteStream);
}
void Update()
{
}
List readImageData()
{
string pcxPath = Application.dataPath + "/resources/bagit_icon.pcx";
List readByteStream = new List();
using (var stream = File.Open(pcxPath, FileMode.Open))
{
using (var bReader = new BinaryReader(stream, System.Text.Encoding.UTF8, false))
{
while (stream.Position != stream.Length)
{
readByteStream.Add(bReader.ReadByte());
}
}
}
return readByteStream;
}
void printBytes(List bytes)
{
int offset = 0;
foreach (var b in bytes)
{
Debug.Log(offset.ToString("X4") + " [" + offset + "]: " + b);
offset++;
}
}
void readBytesHeader(List bytes)
{
bitsInPlane = bytes[3];
minX = bytes[4]; minY = bytes[6];
maxX = bytes[8]; maxY = bytes[10];
horzDPI = bytes[12];
vertDPI = bytes[14];
numColorPlanes = bytes[65];
bytesPerColorPlane = bytes[66];
horzSourceScreen = bytes[70];
vertSourceScreen = bytes[72];
startingPoint = 128;
}
void drawTexture(List bytes)
{
int currentPoint = startingPoint;
Debug.Log("BYTES: " + bytes);
Debug.Log("Size Calculation: " + ((bytes.Count - startingPoint) / 3) + " " + ((maxX / horzDPI) * (maxY / vertDPI)));
Texture2D imgTexture = new Texture2D(maxX + 1, maxY + 1, TextureFormat.RGB24, false);
for (int y = 0; y < maxY; y++)
{
for (int x = 0; x < maxX; x++)
{
if(currentPoint
Подробнее здесь: [url]https://stackoverflow.com/questions/78836583/read-pcx-file-byte-by-byte-and-apply-it-to-a-texture-in-unity-c-sharp[/url]