Skip to main content

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.

Constructors​

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

Fields​

MemberWhat it is
static readonly Vector3 PositionMaxUpper bound for synced positions (2000 on each axis).
static readonly Vector3 PositionMinLower bound for synced positions (-2000 on each axis).
const float PositionPrecisionPrecision for synced positions (1 mm).
15 private and internal fields
MemberWhat it is
private AstarPath aStarA* pathfinding prefab spawned on the server if none is active yet.
private ConnectionChannel chunkSyncChannelBacking field for ChunkSyncChannel, the connection channel for chunk and spawn sync.
private ISocket clientSocketThe client socket, when this scene runs as a client.
private EntityManager entityManagerHolds and registers every network entity in the scene. Made in FirstInitialize, disposed in OnDisable.
private Chunk globalChunkBacking field for GlobalChunk, the chunk for entities that belong everywhere. Force-loaded on server start.
private bool isInitializedSet once FirstInitialize has run.
private SpawnArea respawnPointBacking field for the RespawnPoint spawn area.
private static Logger sceneLoggerNLog logger for the scene.
private SceneSerializer sceneSerializerBatches and sends entity serialization. Made in FirstInitialize.
private ConnectionChannel serializationChannelConnection channel entity updates are sent on.
private int serializationIntervalUsed as a bit mask on the frame counter, so it should be a power of two. Default 2.
private int serializeStepFrame counter that Update uses to pick when to send.
private ISocket serverSocketThe server socket, when this scene runs as a server.
private Transform spawnPointBacking field for SpawnPoint.
private Chunk voidChunkBacking field for VoidChunk. Force-loaded on server start if set.

Properties​

MemberWhat 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
MemberWhat 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​

MemberWhat it is
event Action ServerStartedRaised once the server side of the scene has finished starting.

Methods​

MemberWhat 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
MemberWhat 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: