Skip to content

Commit

Permalink
feat: Add weaver support for Vector2Int and Vector3Int (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Mar 24, 2019
1 parent 7836433 commit e2a6ce9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/Mirror/Editor/Weaver/Weaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class Weaver
public static TypeReference vector2Type;
public static TypeReference vector3Type;
public static TypeReference vector4Type;
public static TypeReference vector2IntType;
public static TypeReference vector3IntType;
public static TypeReference colorType;
public static TypeReference color32Type;
public static TypeReference quaternionType;
Expand Down Expand Up @@ -1014,6 +1016,8 @@ static void SetupUnityTypes()
vector2Type = UnityAssembly.MainModule.GetType("UnityEngine.Vector2");
vector3Type = UnityAssembly.MainModule.GetType("UnityEngine.Vector3");
vector4Type = UnityAssembly.MainModule.GetType("UnityEngine.Vector4");
vector2IntType = UnityAssembly.MainModule.GetType("UnityEngine.Vector2Int");
vector3IntType = UnityAssembly.MainModule.GetType("UnityEngine.Vector3Int");
colorType = UnityAssembly.MainModule.GetType("UnityEngine.Color");
color32Type = UnityAssembly.MainModule.GetType("UnityEngine.Color32");
quaternionType = UnityAssembly.MainModule.GetType("UnityEngine.Quaternion");
Expand Down Expand Up @@ -1187,6 +1191,8 @@ static void SetupReadFunctions()
{ vector2Type.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadVector2") },
{ vector3Type.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadVector3") },
{ vector4Type.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadVector4") },
{ vector2IntType.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadVector2Int") },
{ vector3IntType.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadVector3Int") },
{ colorType.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadColor") },
{ color32Type.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadColor32") },
{ quaternionType.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadQuaternion") },
Expand Down Expand Up @@ -1223,6 +1229,8 @@ static void SetupWriteFunctions()
{ vector2Type.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", vector2Type) },
{ vector3Type.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", vector3Type) },
{ vector4Type.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", vector4Type) },
{ vector2IntType.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", vector2IntType) },
{ vector3IntType.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", vector3IntType) },
{ colorType.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", colorType) },
{ color32Type.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", color32Type) },
{ quaternionType.FullName, Resolvers.ResolveMethodWithArg(NetworkWriterType, CurrentAssembly, "Write", quaternionType) },
Expand Down
10 changes: 10 additions & 0 deletions Assets/Mirror/Runtime/NetworkReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ public Vector4 ReadVector4()
return new Vector4(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
}

public Vector2Int ReadVector2Int()
{
return new Vector2Int((int)ReadPackedUInt32(), (int)ReadPackedUInt32());
}

public Vector3Int ReadVector3Int()
{
return new Vector3Int((int)ReadPackedUInt32(), (int)ReadPackedUInt32(), (int)ReadPackedUInt32());
}

public Color ReadColor()
{
return new Color(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
Expand Down
13 changes: 13 additions & 0 deletions Assets/Mirror/Runtime/NetworkWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ public void Write(Vector4 value)
Write(value.w);
}

public void Write(Vector2Int value)
{
WritePackedUInt32((uint)value.x);
WritePackedUInt32((uint)value.y);
}

public void Write(Vector3Int value)
{
WritePackedUInt32((uint)value.x);
WritePackedUInt32((uint)value.y);
WritePackedUInt32((uint)value.z);
}

public void Write(Color value)
{
Write(value.r);
Expand Down

0 comments on commit e2a6ce9

Please sign in to comment.