Skip to content

Instantly share code, notes, and snippets.

View ChristianTucker's full-sized avatar

Christian Tucker ChristianTucker

View GitHub Profile
public class CharacterController : MonoBehaviour
{
private ClientInputState inputState;
private Vector3 velocity = Vector3.zero;
private int simulationFrame;
private void Start()
{
NetworkClient.RegisterHandler<SimulationState>(OnServerSimulationStateReceived);
}
public class SimulationState : Message
{
public Vector3 position;
public Vector3 velocity;
public int simulationFrame;
}
public class ClientInputState : Message
{
public List<KeyCode> keysPressed;
public List<KeyCode> keysDown;
public List<KeyCode> keysReleased;
public int simulationFrame;
}
// 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);