GhostManager
public class DistanceToThisNetworkEntity
{
public sfloat distance;
public byte[] bytes;
public int byteSizeToStore;
public NetworkEntity entity;
}
public class GhostManager : MonoBehaviour
{
public int maxPacketByteSize = 1300;
public int maxSnapShotsSize = 180;
//each entry in the list holds a dictionary of snapshots per playerid
public List<Dictionary<int, SnapShot>> snapshots = new List<Dictionary<int, SnapShot>>();
public int mostRecentStoredGameTick = -1;
//...
The ghost manager is an optional class that helps in working out what data to send Clients if there is a lot of entities to manage on the Server. The server needs to send SnapShots to the Client so they can sync their worlds up, these SnapShots are made up of data from NetworkEntities and ideally all of this data fits into 1 UDP packet as needing multiple packets to describe a snapshot can cause higher packet loss or other issues. So the ghost manager builds custom snapshot packets per client, packing as much as it can into a single UDP packet based on distance and ignoring the excess.
The idea is that if the world is full of entities, then a client can probably only see a small subset or the closest are the only immediately important ones, whereas ones further out can be ignored. If your game is small on entities and data, then the ghost manager is not needed.
The current example includes the Ghost Manager and you can easily test the effects of it by finding the Glob Spawners on the level and increasing the max number they can spawn to really high and seeing what that looks like for a client when they all group together.
Methods
public void SavePlayerSnapShots(int gameTick, NetworkEntityManager networkEntityManager)
Starts the process of looping through all connected clients and saving unique snapshot packets for each of them by calling SaveWorldSnapShot on each.
public SnapShot SaveWorldSnapShot(PlayerConnection pc, int gameTick, NetworkEntityManager networkEntityManager)
Creates a SnapShot for a specific player packing as much data as it can about the closest entities to them that can fit into a single packet
public SnapShot GetMostRecentPlayerSnapShotStored(int pcID)
Retrieves a SnapShot stored in the ghost managers snapshots dictionary for a specific player based on PlayerID