Skip to content

Commit f8288ef

Browse files
committed
Added Vector2 and Vector4 read & write
1 parent 36b6ee4 commit f8288ef

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitStream.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,30 @@ public void WriteDoublePacked(double value)
334334
}
335335
}
336336

337+
/// <summary>
338+
/// Convenience method that writes two non-varint floats from the vector to the stream
339+
/// </summary>
340+
/// <param name="vector2">Vector to write</param>
341+
public void WriteVector2(Vector2 vector2)
342+
{
343+
WriteSingle(vector2.x);
344+
WriteSingle(vector2.y);
345+
}
346+
347+
/// <summary>
348+
/// Convenience method that writes two varint floats from the vector to the stream
349+
/// </summary>
350+
/// <param name="vector2">Vector to write</param>
351+
public void WriteVector2Packed(Vector2 vector2)
352+
{
353+
WriteSinglePacked(vector2.x);
354+
WriteSinglePacked(vector2.y);
355+
}
356+
337357
/// <summary>
338358
/// Convenience method that writes three non-varint floats from the vector to the stream
339359
/// </summary>
340-
/// <param name="vec">Vector to write</param>
360+
/// <param name="vector3">Vector to write</param>
341361
public void WriteVector3(Vector3 vector3)
342362
{
343363
WriteSingle(vector3.x);
@@ -348,14 +368,38 @@ public void WriteVector3(Vector3 vector3)
348368
/// <summary>
349369
/// Convenience method that writes three varint floats from the vector to the stream
350370
/// </summary>
351-
/// <param name="vec">Vector to write</param>
371+
/// <param name="vector3">Vector to write</param>
352372
public void WriteVector3Packed(Vector3 vector3)
353373
{
354374
WriteSinglePacked(vector3.x);
355375
WriteSinglePacked(vector3.y);
356376
WriteSinglePacked(vector3.z);
357377
}
358378

379+
/// <summary>
380+
/// Convenience method that writes four non-varint floats from the vector to the stream
381+
/// </summary>
382+
/// <param name="vector4">Vector to write</param>
383+
public void WriteVector4(Vector4 vector4)
384+
{
385+
WriteSingle(vector4.x);
386+
WriteSingle(vector4.y);
387+
WriteSingle(vector4.z);
388+
WriteSingle(vector4.w);
389+
}
390+
391+
/// <summary>
392+
/// Convenience method that writes four varint floats from the vector to the stream
393+
/// </summary>
394+
/// <param name="vector4">Vector to write</param>
395+
public void WriteVector4Packed(Vector4 vector4)
396+
{
397+
WriteSinglePacked(vector4.x);
398+
WriteSinglePacked(vector4.y);
399+
WriteSinglePacked(vector4.z);
400+
WriteSinglePacked(vector4.w);
401+
}
402+
359403
/// <summary>
360404
/// Write a single-precision floating point value to the stream. The value is between (inclusive) the minValue and maxValue.
361405
/// </summary>
@@ -469,6 +513,18 @@ public double ReadDoublePacked()
469513
}
470514
}
471515

516+
/// <summary>
517+
/// Read a Vector2 from the stream.
518+
/// </summary>
519+
/// <returns>The Vector2 read from the stream.</returns>
520+
public Vector2 ReadVector2() => new Vector2(ReadSingle(), ReadSingle());
521+
522+
/// <summary>
523+
/// Read a Vector2 from the stream.
524+
/// </summary>
525+
/// <returns>The Vector2 read from the stream.</returns>
526+
public Vector2 ReadVector2Packed() => new Vector2(ReadSinglePacked(), ReadSinglePacked());
527+
472528
/// <summary>
473529
/// Read a Vector3 from the stream.
474530
/// </summary>
@@ -481,6 +537,18 @@ public double ReadDoublePacked()
481537
/// <returns>The Vector3 read from the stream.</returns>
482538
public Vector3 ReadVector3Packed() => new Vector3(ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked());
483539

540+
/// <summary>
541+
/// Read a Vector4 from the stream.
542+
/// </summary>
543+
/// <returns>The Vector4 read from the stream.</returns>
544+
public Vector4 ReadVector4() => new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
545+
546+
/// <summary>
547+
/// Read a Vector4 from the stream.
548+
/// </summary>
549+
/// <returns>The Vector4 read from the stream.</returns>
550+
public Vector4 ReadVector4Packed() => new Vector4(ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked(), ReadSinglePacked());
551+
484552
/// <summary>
485553
/// Read a single-precision floating point value from the stream. The value is between (inclusive) the minValue and maxValue.
486554
/// </summary>

0 commit comments

Comments
 (0)