Idle Connections
Summary
Shows how clients can tell the server to pause and resume sending them data. You could use this to stop syncing data to the client when the game window is not focused.
Description
ksBaseRoom has an IsIdle state that can be used to stop the server from sending updates to that client. Setting Room.IsIdle = true; will prevent the server from sending updates to the client. All entities and players will be destroyed locally when the server acknowledges the request to make the connection idle. Setting it back to true tells the server to resumse sending data to the client again. The first frame received after being idle will respawn all the entities and players and fire OnSpawnEntity/OnPlayerJoin events for them. The following script shows how to toggle the idle state when space is pressed.
using UnityEngine;
using KS.Reactor.Client.Unity;
public class crIdleToggle : ksRoomScript
{
// Called every frame.
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Room.IsIdle = !Room.IsIdle;
}
}
}Last updated

