NetworkScene
A class in Root.Township, Alta.Networking.
The networked scene: holds the entity manager, global and void chunks, the spawner and the connections, and sends entity sync each frame. One per loaded scene, reached through NetworkSceneManager.Current.
- Listed in Networking and servers
- Inherits or implements
NetworkEntityParent,INetworkSceneInternal,INetworkScene,IEntityManager
Constructors
| Member | What it is |
|---|---|
NetworkScene() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
15 private and internal fields
| Member | What it is |
|---|---|
private AstarPath aStar | A* pathfinding prefab spawned on the server if none is active yet. |
private ConnectionChannel chunkSyncChannel | Backing field for ChunkSyncChannel, the connection channel for chunk and spawn sync. |
private ISocket clientSocket | The client socket, when this scene runs as a client. |
private EntityManager entityManager | Holds and registers every network entity in the scene. Made in FirstInitialize, disposed in OnDisable. |
private Chunk globalChunk | Backing field for GlobalChunk, the chunk for entities that belong everywhere. Force-loaded on server start. |
private bool isInitialized | Set once FirstInitialize has run. |
private SpawnArea respawnPoint | Backing field for the RespawnPoint spawn area. |
private static Logger sceneLogger | NLog logger for the scene. |
private SceneSerializer sceneSerializer | Batches and sends entity serialization. Made in FirstInitialize. |
private ConnectionChannel serializationChannel | Connection channel entity updates are sent on. |
private int serializationInterval | Used as a bit mask on the frame counter, so it should be a power of two. Default 2. |
private int serializeStep | Frame counter that Update uses to pick when to send. |
private ISocket serverSocket | The server socket, when this scene runs as a server. |
private Transform spawnPoint | Backing field for SpawnPoint. |
private Chunk voidChunk | Backing field for VoidChunk. Force-loaded on server start if set. |
Properties
| Member | What it is |
|---|---|
ConnectionChannel ChunkSyncChannel { get; } | The connection channel used to sync chunks. |
HashSet<Connection> Connections { get; } | Every player connection to this scene. |
float DecayMultiplier { get; } | The server setting's decay multiplier. |
Chunk GlobalChunk { get; } | The chunk loaded at all times. Force-loaded when the server starts. |
bool HasSaveFiles { get; } | True if the running server's settings have saving turned on. |
bool IsCustomizationEnabled { get; } | The server setting for whether customization is allowed. |
bool IsSimpleServer { get; set; } | True when the server target has the simple server flag. Set at server start. |
int LoadingCount { get; set; } | Count of things still loading, raised and lowered by cave generation. |
Transform PlayerFolder { get; private set; } | The transform players are put under. |
SpawnManager Spawner { get; private set; } | The spawn manager: the server or client version depending on the side. |
Transform SpawnPoint { get; } | Default spawn transform set in the scene. |
float SpawnRateMultiplier { get; } | The server setting's spawning rate multiplier. |
Chunk VoidChunk { get; } | A second always-loaded chunk, if the scene has one. |
2 private and internal properties
| Member | What it is |
|---|---|
private SpawnArea Alta.Networking.INetworkScene.RespawnPoint { get; } | The spawn area players respawn at. |
private SceneSerializer Alta.Networking.INetworkSceneInternal.SceneSerializer { get; } | The scene's serializer, which batches entity updates and sends them. |
Events
| Member | What it is |
|---|---|
event Action ServerStarted | Raised once the server side of the scene has finished starting. |
Methods
| Member | What it is |
|---|---|
NetworkEntity GetEntity(uint identifier) | Looks up a network entity by identifier. |
async Task Initialize(ISocket socket, Action<string> statusCallback) | Sets up the scene for the socket: server side loads the global and void chunks and raises ServerStarted. |
void PrintAllEnitityNames(Logger logger) | Writes a CSV of every entity to entity-details.csv in the persistent data folder. |
void PrintHealth(Logger logger) | Logs the entity manager's health check. |
void PrintPrefabsCount(Logger logger) | Writes a count of root entities per prefab to prefabs count.txt in the persistent data folder. |
14 private and internal methods
| Member | What it is |
|---|---|
private void Alta.Networking.INetworkSceneInternal.AddConnection(Connection connection) | Adds a connection to Connections and removes it again when it disconnects. |
private void Awake() | Only logs that the scene woke up. |
private void FirstInitialize(bool isServer) | Runs once: builds the chunk lookup from embedded location chunks, makes the entity manager and serializer, creates the Players folder and turns off embedded prefab components. |
private uint Alta.Networking.INetworkSceneInternal.ForceRegisterEntity(NetworkEntity entity) | Registers an entity with the entity manager, with a new identifier or a given one. |
private void Alta.Networking.INetworkSceneInternal.ForceRegisterEntity(NetworkEntity entity, uint identifier) | Registers an entity with the entity manager, with a new identifier or a given one. |
private void Alta.Networking.INetworkSceneInternal.HandleSync(uint embeddedIndex, uint identifier, uint[] embedded) | Client: syncs one embedded scene entity's identifier. After the last one, tells NetworkSceneManager the scene sync is done. |
private void InitializeAsClient() | Client: makes the client spawn manager. |
private async Task InitializeAsServer() | Server: makes the spawn manager and A* graph, force-loads the global and void chunks, registers and chunks embedded entities, then raises ServerStarted. |
private void Alta.Networking.Internal.IEntityManager.MarkSerialized(NetworkEntity entity, EntitySerializer serializer) | Hands an entity and its serializer to the entity manager to mark it as needing a sync. |
private void OnDisable() | Clears NetworkSceneManager.Current if it's this scene, resets the scene load wait and disposes the entity manager. |
private void RemoveConnection(Connection connection) | Removes a disconnected connection from Connections. |
private void SendSerialized(ISocket socket) | Sends the batched entity updates on a socket through the scene serializer. |
private void Alta.Networking.Internal.IEntityManager.SerializeAsClient(NetworkEntity entity) | Asks the entity manager to send a client-side update for an entity. |
private void Update() | Alternates frames between sending server and client entity updates, using serializationInterval as a bit mask. |
Used in
Members of other types that take, return or hold a NetworkScene: