/// <summary> /// Returns a base64 encoded version of the config /// </summary> /// <returns></returns> public string ToBase64() { NetworkConfig config = this; using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteString(config.protocalVersion); writer.WriteInt32Packed(config.receiveTickrate); writer.WriteInt32Packed(config.maxReceiveEventsPerTickRate); writer.WriteInt32Packed(config.eventTickrate); writer.WriteInt32Packed(config.clientConnectionBufferTimeout); writer.WriteInt32Packed(config.secondsHistory); writer.WriteBool(config.enableTimeResync); writer.WriteBool(config.ensureNetworkedVarLengthSafety); writer.WriteBits((byte)config.rpcHashSize, 3); writer.WriteBool(recycleNetworkIDs); writer.WriteSinglePacked(networkIDRecycleDelay); writer.WriteBool(enableNetworkedVar); writer.WriteBool(clientSendSceneEvents); writer.WriteBool(serverSendSceneEvents); stream.PadStream(); return Convert.ToBase64String(stream.ToArray()); } } }
/// <summary> /// Sends the named message /// </summary> /// <param name="name">The message name to send</param> /// <param name="clientIds">The clients to send to, sends to everyone if null</param> /// <param name="stream">The message stream containing the data</param> /// <param name="channel">The channel to send the data on</param> /// <param name="security">The security settings to apply to the message</param> public static void SendNamedMessage(string name, List <ulong> clientIds, Stream stream, string channel = null, SecuritySendFlags security = SecuritySendFlags.None) { ulong hash = NetworkedBehaviour.HashMethodName(name); using (PooledBitStream messageStream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(messageStream)) { writer.WriteUInt64Packed(hash); } messageStream.CopyFrom(stream); if (!NetworkingManager.Singleton.IsServer) { if (NetworkLog.CurrentLogLevel <= LogLevel.Error) { NetworkLog.LogWarning("Can not send named messages to multiple users as a client"); } return; } InternalMessageSender.Send(MLAPIConstants.MLAPI_NAMED_MESSAGE, string.IsNullOrEmpty(channel) ? "MLAPI_DEFAULT_MESSAGE" : channel, clientIds, messageStream, security, null); } }
/// <summary> /// Gets a SHA256 hash of parts of the NetworkingConfiguration instance /// </summary> /// <param name="cache"></param> /// <returns></returns> public ulong GetConfig(bool cache = true) { if (ConfigHash != null && cache) return ConfigHash.Value; using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteString(protocalVersion); writer.WriteBool(enableNetworkedVar); writer.WriteBool(ensureNetworkedVarLengthSafety); writer.WriteBits((byte)rpcHashSize, 3); stream.PadStream(); if (cache) { ConfigHash = stream.ToArray().GetStableHash64(); return ConfigHash.Value; } return stream.ToArray().GetStableHash64(); } } }
/// <summary> /// Hides a object from a specific client /// </summary> /// <param name="clientId">The client to hide the object for</param> public void NetworkHide(ulong clientId) { if (!IsSpawned) { throw new SpawnStateException("Object is not spawned"); } if (!NetworkingManager.Singleton.IsServer) { throw new NotServerException("Only server can change visibility"); } if (observers.Contains(clientId) && clientId != NetworkingManager.Singleton.ServerClientId) { // Send destroy call observers.Remove(clientId); using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt64Packed(NetworkId); InternalMessageSender.Send(MLAPIConstants.MLAPI_DESTROY_OBJECT, "MLAPI_INTERNAL", stream, SecuritySendFlags.None, null); } } } }
private void OnLog(string condition, string stackTrace, LogType logType) { //DO NOT CALL Debug.Log in this function or it will cause an infinite loop! //Wait until this network is ready to log. if (!sendLogEvents || !networkManager.isRunning || (!networkManager.isServer && !networkManager.isConnected)) { return; } using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteString(condition); writer.WriteBool(includeStacktrace); if (includeStacktrace) { writer.WriteString(stackTrace); } writer.WriteByte((byte)logType); if (networkManager.isServer) { //Send to all clients that are expecting it. MessageSender.SendToSpecific(m_ClientsReceivingLogEvents, networkLogMessageType, "NETWORK_INTERNAL", stream); } else { //Send to server MessageSender.Send(networkManager.serverID, networkLogMessageType, networkManager.networkInternalChannel, stream); } } } }
public void Write(Stream stream) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteInt32Packed(TeamID); writer.WriteBool(isRightHanded); writer.WriteBool(isMoving); writer.WriteBool(isSprinting); writer.WriteBool(isDribbling); writer.WriteBool(isScreening); writer.WriteBool(isHardScreening); writer.WriteBool(isShooting); writer.WriteBool(isHelping); writer.WriteBool(isMovementFrozen); writer.WriteBool(isBallInLeftHand); writer.WriteBool(isCtrlDown); writer.WriteBool(isAltDown); writer.WriteBool(isDribUp); writer.WriteBool(isDribDown); writer.WriteBool(isDribLeft); writer.WriteBool(isDribRight); writer.WriteBool(isAI); writer.WriteVector3Packed(m_target); } }
// this happens after approval (96% sure :p) private void ML_OnClientConnected(ulong _clientId) { if (!NetworkingManager.Singleton.IsHost && !NetworkingManager.Singleton.IsServer) { return; } Debug.Log("Client " + _clientId + " connected"); NetworkedClient client = NetworkingManager.Singleton.ConnectedClients[_clientId]; Player player = client.GetPlayer(); player.ClientId.Value = _clientId; player.Name.Value = connectionDataCache[_clientId].playerName; connectionDataCache.Remove(_clientId); using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter w = PooledBitWriter.Get(stream)) { w.WriteUInt64(player.NetworkedObject.NetworkId); CustomMessagingManager.SendNamedMessage("ClientConnected", AllClientIDs(), stream); } } }
/// <summary> /// Spawns a object from the pool at a given position and rotation. Can only be called from server. /// </summary> /// <param name="poolName">The name of the pool</param> /// <param name="position">The position to spawn the object at</param> /// <param name="rotation">The rotation to spawn the object at</param> /// <returns></returns> public static NetworkedObject SpawnPoolObject(string poolName, Vector3 position, Quaternion rotation) { if (!NetworkingManager.singleton.isServer) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("Object spawning can only occur on server"); } return(null); } NetworkedObject netObject = Pools[PoolNamesToIndexes[poolName]].SpawnObject(position, rotation); using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt32Packed(netObject.NetworkId); writer.WriteSinglePacked(position.x); writer.WriteSinglePacked(position.y); writer.WriteSinglePacked(position.z); writer.WriteSinglePacked(rotation.eulerAngles.x); writer.WriteSinglePacked(rotation.eulerAngles.y); writer.WriteSinglePacked(rotation.eulerAngles.z); InternalMessageHandler.Send(MLAPIConstants.MLAPI_SPAWN_POOL_OBJECT, "MLAPI_INTERNAL", stream); } } return(netObject); }
/// <inheritdoc /> public void WriteDelta(Stream stream) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt16Packed((ushort)dirtyEvents.Count); for (int i = 0; i < dirtyEvents.Count; i++) { writer.WriteBits((byte)dirtyEvents[i].eventType, 2); switch (dirtyEvents[i].eventType) { case NetworkedSetEvent <T> .EventType.Add: { writer.WriteObjectPacked(dirtyEvents[i].value); //BOX } break; case NetworkedSetEvent <T> .EventType.Remove: { writer.WriteObjectPacked(dirtyEvents[i].value); //BOX } break; case NetworkedSetEvent <T> .EventType.Clear: { //Nothing has to be written } break; } } } }
internal static void Send(uint clientId, byte messageType, string channelName, Stream messageStream, bool skipQueue = false) { if (NetworkingManager.singleton.isServer && clientId == NetworkingManager.singleton.ServerClientId) { return; } using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteByte(messageType); stream.CopyFrom(messageStream); NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); byte error; if (skipQueue) { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(clientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], true, out error); } else { netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(clientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); } } }
internal static void Send(byte messageType, string channelName, uint clientIdToIgnore, Stream messageStream) { using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteByte(messageType); stream.CopyFrom(messageStream); NetworkProfiler.StartEvent(TickType.Send, (uint)stream.Length, channelName, MLAPIConstants.MESSAGE_NAMES[messageType]); for (int i = 0; i < netManager.ConnectedClientsList.Count; i++) { if (netManager.ConnectedClientsList[i].ClientId == clientIdToIgnore || (NetworkingManager.singleton.isServer && netManager.ConnectedClientsList[i].ClientId == NetworkingManager.singleton.ServerClientId)) { continue; } byte error; netManager.NetworkConfig.NetworkTransport.QueueMessageForSending(netManager.ConnectedClientsList[i].ClientId, stream.GetBuffer(), (int)stream.Length, MessageManager.channels[channelName], false, out error); } NetworkProfiler.EndEvent(); } } }
private static void LogServer(string message, LogType logType) { // Get the sender of the local log ulong localId = NetworkingManager.Singleton != null ? NetworkingManager.Singleton.LocalClientId : 0; switch (logType) { case LogType.Info: LogInfoServerLocal(message, localId); break; case LogType.Warning: LogWarningServerLocal(message, localId); break; case LogType.Error: LogErrorServerLocal(message, localId); break; } if (NetworkingManager.Singleton != null && !NetworkingManager.Singleton.IsServer && NetworkingManager.Singleton.NetworkConfig.EnableNetworkLogs) { using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteByte((byte)logType); writer.WriteStringPacked(message); InternalMessageSender.Send(NetworkingManager.Singleton.ServerClientId, MLAPIConstants.MLAPI_SERVER_LOG, "MLAPI_INTERNAL", stream, SecuritySendFlags.None, null); } } } }
private void OnLeftSpawnButtonPressed() { if (leftNetworkSquare.isNetworkSpawned) { leftNetworkSquare.UnspawnOnNetwork(); } else { if (m_NetworkManager.isServer) { using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteSinglePacked(m_LeftObjectPositioner.rect.center.x); writer.WriteSinglePacked(m_LeftObjectPositioner.rect.center.y); } leftNetworkSquare.SpawnOnNetwork(stream); } } else { leftNetworkSquare.SpawnOnNetwork(); } } }
internal static void RemoveOwnership(NetworkedObject netObject) { if (!NetworkingManager.Singleton.IsServer) { throw new NotServerException("Only the server can change ownership"); } if (!netObject.IsSpawned) { throw new SpawnStateException("Object is not spawned"); } for (int i = NetworkingManager.Singleton.ConnectedClients[netObject.OwnerClientId].OwnedObjects.Count - 1; i > -1; i--) { if (NetworkingManager.Singleton.ConnectedClients[netObject.OwnerClientId].OwnedObjects[i] == netObject) { NetworkingManager.Singleton.ConnectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAt(i); } } netObject._ownerClientId = null; using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt64Packed(netObject.NetworkId); writer.WriteUInt64Packed(netObject.OwnerClientId); InternalMessageSender.Send(MLAPIConstants.MLAPI_CHANGE_OWNER, "MLAPI_INTERNAL", stream, SecuritySendFlags.None, netObject); } } }
internal static void ChangeOwnership(uint netId, uint clientId) { if (!netManager.isServer) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("You can only change ownership from Server"); } return; } NetworkedObject netObject = SpawnManager.SpawnedObjects[netId]; for (int i = NetworkingManager.singleton.ConnectedClients[netObject.OwnerClientId].OwnedObjects.Count - 1; i > -1; i--) { if (NetworkingManager.singleton.ConnectedClients[netObject.OwnerClientId].OwnedObjects[i].NetworkId == netId) { NetworkingManager.singleton.ConnectedClients[netObject.OwnerClientId].OwnedObjects.RemoveAt(i); } } NetworkingManager.singleton.ConnectedClients[clientId].OwnedObjects.Add(netObject); netObject.OwnerClientId = clientId; using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt32Packed(netId); writer.WriteUInt32Packed(clientId); InternalMessageHandler.Send(MLAPIConstants.MLAPI_CHANGE_OWNER, "MLAPI_INTERNAL", stream, SecuritySendFlags.None); } } }
public void WriteDelta(Stream stream) => WriteField(stream); // Based on default NetworkedVar implementation. This class doesnt need this /// <inheritdoc /> public void WriteField(Stream stream) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteObjectPacked(InternalValue); //BOX } }
internal static BitStream WrapMessage(byte messageType, ulong clientID, BitStream messageBody, SecuritySendFlags flags) { try { bool encrypted = ((flags & SecuritySendFlags.Encrypted) == SecuritySendFlags.Encrypted) && false; //NetworkManager.Get().NetworkConfig.EnableEncryption; bool authenticated = (flags & SecuritySendFlags.Authenticated) == SecuritySendFlags.Authenticated && false; //NetworkManager.Get().NetworkConfig.EnableEncryption; PooledBitStream outStream = PooledBitStream.Get(); using (PooledBitWriter outWriter = PooledBitWriter.Get(outStream)) { outWriter.WriteBit(encrypted); outWriter.WriteBit(authenticated); outWriter.WriteBits(messageType, 6); outStream.Write(messageBody.GetBuffer(), 0, (int)messageBody.Length); } return(outStream); } catch (Exception e) { Debug.LogError("Error while wrapping headers"); Debug.LogError(e.ToString()); return(null); } }
// Ran on server internal static void HandleHailResponse(ulong clientId, Stream stream) { if (!NetworkingManager.Singleton.PendingClients.ContainsKey(clientId) || NetworkingManager.Singleton.PendingClients[clientId].ConnectionState != PendingClient.State.PendingHail) { return; } if (!NetworkingManager.Singleton.NetworkConfig.EnableEncryption) { return; } using (PooledBitReader reader = PooledBitReader.Get(stream)) { if (NetworkingManager.Singleton.PendingClients[clientId].KeyExchange != null) { byte[] diffieHellmanPublic = reader.ReadByteArray(); NetworkingManager.Singleton.PendingClients[clientId].AesKey = NetworkingManager.Singleton.PendingClients[clientId].KeyExchange.GetSharedSecret(diffieHellmanPublic); } } NetworkingManager.Singleton.PendingClients[clientId].ConnectionState = PendingClient.State.PendingConnection; NetworkingManager.Singleton.PendingClients[clientId].KeyExchange = null; // Give to GC // Send greetings, they have passed all the handshakes using (PooledBitStream outStream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(outStream)) { writer.WriteInt64Packed(DateTime.Now.Ticks); // This serves no purpose. } InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_GREETINGS, "MLAPI_INTERNAL", outStream, SecuritySendFlags.None, null); } }
/// <summary> /// Hides a object from a specific client /// </summary> /// <param name="clientId">The client to hide the object for</param> public void NetworkHide(ulong clientId) { if (!NetworkingManager.Singleton.IsServer) { if (LogHelper.CurrentLogLevel <= LogLevel.Error) { LogHelper.LogError("Can only call NetworkHide on the server"); } return; } if (observers.Contains(clientId) && clientId != NetworkingManager.Singleton.ServerClientId) { // Send destroy call observers.Remove(clientId); using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt64Packed(NetworkId); InternalMessageHandler.Send(MLAPIConstants.MLAPI_DESTROY_OBJECT, "MLAPI_INTERNAL", stream, SecuritySendFlags.None, null); } } } }
public void InvokeServerRPC(RPCDelegate method, Stream messageStream, byte channel = NetworkTransport.DEFAULT_CHANNEL) { if (!isClient) { //We are only a server and not a client Debug.LogError("Tried to invoke a ServerRPC without being a client. Only a client can invoke a server RPC.", this); return; } ulong hash = HashMethod(method.Method); using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt64Packed(networkID); writer.WriteUInt64Packed(hash); stream.CopyFrom(messageStream); if (isHost) { messageStream.Position = 0; //Invoke local InvokeLocalServerRPC(hash, networkManager.clientID, stream); } else { MessageSender.Send(networkManager.serverID, m_NetworkBehaviourManager.serverRPCMessageType, channel, stream); } } } }
//private void FixedUpdate() //{ //} private void Fire() { Vector3 firePosition = m_cameraFOV.transform.position; Vector3 fireDirection = m_cameraFOV.transform.forward; // Do server side hit detection only when there is a hit on client side. Just to save some server performance bool shouldVerifyHitOnServer = true; if (IVGameManager.Instance.m_useHitScan) { shouldVerifyHitOnServer = FireHitScan(firePosition, fireDirection); } else { shouldVerifyHitOnServer = InstantiateBullet(firePosition, fireDirection); // Instantiate bullet immediately on the client who is firing } using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteBool(shouldVerifyHitOnServer); writer.WriteVector3Packed(firePosition); writer.WriteVector3Packed(fireDirection); InvokeServerRpcPerformance(FireOnServer, stream); } } }
internal static void OnFirstSceneSwitchSync(uint sceneIndex, Guid switchSceneGuid) { if (!sceneIndexToString.ContainsKey(sceneIndex) || !registeredSceneNames.Contains(sceneIndexToString[sceneIndex])) { if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("Server requested a scene switch to a non registered scene"); } return; } else if (SceneManager.GetActiveScene().name == sceneIndexToString[sceneIndex]) { return; //This scene is already loaded. This usually happends at first load } lastScene = SceneManager.GetActiveScene(); string sceneName = sceneIndexToString[sceneIndex]; nextScene = SceneManager.GetSceneByName(sceneName); CurrentActiveSceneIndex = sceneNameToIndex[sceneName]; SceneManager.LoadScene(sceneName); using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteByteArray(switchSceneGuid.ToByteArray()); InternalMessageHandler.Send(NetworkingManager.Singleton.ServerClientId, MLAPIConstants.MLAPI_CLIENT_SWITCH_SCENE_COMPLETED, "MLAPI_INTERNAL", stream, SecuritySendFlags.None, null); } } isSwitching = false; }
internal void SendClientRPCPerformance(ulong hash, uint clientId, Stream messageStream, string channel, SecuritySendFlags security) { if (!IsServer && IsRunning) { //We are NOT a server. if (LogHelper.CurrentLogLevel <= LogLevel.Normal) { LogHelper.LogWarning("Only clients and host can invoke ClientRPC"); } return; } using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt32Packed(NetworkId); writer.WriteUInt16Packed(NetworkedObject.GetOrderIndex(this)); writer.WriteUInt64Packed(hash); stream.CopyFrom(messageStream); if (IsHost && clientId == NetworkingManager.Singleton.LocalClientId) { messageStream.Position = 0; InvokeClientRPCLocal(hash, NetworkingManager.Singleton.LocalClientId, messageStream); } else { InternalMessageHandler.Send(clientId, MLAPIConstants.MLAPI_CLIENT_RPC, string.IsNullOrEmpty(channel) ? "MLAPI_DEFAULT_MESSAGE" : channel, stream, security); } } } }
internal static void HandleClientRPCRequest(ulong clientId, Stream stream, string channelName, SecuritySendFlags security) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { ulong networkId = reader.ReadUInt64Packed(); ushort behaviourId = reader.ReadUInt16Packed(); ulong hash = reader.ReadUInt64Packed(); ulong responseId = reader.ReadUInt64Packed(); if (SpawnManager.SpawnedObjects.ContainsKey(networkId)) { NetworkedBehaviour behaviour = SpawnManager.SpawnedObjects[networkId].GetBehaviourAtOrderIndex(behaviourId); if (behaviour != null) { object result = behaviour.OnRemoteClientRPC(hash, clientId, stream); using (PooledBitStream responseStream = PooledBitStream.Get()) { using (PooledBitWriter responseWriter = PooledBitWriter.Get(responseStream)) { responseWriter.WriteUInt64Packed(responseId); responseWriter.WriteObjectPacked(result); } InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_CLIENT_RPC_RESPONSE, channelName, responseStream, security, null); } } } } }
private void OnTriggerEnter2D(Collider2D col) { switch (col.name) { case "LeftWall": right++; break; case "RightWall": left++; break; } using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteInt32(left); writer.WriteInt32(right); InvokeClientRpcOnEveryonePerformance(WinRPC, stream); } } Spawn(); }
internal static void SendSpawnCallForObject(ulong clientId, NetworkedObject netObject, Stream payload) { using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteBool(netObject.IsPlayerObject); writer.WriteUInt64Packed(netObject.NetworkId); writer.WriteUInt64Packed(netObject.OwnerClientId); if (NetworkingManager.Singleton.NetworkConfig.UsePrefabSync) { writer.WriteUInt64Packed(netObject.PrefabHash); } else { writer.WriteBool(netObject.IsSceneObject == null ? true : netObject.IsSceneObject.Value); if (netObject.IsSceneObject == null || netObject.IsSceneObject.Value) { writer.WriteUInt64Packed(netObject.NetworkedInstanceId); } else { writer.WriteUInt64Packed(netObject.PrefabHash); } } writer.WriteBool(netObject.DestroyWithScene); writer.WriteSinglePacked(netObject.transform.position.x); writer.WriteSinglePacked(netObject.transform.position.y); writer.WriteSinglePacked(netObject.transform.position.z); writer.WriteSinglePacked(netObject.transform.rotation.eulerAngles.x); writer.WriteSinglePacked(netObject.transform.rotation.eulerAngles.y); writer.WriteSinglePacked(netObject.transform.rotation.eulerAngles.z); writer.WriteBool(payload != null); if (payload != null) { writer.WriteInt32Packed((int)payload.Length); } if (NetworkingManager.Singleton.NetworkConfig.EnableNetworkedVar) { netObject.WriteNetworkedVarData(stream, clientId); } if (payload != null) { stream.CopyFrom(payload); } } InternalMessageHandler.Send(clientId, MLAPIConstants.MLAPI_ADD_OBJECT, "MLAPI_INTERNAL", stream, SecuritySendFlags.None, null); } }
void InvokeApplyTransform(ulong clientId, Vector3 position, Quaternion rotation, string channelName) { using (PooledBitStream stream = PooledBitStream.Get()) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { if (TransformTypeToSync == TransformType.Transform2D) { if (SyncPosition && SyncRotation) { writer.WriteVector2Packed(position); writer.WriteSinglePacked(rotation.eulerAngles.z); } else if (SyncPosition) { writer.WriteVector2Packed(position); } else if (SyncRotation) { writer.WriteSinglePacked(rotation.eulerAngles.z); } InvokeClientRpcOnClientPerformance("ApplyTransform2D", clientId, stream, channelName, Security.SecuritySendFlags.None); } else if (TransformTypeToSync == TransformType.Transform3D) { if (SyncPosition && SyncRotation) { writer.WriteVector3Packed(position); if (FullRotation) { writer.WriteVector3Packed(rotation.eulerAngles); } else { writer.WriteSingle(rotation.eulerAngles.y); } } else if (SyncPosition) { writer.WriteVector3Packed(position); } else if (SyncRotation) { if (FullRotation) { writer.WriteVector3Packed(rotation.eulerAngles); } else { writer.WriteSingle(rotation.eulerAngles.y); } } InvokeClientRpcOnClientPerformance("ApplyTransform", clientId, stream, channelName, Security.SecuritySendFlags.None); } } } }
public void Write(Stream stream) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteInt32Packed(points); writer.WriteInt32Packed(fouls); } }
public void Write(Stream stream) { using (var writer = PooledBitWriter.Get(stream)) { writer.WriteInt32Packed(playerId); writer.WriteVector2Packed(motion); } }
/// <inheritdoc /> public void WriteField(Stream stream) { using (PooledBitWriter writer = PooledBitWriter.Get(stream)) { writer.WriteUInt64Packed(InternalValue.clientID); //BOX writer.WriteUInt64Packed(InternalValue.networkID); } }