I am creating a pathfinding system that I want to work with my Multiplayer game. I am using Mirror to handle networking. I created a custom Reader/Writer class so that I can send my custom type (OverlayTile) to my server.. If I don't create that custom Reader/Writer class, I get: Use a supported type or use a custom reader (At OverlayTile). .. I did create a custom Reader and Writer (I'll share below), but my question is: My OverlayTile class has a field OverlayTile previous .. I am not sure how to go about adding support for this field that references itself. The other properties have something like reader.readInt() but how could I do something similar like this for my OverlayTile type?
I have a class called OverlayTile which looks like this:
public class OverlayTile : MonoBehaviour
{
public int G;
public int H;
public int F { get { return G + H; } }
public bool isBlocked;
public OverlayTile previous;
public Vector3Int gridLocation;
}
My Reader/Writer class looks like this:
public static class OverlayTileReaderWriter
{
public static void writeOverlayTile(this NetworkWriter writer, OverlayTile overlayTile)
{
writer.WriteInt(overlayTile.F);
writer.WriteInt(overlayTile.G);
writer.WriteInt(overlayTile.H);
writer.WriteBool(overlayTile.isBlocked);
writer.WriteVector3Int(overlayTile.gridLocation);
}
public static OverlayTile readOverlayTile(this NetworkReader reader)
{
return new OverlayTile
{
G = reader.ReadInt(),
H = reader.ReadInt(),
isBlocked = reader.ReadBool(),
gridLocation = reader.ReadVector3Int(),
// previous = overlayTile.GetComponent<OverlayTile>() ??
};
}
}