// A "Voos Name" may be a 32-char GUID or just some string, like // __DEFAULT_BEHAVIOR__ public static string ReadVoosName(this NET.NetworkReader reader) { byte header = reader.ReadByte(); if (header == VN_EMPTY) { return(""); } if (header == VN_GUID) { // Guid byte[] bytes = new byte[16]; for (int i = 0; i < 16; i++) { bytes[i] = reader.ReadByte(); } return((new System.Guid(bytes)).ToString("N")); } else { Debug.Assert(header == VN_UTF16); return(reader.ReadUtf16()); } }
void InitNewPlayerRPC(byte[] zippedMetaBytes, byte[] zippedVoosBytes) { Util.Log($"InitNewPlayerRPC, {zippedMetaBytes.Length / 1024} KB zippedMetaBytes, {zippedVoosBytes.Length / 1024} KB zippedVoosBytes"); byte[] unzippedMetaBytes = Util.UnGZip(zippedMetaBytes); string payloadJson = Encoding.UTF8.GetString(unzippedMetaBytes, 0, unzippedMetaBytes.Length); NewPlayerInitPayload payload = JsonUtility.FromJson <NewPlayerInitPayload>(payloadJson); if (payload.version != NewPlayerInitPayload.CurrentVersion) { OnFatalError($"The game you're trying to join seems to be running an incompatible version of the game.\nQuit the game and make sure Steam has no pending updates."); return; } byte[] unzippedVoosBytes = Util.UnGZip(zippedVoosBytes); var voosReader = new UNET.NetworkReader(unzippedVoosBytes); behaviorSystem.LoadDatabaseForNetworkInit(payload.behaviorDatabase); voosEngine.DeserializePlayerInitV2(voosReader); sojoSystem.LoadDatabase(payload.sojoDatabase); stage.Load(payload.stage); receivedPlayerInitPayload = true; lastReceivedTerrainMeta = payload.terrainMeta; }
public static Color ReadColor(this UnityEngine.Networking.NetworkReader reader) { return(new Color( reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); }
public static Vector3 ReadVoosVector3(this UnityEngine.Networking.NetworkReader reader) { return(new Vector3( reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle() )); }
Cell ReadCell(UnityEngine.Networking.NetworkReader reader) { int x = reader.ReadByte() - cellArrayOffsetX; int y = reader.ReadByte() - cellArrayOffsetY; int z = reader.ReadByte() - cellArrayOffsetZ; Cell c = new Cell(x, y, z); return(c); }
public void TestUtf16Serialize() { byte[] buffer = new byte[100]; var writer = new UnityEngine.Networking.NetworkWriter(buffer); string sample = "japanese いろはに"; writer.WriteUtf16(sample); var reader = new UnityEngine.Networking.NetworkReader(buffer); string actual = reader.ReadUtf16(); Assert.AreEqual(sample, actual); }
// NOTE: Not thread-safe. public static string ReadUtf16(this UnityEngine.Networking.NetworkReader reader) { var builder = ReadUtf16Builder; builder.Clear(); ushort length = reader.ReadUInt16(); // TODO this could be more efficient..with ReadBytes or something. for (int i = 0; i < length; i++) { char c = (char)reader.ReadUInt16(); builder.Append(c); } return(builder.ToString()); }
void LoadLegacy(UnityEngine.Networking.NetworkReader reader) { int count = reader.ReadInt32(); Util.Log($"loading {count} legacy cells"); for (int i = 0; i < count; i++) { Cell c = new Cell(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); LegacyBlockInfo info = new LegacyBlockInfo(); info.SetData(reader.ReadByte()); CellValue block = new CellValue(info.GetBlockType(), info.GetBlockDirection(), BlockStyle.Stone); SetCell(block, c); Side westEdge = new Side(c.x, c.y, c.z, CellSide.West); SetSide(westEdge, info.WestWall(), BlockStyle.Stone); Side southEdge = new Side(c.x, c.y, c.z, CellSide.South); SetSide(southEdge, info.SouthWall(), BlockStyle.Stone); } }
public override void Deserialize(UnityEngine.Networking.NetworkReader reader) { base.Deserialize(reader); _actionInstruction = reader.ReadString(); }
public virtual void Deserialize(UnityEngine.Networking.NetworkReader reader) { _setId = reader.ReadInt32(); _currentVariantIndex = reader.ReadInt32(); _panelLabel = reader.ReadString(); }
protected override float DeserializeItem(NetworkReader reader) => reader.ReadSingle();
public static bool ReadVoosBoolean(this UnityEngine.Networking.NetworkReader reader) { return(reader.ReadByte() == 1); }
protected override string DeserializeItem(NetworkReader reader) { return(reader.ReadString()); }
protected override float DeserializeItem(NetworkReader reader) { return(reader.ReadSingle()); }
// De-serialize the contents of the reader into this message public virtual void Deserialize(NetworkReader reader) { }
public static Vector3 UnserializeVelocity2D(NetworkReader reader, CompressionSyncMode compression) { return(reader.ReadVector2()); }
public void Deserialize(byte[] cellBytes) { Clear(); // Util.Log($"loading terrain data of {cellBytes.Length} bytes"); var reader = new UnityEngine.Networking.NetworkReader(cellBytes); // Again - kinda awkward to have the deserialize code here. int version = reader.ReadInt32(); if (version == 0) { Util.LogWarning($"Ignoring terrain version 0"); } else if (version == 1) { LoadLegacy(reader); } else if (version == TerrainDatabase.CurrentVersion) { int blockCount = reader.ReadInt32(); // Util.Log($"reading {blockCount} blocks"); for (int i = 0; i < blockCount; i++) { TerrainDatabase.BlockInfo info = new TerrainDatabase.BlockInfo(); info.b0 = reader.ReadByte(); info.b1 = reader.ReadByte(); Cell c = ReadCell(reader); Debug.Assert(info.GetShape() != BlockShape.Empty); SetCell(info.ToBlock(), c); } System.Action <CellSide> LoadSideMap = (CellSide cellSide) => { int count = reader.ReadInt32(); // Util.Log($"Reading {count} {cellSide} walls"); for (int i = 0; i < count; i++) { TerrainDatabase.SideInfo info = new TerrainDatabase.SideInfo(); info.b0 = reader.ReadByte(); Cell c = ReadCell(reader); Side side = new Side { side = cellSide, x = c.x, y = c.y, z = c.z }; SetSide(side, true, info.GetStyle()); } }; LoadSideMap.Invoke(CellSide.South); LoadSideMap.Invoke(CellSide.West); Debug.Assert(reader.ReadByte() == 42, "End-of-buffer sanity check failed!"); } else { throw new System.Exception($"Given terrain of unknown version: {version}."); } }
private void UnserializeModeCharacterController(NetworkReader reader, bool initialState) { if (base.hasAuthority) { reader.ReadVector3(); if (syncRotationAxis != 0) { UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression); } return; } if (base.isServer && m_ClientMoveCallback3D != null) { Vector3 position = reader.ReadVector3(); Quaternion rotation = Quaternion.identity; if (syncRotationAxis != 0) { rotation = UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression); } if (m_CharacterController == null) { return; } Vector3 velocity = m_CharacterController.velocity; if (!m_ClientMoveCallback3D(ref position, ref velocity, ref rotation)) { return; } m_TargetSyncPosition = position; m_TargetSyncVelocity = velocity; if (syncRotationAxis != 0) { m_TargetSyncRotation3D = rotation; } } else { m_TargetSyncPosition = reader.ReadVector3(); if (syncRotationAxis != 0) { m_TargetSyncRotation3D = UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression); } } if (m_CharacterController == null) { return; } Vector3 a = m_TargetSyncPosition - base.transform.position; Vector3 a2 = a / GetNetworkSendInterval(); m_FixedPosDiff = a2 * Time.fixedDeltaTime; if (base.isServer && !base.isClient) { base.transform.position = m_TargetSyncPosition; base.transform.rotation = m_TargetSyncRotation3D; return; } if (GetNetworkSendInterval() == 0f) { base.transform.position = m_TargetSyncPosition; if (syncRotationAxis != 0) { base.transform.rotation = m_TargetSyncRotation3D; } return; } float magnitude = (base.transform.position - m_TargetSyncPosition).magnitude; if (magnitude > snapThreshold) { base.transform.position = m_TargetSyncPosition; } if (interpolateRotation == 0f && syncRotationAxis != 0) { base.transform.rotation = m_TargetSyncRotation3D; } if (m_InterpolateMovement == 0f) { base.transform.position = m_TargetSyncPosition; } if (initialState && syncRotationAxis != 0) { base.transform.rotation = m_TargetSyncRotation3D; } }
private void UnserializeMode2D(NetworkReader reader, bool initialState) { if (base.hasAuthority) { reader.ReadVector2(); reader.ReadVector2(); if (syncRotationAxis != 0) { UnserializeRotation2D(reader, rotationSyncCompression); } if (syncSpin) { UnserializeSpin2D(reader, rotationSyncCompression); } } else { if (m_RigidBody2D == null) { return; } if (base.isServer && m_ClientMoveCallback2D != null) { Vector2 position = reader.ReadVector2(); Vector2 velocity = reader.ReadVector2(); float rotation = 0f; if (syncRotationAxis != 0) { rotation = UnserializeRotation2D(reader, rotationSyncCompression); } if (!m_ClientMoveCallback2D(ref position, ref velocity, ref rotation)) { return; } m_TargetSyncPosition = position; m_TargetSyncVelocity = velocity; if (syncRotationAxis != 0) { m_TargetSyncRotation2D = rotation; } } else { m_TargetSyncPosition = reader.ReadVector2(); m_TargetSyncVelocity = reader.ReadVector2(); if (syncRotationAxis != 0) { m_TargetSyncRotation2D = UnserializeRotation2D(reader, rotationSyncCompression); } } if (syncSpin) { m_TargetSyncAngularVelocity2D = UnserializeSpin2D(reader, rotationSyncCompression); } if (base.isServer && !base.isClient) { base.transform.position = m_TargetSyncPosition; m_RigidBody2D.MoveRotation(m_TargetSyncRotation2D); m_RigidBody2D.velocity = m_TargetSyncVelocity; return; } if (GetNetworkSendInterval() == 0f) { base.transform.position = m_TargetSyncPosition; m_RigidBody2D.velocity = m_TargetSyncVelocity; if (syncRotationAxis != 0) { m_RigidBody2D.MoveRotation(m_TargetSyncRotation2D); } if (syncSpin) { m_RigidBody2D.angularVelocity = m_TargetSyncAngularVelocity2D; } return; } float magnitude = (m_RigidBody2D.position - (Vector2)m_TargetSyncPosition).magnitude; if (magnitude > snapThreshold) { m_RigidBody2D.position = m_TargetSyncPosition; m_RigidBody2D.velocity = m_TargetSyncVelocity; } if (interpolateRotation == 0f && syncRotationAxis != 0) { m_RigidBody2D.rotation = m_TargetSyncRotation2D; if (syncSpin) { m_RigidBody2D.angularVelocity = m_TargetSyncAngularVelocity2D; } } if (m_InterpolateMovement == 0f) { m_RigidBody2D.position = m_TargetSyncPosition; } if (initialState) { m_RigidBody2D.rotation = m_TargetSyncRotation2D; } } }
private void UnserializeMode3D(NetworkReader reader, bool initialState) { if (base.hasAuthority) { reader.ReadVector3(); reader.ReadVector3(); if (syncRotationAxis != 0) { UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression); } if (syncSpin) { UnserializeSpin3D(reader, syncRotationAxis, rotationSyncCompression); } return; } if (base.isServer && m_ClientMoveCallback3D != null) { Vector3 position = reader.ReadVector3(); Vector3 velocity = reader.ReadVector3(); Quaternion rotation = Quaternion.identity; if (syncRotationAxis != 0) { rotation = UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression); } if (!m_ClientMoveCallback3D(ref position, ref velocity, ref rotation)) { return; } m_TargetSyncPosition = position; m_TargetSyncVelocity = velocity; if (syncRotationAxis != 0) { m_TargetSyncRotation3D = rotation; } } else { m_TargetSyncPosition = reader.ReadVector3(); m_TargetSyncVelocity = reader.ReadVector3(); if (syncRotationAxis != 0) { m_TargetSyncRotation3D = UnserializeRotation3D(reader, syncRotationAxis, rotationSyncCompression); } } if (syncSpin) { m_TargetSyncAngularVelocity3D = UnserializeSpin3D(reader, syncRotationAxis, rotationSyncCompression); } if (m_RigidBody3D == null) { return; } if (base.isServer && !base.isClient) { m_RigidBody3D.MovePosition(m_TargetSyncPosition); m_RigidBody3D.MoveRotation(m_TargetSyncRotation3D); m_RigidBody3D.velocity = m_TargetSyncVelocity; return; } if (GetNetworkSendInterval() == 0f) { m_RigidBody3D.MovePosition(m_TargetSyncPosition); m_RigidBody3D.velocity = m_TargetSyncVelocity; if (syncRotationAxis != 0) { m_RigidBody3D.MoveRotation(m_TargetSyncRotation3D); } if (syncSpin) { m_RigidBody3D.angularVelocity = m_TargetSyncAngularVelocity3D; } return; } float magnitude = (m_RigidBody3D.position - m_TargetSyncPosition).magnitude; if (magnitude > snapThreshold) { m_RigidBody3D.position = m_TargetSyncPosition; m_RigidBody3D.velocity = m_TargetSyncVelocity; } if (interpolateRotation == 0f && syncRotationAxis != 0) { m_RigidBody3D.rotation = m_TargetSyncRotation3D; if (syncSpin) { m_RigidBody3D.angularVelocity = m_TargetSyncAngularVelocity3D; } } if (m_InterpolateMovement == 0f) { m_RigidBody3D.position = m_TargetSyncPosition; } if (initialState && syncRotationAxis != 0) { m_RigidBody3D.rotation = m_TargetSyncRotation3D; } }
public static float UnserializeSpin2D(NetworkReader reader, CompressionSyncMode compression) { return(ReadAngle(reader, compression)); }
public override void Deserialize(UnityEngine.Networking.NetworkReader reader) { slotId = reader.ReadByte(); loadedState = reader.ReadBoolean(); }
protected void HandleBytes(byte[] buffer, int receivedSize, int channelId) { NetworkReader reader = new NetworkReader(buffer); HandleReader(reader, receivedSize, channelId); }