Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Tucker ChristianTucker

View GitHub Profile
View CharacterController.cs
public class CharacterController : MonoBehaviour
{
private ClientInputState inputState;
private Vector3 velocity = Vector3.zero;
private int simulationFrame;
private void Start()
{
NetworkClient.RegisterHandler<SimulationState>(OnServerSimulationStateReceived);
}
View SimulationState.cs
public class SimulationState : Message
{
public Vector3 position;
public Vector3 velocity;
public int simulationFrame;
}
View ClientInputState.cs
public class ClientInputState : Message
{
public List<KeyCode> keysPressed;
public List<KeyCode> keysDown;
public List<KeyCode> keysReleased;
public int simulationFrame;
}
View Psuedo networking example.cs
// Psuedo implementation to send data to a client.
NetworkServer.SendToClient(NetworkConnection connection, Message message);
// Psuedo implementation to send data to the server.
NetworkClient.Send(Message message);
// Psuedo implementation to register incoming message handlers.
NetworkClient.RegisterHandler<T>(Action<NetworkConnection, T> handler);
NetworkServer.RegisterHandler<T>(Action<NetworkConnection, T> handler);