Files
EndlessHostRoles/Modules/Extensions/HazelExtensions.cs
T
2025-02-06 18:28:52 +01:00

55 lines
1.6 KiB
C#

using Hazel;
using UnityEngine;
namespace EHR;
public static class HazelExtensions
{
// -------------------------------------------------------------------------------------------------------------------------
public static SendOption SendOption => GameStates.CurrentServerType == GameStates.ServerType.Vanilla ? SendOption.None : SendOption.Reliable;
public static void Write(this MessageWriter writer, Vector2 vector)
{
NetHelpers.WriteVector2(vector, writer);
}
public static void Write(this MessageWriter writer, Vector3 vector)
{
writer.Write(vector.x);
writer.Write(vector.y);
writer.Write(vector.z);
}
public static void Write(this MessageWriter writer, Color color)
{
writer.Write(color.r);
writer.Write(color.g);
writer.Write(color.b);
writer.Write(color.a);
}
// -------------------------------------------------------------------------------------------------------------------------
public static Vector2 ReadVector2(this MessageReader reader)
{
return NetHelpers.ReadVector2(reader);
}
public static Vector3 ReadVector3(this MessageReader reader)
{
float x = reader.ReadSingle();
float y = reader.ReadSingle();
float z = reader.ReadSingle();
return new(x, y, z);
}
public static Color ReadColor(this MessageReader reader)
{
float r = reader.ReadSingle();
float g = reader.ReadSingle();
float b = reader.ReadSingle();
float a = reader.ReadSingle();
return new(r, g, b, a);
}
}