Skip to main content

FarAwayController

A class in Root.Township, the global namespace.

Shows markers for nearby players whose player controllers a client has not loaded. On a simple server it sends each player the chunk and head position of the other players within range; clients draw a marker prefab at those spots.

Constructors​

MemberWhat it is
FarAwayController()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

9 private and internal fields
MemberWhat it is
private List<Transform> activeMarkersClient: marker transforms currently shown.
private GameObject farawayMarkerPrefabPrefab spawned for each far-away player marker.
private bool isSendingServer: whether the next update frame sends or prepares.
private Stack<GameObject> markerPoolClient: hidden marker objects kept for reuse.
private float maxDistanceToSendSquaredSquared distance within which another player is sent to a client. Default 400 (20 m).
private Dictionary<IPlayer, FarAwayController.PlayerTuple> preparedDataServer: per-player tracking data and close-by lists. Only created on a simple server.
private MethodSync syncPlayerMethod sync on SyncE used to send the close-by lists.
private IUnityUpdateMethod updateHandle of the registered update method, Render on clients or UpdateSend on the server.
private List<FarAwayController.PlayerData> workingListServer: all tracked players' data. Client: the positions last received.

Methods​

MemberWhat it is
override void Initialize()Creates the syncPlayer method sync and, on a non-headless client, registers Render for updates.
override void InitializeAsServer(SpawnData spawnData)Server: on a simple server, creates preparedData and registers UpdateSend for updates.
override void OnConnected(Player player)Server: starts tracking the joining player's head position.
override void OnDisconnected(Player player)Server: stops tracking the leaving player.
6 private and internal methods
MemberWhat it is
private void OnDestroy()Deregisters the update method.
private void Prepare()Server: refreshes every tracked player's position, then fills each player's list of others within maxDistanceToSendSquared.
private void Render()Client: places a marker at each received position whose player has no loaded controller, pooling unused markers.
private void Send()Server: sends each connected player their prepared close-by list.
private void SyncPlayer(IPlayer player, Stream stream)Writes a player's close-by list (up to 16 entries) on the server and reads it into workingList on the client.
private void UpdateSend()Server: alternates frames between Prepare and Send.