Skip to content

Commit d629244

Browse files
committed
Added color read & write methods
1 parent 4cad635 commit d629244

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitStream.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,42 @@ public void WriteDoublePacked(double value)
334334
}
335335
}
336336

337+
/// <summary>
338+
/// Convenience method that writes four non-varint floats from the color to the stream
339+
/// </summary>
340+
/// <param name="color">Color to write</param>
341+
public void WriteColor(Color color)
342+
{
343+
WriteSingle(color.r);
344+
WriteSingle(color.g);
345+
WriteSingle(color.b);
346+
WriteSingle(color.a);
347+
}
348+
349+
/// <summary>
350+
/// Convenience method that writes four varint floats from the color to the stream
351+
/// </summary>
352+
/// <param name="color">Color to write</param>
353+
public void WriteColorPacked(Color color)
354+
{
355+
WriteSinglePacked(color.r);
356+
WriteSinglePacked(color.g);
357+
WriteSinglePacked(color.b);
358+
WriteSinglePacked(color.a);
359+
}
360+
361+
/// <summary>
362+
/// Convenience method that writes four non-varint floats from the color to the stream
363+
/// </summary>
364+
/// <param name="color32">Color32 to write</param>
365+
public void WriteColor32(Color32 color32)
366+
{
367+
WriteSingle(color32.r);
368+
WriteSingle(color32.g);
369+
WriteSingle(color32.b);
370+
WriteSingle(color32.a);
371+
}
372+
337373
/// <summary>
338374
/// Convenience method that writes two non-varint floats from the vector to the stream
339375
/// </summary>
@@ -549,6 +585,24 @@ public double ReadDoublePacked()
549585
/// <returns>The Vector4 read from the stream.</returns>
550586
public Vector4 ReadVector4Packed() => new Vector4(ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked());
551587

588+
/// <summary>
589+
/// Read a Color from the stream.
590+
/// </summary>
591+
/// <returns>The Color read from the stream.</returns>
592+
public Color ReadColor() => new Color(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
593+
594+
/// <summary>
595+
/// Read a Color from the stream.
596+
/// </summary>
597+
/// <returns>The Color read from the stream.</returns>
598+
public Color ReadColorPacked() => new Color(ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked());
599+
600+
/// <summary>
601+
/// Read a Color32 from the stream.
602+
/// </summary>
603+
/// <returns>The Color32 read from the stream.</returns>
604+
public Color32 ReadColor32() => new Color32((byte)ReadByte(), (byte)ReadByte(), (byte)ReadByte(), (byte)ReadByte());
605+
552606
/// <summary>
553607
/// Read a single-precision floating point value from the stream. The value is between (inclusive) the minValue and maxValue.
554608
/// </summary>

0 commit comments

Comments
 (0)