void LateUpdate() { _ws.ProcessMessageQueue(this); if (_ws.ConnectionState == ClientState.Connected) { if (Time.time - _timeSinceLastSend > SendInterval) { _timeSinceLastSend = Time.time; QuantizedVector3 qPosition = BoundedRange.Quantize(_modelTransform.position, Constants.WORLD_BOUNDS); QuantizedQuaternion qRotation = SmallestThree.Quantize(_modelTransform.rotation); ushort qBestTime = HalfPrecision.Quantize(GameTimer.BestTime); _bitBuffer.Clear(); _bitBuffer.AddUInt(qPosition.x) .AddUInt(qPosition.y) .AddUInt(qPosition.z) .AddUInt(qRotation.m) .AddUInt(qRotation.a) .AddUInt(qRotation.b) .AddUInt(qRotation.c) .AddUShort(qBestTime) .ToArray(_byteBuffer); _ws.Send(new ArraySegment <byte>(_byteBuffer, 0, 28)); } } }
private void WebClientOnonConnect() { Debug.Log("Client connected"); _wasConnected = true; // Hide the connect screen ConnectUIController.HideConnectScreen(); // Setup your own nametag LocalPlayerTransform.GetComponent <Nametag>().SetName(ConnectUIController.DisplayName); // Send server your name and potentially some character customization stuff _bitBuffer.Clear(); _bitBuffer.AddByte(8); _bitBuffer.AddString(ConnectUIController.DisplayName); _bitBuffer.ToArray(_buffer); _webClient.Send(new ArraySegment <byte>(_buffer, 0, 22)); }
private void Update() { client?.ProcessMessageQueue(); if (keepAlive < Time.time) { client?.Send(new ArraySegment <byte>(new byte[1] { 0 })); keepAlive = Time.time + 1; } }
void OnData(ArraySegment <byte> data) { Debug.Log($"Data from Server, length:{data.Count}"); if (echo) { if (client is WebSocketClientStandAlone standAlone) { standAlone.Send(data); } else { client.Send(data); } } }