2using System.Collections;
3using System.Collections.Generic;
10using NaughtyAttributes;
23 [SerializeField]
private float lastMessage = 0.0f;
25 private byte[] sendByteArray =
new byte[4096];
26 private readonly
object lockobject =
new object();
31 Dispatcher.CheckInstance();
33 ws = WebSocketFactory.CreateInstance($
"ws://{hostIP}:{Port}/sync");
38 Debug.Log(
"WS connected!");
40 Dispatcher.InvokeAsync(
42 new ContextualizedAction(
46 lastMessage = Time.time;
49 ws.
Send(sendByteArray);
59 Debug.Log(
"WS client received message: " + Encoding.UTF8.GetString(msg));
61 Dispatcher.InvokeAsync(
63 new ContextualizedAction(
67 lastMessage = Time.time;
69 ws.
Send(sendByteArray);
78 ws.
OnError += (
string errMsg) =>
80 Debug.Log(
"WS error: " + errMsg);
86 Debug.Log(
"WS closed with code: " + code.ToString());
89 Dispatcher.InvokeAsync(
91 new ContextualizedAction(
114 private void OnDestroy()
125 var allsyncedobjects = FindObjectsOfType<SyncThis>();
126 foreach (var syncedobject
in allsyncedobjects)
142 private void FixedUpdate()
150 ws.
Send(sendByteArray);
164 private void CreateSendPacket()
170 sendByteArray[offset] = (byte) go.name.Length;
172 foreach (var c in go.name)
174 sendByteArray[offset] = (byte)c;
178 CopyVector3ToByteArray(ref sendByteArray, ref offset, go.transform.localPosition);
179 CopyVector3ToByteArray(ref sendByteArray, ref offset, go.transform.localEulerAngles);
181 #region BiztosLehetneSzebben
223 private void CopyVector3ToByteArray(ref
byte[] array, ref
int arrayOffset, Vector3 value)
225 Buffer.BlockCopy( BitConverter.GetBytes( value.x ), 0, array, arrayOffset , 4 );
226 Buffer.BlockCopy( BitConverter.GetBytes( value.y ), 0, array, arrayOffset + 4, 4 );
227 Buffer.BlockCopy( BitConverter.GetBytes( value.z ), 0, array, arrayOffset + 8, 4 );
237 ws.
Send(
"dummy thicc");
UnityEngine.UI.Button Button
void Send(byte[] data)
Send binary data over the socket.
WebSocketMessageEventHandler OnMessage
Occurs when a message is received.
WebSocketErrorEventHandler OnError
Occurs when an error was reported from WebSocket.
WebSocketOpenEventHandler OnOpen
Occurs when the connection is opened.
bool Ping()
Trys to ping the host.
void Connect()
Open WebSocket connection
void Close(WebSocketCloseCode code=WebSocketCloseCode.Normal, string reason=null)
Close WebSocket connection with optional status code and reason.
WebSocketCloseEventHandler OnClose
Occurs when the socked was closed.
WebSocketState GetState()
Return WebSocket connection state.
List< GameObject > syncObjects
WebSocketCloseCode
Web socket close codes.
WebSocketState
Enum representing WebSocket connection state