public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId(); GameObject cTurretObject = CNetwork.Factory.FindObject(cTurretViewId); if (cTurretObject != null) { CLaserTurretBehaviour cLaserTurretBehaviour = cTurretObject.GetComponent<CLaserTurretBehaviour>(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); switch (eAction) { case ENetworkAction.FireLasers: cLaserTurretBehaviour.FireLasers(); break; default: Debug.LogError(string.Format("Unknown network action ({0})", eAction)); break; } } } }
void OnRecievedPlayerMicrophoneAudio(CNetworkPlayer _cPlayer, CNetworkStream _cAudioDataStream) { GameObject playerActor = CGamePlayers.GetPlayerActor(_cPlayer.PlayerId); CNetworkViewId playerViewID = playerActor.GetComponent <CNetworkView>().ViewId; _cAudioDataStream.SetReadOffset(0); byte[] streamData = _cAudioDataStream.ReadBytes(_cAudioDataStream.NumUnreadBytes); CNetworkStream dataStream = new CNetworkStream(); dataStream.Write(streamData); dataStream.Write(playerViewID); Dictionary <ulong, CNetworkPlayer> players = CNetwork.Server.FindNetworkPlayers(); foreach (ulong playerID in players.Keys) { if (m_bReturnToSender) { CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream); } else { if (_cPlayer.PlayerId != playerID) { CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream); } } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId(); GameObject cModuleGunObject = cModuleGunViewId.GameObject; CToolInterface cToolInterface = cModuleGunObject.GetComponent<CToolInterface>(); CTorchLight cTorchLight = cModuleGunObject.GetComponent<CTorchLight>(); switch (eAction) { case ENetworkAction.TurnOnLight: cTorchLight.SetActive(true); break; case ENetworkAction.TurnOffLight: cTorchLight.SetActive(false); break; case ENetworkAction.ToggleColour: cTorchLight.ToggleColour(); break; default: Debug.LogError("Unknown network action: " + eAction); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId(); GameObject cModuleGunObject = cModuleGunViewId.GameObject; CToolInterface cToolInterface = cModuleGunObject.GetComponent <CToolInterface>(); CModuleGunBehaviour cModuleGunBehaviour = cModuleGunObject.GetComponent <CModuleGunBehaviour>(); switch (eAction) { case ENetworkAction.OpenDui: cModuleGunBehaviour.OpenDui(cToolInterface.OwnerPlayerActor.GetComponent <CPlayerInteractor>().TargetActorObject); break; case ENetworkAction.CloseDui: cModuleGunBehaviour.CloseDui(); break; default: Debug.LogError("Unknown network action"); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId cCockpitObjectViewId = _cStream.ReadNetworkViewId(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); GameObject cCockpitObject = CNetwork.Factory.FindObject(cCockpitObjectViewId); CCockpit cCockpit = cCockpitObject.GetComponent <CCockpit>(); switch (eAction) { case ENetworkAction.EnterCockpit: cCockpit.HandleEnterCockpit(_cNetworkPlayer.PlayerId); break; case ENetworkAction.LeaveCockpit: cCockpit.HandleLeaveCockpit(_cNetworkPlayer.PlayerId); break; default: Debug.LogError(string.Format("Unknown network action ({0})")); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); if (cPlayerActor != null) { CPlayerAirMotor cAirMotor = cPlayerActor.GetComponent<CPlayerAirMotor>(); while (_cStream.HasUnreadData) { ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.UpdateStates: cAirMotor.m_usMovementStates = _cStream.ReadUInt(); break; default: Debug.LogError(string.Format("Unknown network action ({0})", (int)eNetworkAction)); break; } } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); if (cPlayerActor != null) { CPlayerAirMotor cAirMotor = cPlayerActor.GetComponent <CPlayerAirMotor>(); while (_cStream.HasUnreadData) { ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.UpdateStates: cAirMotor.m_usMovementStates = _cStream.ReadUInt(); break; default: Debug.LogError(string.Format("Unknown network action ({0})", (int)eNetworkAction)); break; } } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerObject = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); CPlayerBackPack cPlayerBackPack = cPlayerObject.GetComponent <CPlayerBackPack>(); // Process stream data while (_cStream.HasUnreadData) { // Extract action ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); // Handle action switch (eAction) { case ENetworkAction.PickupModule: CNetworkViewId cModuleViewId = _cStream.ReadNetworkViewId(); cPlayerBackPack.PickupModule(_cNetworkPlayer.PlayerId, cModuleViewId); break; case ENetworkAction.DropModule: cPlayerBackPack.DropModule(); break; case ENetworkAction.InsertCell: CNetworkViewId cCellSlotViewId = _cStream.ReadNetworkViewId(); cPlayerBackPack.InsertCell(_cNetworkPlayer.PlayerId, cCellSlotViewId); break; } } }
public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { // While there is unread data in the stream while (_cStream.HasUnreadData) { // Save the first byte as the network action ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); // Switch on the network action switch (eNetworkAction) { // New player message was sent case ENetworkAction.ActionSendPlayerMessage: { // Read out messages into output strings string strName = _cStream.ReadString(); string strMessage = _cStream.ReadString(); // Find all players within 'hearing' range of the source player foreach (CNetworkPlayer Player in CheckPlayerDistances(_cNetworkPlayer)) { // Invoke RPC call to send the message to each player Instance.InvokeRpc(Player.PlayerId, "ReceivePlayerMessage", strName, strMessage); } break; } } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId(); GameObject cModuleGunObject = cModuleGunViewId.GameObject; CToolInterface cToolInterface = cModuleGunObject.GetComponent <CToolInterface>(); CTorchLight cTorchLight = cModuleGunObject.GetComponent <CTorchLight>(); switch (eAction) { case ENetworkAction.TurnOnLight: cTorchLight.SetActive(true); break; case ENetworkAction.TurnOffLight: cTorchLight.SetActive(false); break; case ENetworkAction.ToggleColour: cTorchLight.ToggleColour(); break; default: Debug.LogError("Unknown network action: " + eAction); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId(); GameObject cTurretObject = CNetwork.Factory.FindObject(cTurretViewId); if (cTurretObject != null) { CLaserTurretBehaviour cLaserTurretBehaviour = cTurretObject.GetComponent <CLaserTurretBehaviour>(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); switch (eAction) { case ENetworkAction.FireLasers: cLaserTurretBehaviour.FireLasers(); break; default: Debug.LogError(string.Format("Unknown network action ({0})", eAction)); break; } } } }
protected void HandlePlayerConnect(RakNet.SystemAddress _cSystemAddress, RakNet.RakNetGUID _cGuid) { // Create network player instance for new player CNetworkPlayer cNetworkPlayer = gameObject.AddComponent <CNetworkPlayer>(); // Check is host by matching address and connection guid bool bIsHost = _cGuid.g == CNetwork.Connection.RakPeer.GetMyGUID().g; // Initialise player instance cNetworkPlayer.Initialise(_cSystemAddress, _cGuid, bIsHost); // Store network player instance s_mNetworkPlayers.Add(cNetworkPlayer.Guid.g, cNetworkPlayer); // Join notice Logger.Write("A player has joined. Instance id ({0}) System address ({1}) Guid ({2})", cNetworkPlayer.PlayerId, _cSystemAddress, _cGuid); // Notify event observers if (EventPlayerConnect != null) { EventPlayerConnect(cNetworkPlayer); } // Update server info, player count UpdateServerInfo(); // Tell player that he has been given the initial game state cNetworkPlayer.SetDownloadingInitialGameStateComplete(); }
public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.ActionSendPlayerName: { string sPlayerName = _cStream.ReadString(); //Send all dictionary entries to new player foreach (KeyValuePair <ulong, string> entry in CGamePlayers.s_cInstance.m_mPlayersNames) { //Make sure you don't send RPC to yourself. Foreach loops will not let you modify the collections object (dictionary) you are operating on. if (_cNetworkPlayer.PlayerId != CNetwork.PlayerId) { CGamePlayers.s_cInstance.InvokeRpc(_cNetworkPlayer.PlayerId, "RegisterPlayerName", entry.Key, entry.Value); } } // Send new player name to all other players CGamePlayers.s_cInstance.InvokeRpcAll("RegisterPlayerName", _cNetworkPlayer.PlayerId, sPlayerName); break; } } }
void OnPlayerDisconnect(CNetworkPlayer _cNetworkPlayer) { if (MountedPlayerId == _cNetworkPlayer.PlayerId) { //Debug.LogError("Player left cockpit" + gameObject.name); HandleLeaveCockpit(_cNetworkPlayer.PlayerId); } }
public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { // Retrieve player actors head CPlayerHead cMyActorHead = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent <CPlayerHead>(); // Write my head's x-rotation float fRotationX = _cStream.ReadFloat(); cMyActorHead.m_fHeadEulerX.Set(fRotationX); }
public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); CPlayerRagdoll ragdoll = cPlayerActor.GetComponent <CPlayerRagdoll>(); while (_cStream.HasUnreadData) { // Extract action ragdoll.m_bRagdollState.Set(_cStream.ReadByte()); } }
static protected void NotifyOnEvent(CNetworkPlayer _cNetworkPlayer, CDUIElement _DUIElement, EElementNotificationType _NotificationType, object[] _Arguments) { ulong ignorePlayer = _cNetworkPlayer.PlayerId; foreach (ulong playerId in CNetwork.Server.FindNetworkPlayers().Keys) { if (playerId != ignorePlayer) { _DUIElement.InvokeRpc(playerId, "Invoke" + _NotificationType.ToString(), _Arguments); } } }
void OnPlayerDisconnect(CNetworkPlayer _cPlayer) { CNetworkViewId cPlayerActorNetworkViewId = GetPlayerActorViewId(_cPlayer.PlayerId); if (cPlayerActorNetworkViewId != null) { CNetwork.Factory.DestoryObject(cPlayerActorNetworkViewId); // Sync unregister player actor view id with everyone InvokeRpcAll("UnregisterPlayerActor", _cPlayer.PlayerId); //Remove player from dictionary of player names InvokeRpcAll("UnregisterPlayerName", _cPlayer.PlayerId); Logger.Write("Removed Player Actor for Player Id ({0})", _cPlayer.PlayerId); } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { if (CGamePlayers.SelfActor == null) { return; } CPlayerInteractor cPlayerInteractor = CGamePlayers.SelfActor.GetComponent <CPlayerInteractor>(); while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cNewTargetViewId = _cStream.ReadNetworkViewId(); switch (eAction) { case ENetworkAction.UpdateTarget: if (cNewTargetViewId != null) { cPlayerInteractor.m_cTargetActorObject = cNewTargetViewId.GameObject; if (cPlayerInteractor.EventServerTargetChange != null) { cPlayerInteractor.EventServerTargetChange(cPlayerInteractor.m_cTargetActorObject); } // Debug.LogError("Found new target: " + cPlayerInteractor.m_cTargetActorObject); } else { cPlayerInteractor.m_cTargetActorObject = null; if (cPlayerInteractor.EventServerTargetChange != null) { cPlayerInteractor.EventServerTargetChange(null); } //Debug.LogError("Found new target: " + null); } break; default: Debug.LogError("Unknown network action"); break; } } }
void OnPlayerJoin(CNetworkPlayer _cPlayer) { // Send created objects to new player CNetwork.Factory.SyncPlayer(_cPlayer); // Server doesn't need this if (!_cPlayer.IsHost) { // Sync current players actor view ids with new player foreach (KeyValuePair <ulong, CNetworkViewId> tEntry in m_mPlayersActors) { InvokeRpc(_cPlayer.PlayerId, "RegisterPlayerActor", tEntry.Key, tEntry.Value); } } // Placeholder Test stuff //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolAk47); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolTorch); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolExtinguisher); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.Fire); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolMedical); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.BlackMatterCell); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.FuelCell); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.PlasmaCell); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.PowerCell); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.BioCell); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.ReplicatorCell); //Place module gun //GameObject tool = CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolModuleGun); //tool.GetComponent<CNetworkView>().SetPosition(new Vector3(-10.0f, -8.0f, -13.0f)); //tool = CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolAk47); //tool.GetComponent<CNetworkView>().SetPosition(new Vector3(-10.0f, -9.0f, -13.0f)); //Place Ratchet //GameObject ratchet = CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolRatchet); //ratchet.GetComponent<CNetworkView>().SetPosition(new Vector3(-10.0f, -11.0f, -13.0f)); m_aUnspawnedPlayers.Add(_cPlayer.PlayerId); //Send all dictionary entries to all players. Logger.Write("Created new player actor for player id ({0})", _cPlayer.PlayerId); }
public static void UnserializeBeltState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CPlayerBelt cPlayerBelt = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent <CPlayerBelt>(); switch (eAction) { case ENetworkAction.PickupTool: { CNetworkViewId cToolViewId = _cStream.ReadNetworkViewId(); cPlayerBelt.PickupTool(cToolViewId.GameObject); } break; } } }
protected void HandlePlayerDisconnect(CNetworkPlayer _cPlayer, EDisconnectType _eDisconnectType) { Logger.Write("A client has disconnected"); // Notify event observers if (EventPlayerDisconnect != null) { EventPlayerDisconnect(_cPlayer); } Component.Destroy(s_mNetworkPlayers[_cPlayer.PlayerId]); // Remove and delete network player s_mNetworkPlayers.Remove(_cPlayer.PlayerId); // Update server info, player count UpdateServerInfo(); }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId oxygenRefillViewId = _cStream.ReadNetworkViewId(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); GameObject cOxygenRefillerObject = oxygenRefillViewId.GameObject; COxygenRefillerBehaviour blah = cOxygenRefillerObject.GetComponent <COxygenRefillerBehaviour>(); switch (eAction) { case ENetworkAction.RefillOxygen: blah.HandlePlayerOxygenRefill(_cNetworkPlayer.PlayerId); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId oxygenRefillViewId = _cStream.ReadNetworkViewId(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); GameObject cOxygenRefillerObject = oxygenRefillViewId.GameObject; COxygenRefillerBehaviour blah = cOxygenRefillerObject.GetComponent<COxygenRefillerBehaviour>(); switch (eAction) { case ENetworkAction.RefillOxygen: blah.HandlePlayerOxygenRefill(_cNetworkPlayer.PlayerId); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cMedicalSpayViewId = _cStream.ReadNetworkViewId(); switch (eAction) { case ENetworkAction.SprayStart: cMedicalSpayViewId.GameObject.GetComponent<CMedicalSpray>().m_bActive.Set(true); break; case ENetworkAction.SprayEnd: cMedicalSpayViewId.GameObject.GetComponent<CMedicalSpray>().m_bActive.Set(false); break; default: Debug.LogError("Unknown network action"); break; } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cFireExtinguisherViewId = _cStream.ReadNetworkViewId(); switch (eAction) { case ENetworkAction.ExtinguishFireStart: cFireExtinguisherViewId.GameObject.GetComponent <CFireExtinguisherSpray>().m_bActive.Set(true); break; case ENetworkAction.ExtinguishFireEnd: cFireExtinguisherViewId.GameObject.GetComponent <CFireExtinguisherSpray>().m_bActive.Set(false); break; default: Debug.LogError("Unknown network action"); break; } }
public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); if (cPlayerActor != null) { //while (_cStream.HasUnreadData) { // Retrieve player actor motor CPlayerGroundMotor cPlayerActorMotor = cPlayerActor.GetComponent <CPlayerGroundMotor>(); ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.UpdateStates: { cPlayerActorMotor.m_uiMovementStates = _cStream.ReadByte(); if (cPlayerActor != CGamePlayers.SelfActor) { cPlayerActor.transform.eulerAngles = new Vector3(0.0f, _cStream.ReadFloat(), 0.0f); } else { _cStream.ReadFloat(); } cPlayerActorMotor.m_bStates.Set((byte)cPlayerActorMotor.m_uiMovementStates); } break; default: Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction)); break; } } } }
public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { // Extract action ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); switch (eAction) { case ENetworkAction.SetRepairState: { //Figure out which ratchet sent it's new state CRatchetBehaviour ratchet = _cStream.ReadNetworkViewId().GameObject.GetComponent<CRatchetBehaviour>(); ratchet.m_TargetComponent = _cStream.ReadNetworkViewId().GameObject.GetComponent<CComponentInterface>(); ratchet.m_eRepairState = (ERepairState)_cStream.ReadByte(); break; } } } }
public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { // Extract action ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); switch (eAction) { case ENetworkAction.SetRepairState: { //Figure out which kits sent it's new state CCircuitryKitBehaviour CircuitryKit = _cStream.ReadNetworkViewId().GameObject.GetComponent <CCircuitryKitBehaviour>(); CircuitryKit.m_TargetComponent = _cStream.ReadNetworkViewId().GameObject.GetComponent <CComponentInterface>(); CircuitryKit.m_eRepairState = (ERepairState)_cStream.ReadByte(); break; } } } }
static public void UnserializeSliderEvents(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while(_cStream.HasUnreadData) { // Get the DUISlider and its network view CDUISlider duiSlider = CNetwork.Factory.FindObject(_cStream.ReadNetworkViewId()).GetComponent<CDUISlider>(); // Get the interaction notification ESliderNotificationType notification = (ESliderNotificationType)_cStream.ReadByte(); // Based on the notification type, update the clients of the event switch(notification) { case ESliderNotificationType.OnValueChange: float value = _cStream.ReadFloat(); duiSlider.SetSliderValue(value); break; default:break; } } }
static public void UnserializeSliderEvents(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { // Get the DUISlider and its network view CDUISlider duiSlider = CNetwork.Factory.FindObject(_cStream.ReadNetworkViewId()).GetComponent <CDUISlider>(); // Get the interaction notification ESliderNotificationType notification = (ESliderNotificationType)_cStream.ReadByte(); // Based on the notification type, update the clients of the event switch (notification) { case ESliderNotificationType.OnValueChange: float value = _cStream.ReadFloat(); duiSlider.SetSliderValue(value); break; default: break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cAk47ViewId = _cStream.ReadNetworkViewId(); switch (eAction) { case ENetworkAction.ShootStart: cAk47ViewId.GameObject.GetComponent <CAk47Behaviour>().m_bShoot = true; break; case ENetworkAction.ShootEnd: cAk47ViewId.GameObject.GetComponent <CAk47Behaviour>().m_bShoot = false; break; default: Debug.LogError("Unknown network action"); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cPlayer, CNetworkStream _cStream) { TPlayerStates tPlayerStates = s_cInstance.m_mPlayerStates[_cPlayer.PlayerId]; tPlayerStates.ulPreviousInput = tPlayerStates.ulInput; tPlayerStates.ulInput = _cStream.ReadULong(); tPlayerStates.fPreviousMouseX = tPlayerStates.fMouseX; tPlayerStates.fPreviousMouseY = tPlayerStates.fMouseY; tPlayerStates.fMouseX = _cStream.ReadFloat(); tPlayerStates.fMouseY = _cStream.ReadFloat(); if (tPlayerStates.fPreviousMouseX != tPlayerStates.fMouseX) { s_cInstance.InvokeClientClientAxisEvent(EAxis.MouseX, _cPlayer.PlayerId, tPlayerStates.fMouseX); } if (tPlayerStates.fPreviousMouseY != tPlayerStates.fMouseY) { s_cInstance.InvokeClientClientAxisEvent(EAxis.MouseY, _cPlayer.PlayerId, tPlayerStates.fMouseY); } s_cInstance.ProcessClientEvents(_cPlayer.PlayerId, tPlayerStates); }
public static void ProcessPlayerSerializedData(CNetworkPlayer _cPlayer, byte[] _baData) { // Create packet stream CNetworkStream cStream = new CNetworkStream(_baData); // Ignore timestamp packet id cStream.IgnoreBytes(1); // Retrieve latency ulong ulLatency = RakNet.RakNet.GetTime() - cStream.ReadULong(); // Ignmore serialized data packet id cStream.IgnoreBytes(1); // Iterate through the packet data while (cStream.HasUnreadData && cStream.NumUnreadBits > 18) { // Extract the target identifier byte bTargetIdentifier = cStream.ReadByte(); // Extract the size of the data ushort usBitSize = cStream.ReadBits <ushort>(10); ushort usByteSize = (ushort)((float)usBitSize / 8.0f); // Extract the data byte[] baData = new byte[usByteSize]; cStream.BitStream.ReadBits(baData, usBitSize); // Create stream for the control CNetworkStream cTargetStream = new CNetworkStream(); cTargetStream.WriteBits(baData, usBitSize); // Have the target process its data s_mThrottledSerializeTargets[bTargetIdentifier].nUnserializeMethod(_cPlayer, cTargetStream); } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId(); GameObject cTurretObject = CNetwork.Factory.FindObject(cTurretViewId); if (cTurretObject != null) { CMiningTurretBehaviour cMiningTurretBehaviour = cTurretObject.GetComponent <CMiningTurretBehaviour>(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); switch (eAction) { case ENetworkAction.StartFractureLaser: cMiningTurretBehaviour.m_bFractureLaserButtonDown = true; break; case ENetworkAction.StopFractureLaser: cMiningTurretBehaviour.m_bFractureLaserButtonDown = false; break; case ENetworkAction.StartExtractorBeam: cMiningTurretBehaviour.m_bExtracterBeamButtonDown = true; break; case ENetworkAction.StopExtractorBeam: cMiningTurretBehaviour.m_bExtracterBeamButtonDown = false; break; default: Debug.LogError(string.Format("Unknown network action ({0})", eAction)); break; } } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId cTurretViewId = _cStream.ReadNetworkViewId(); GameObject cTurretObject = CNetwork.Factory.FindObject(cTurretViewId); if (cTurretObject != null) { CMiningTurretBehaviour cMiningTurretBehaviour = cTurretObject.GetComponent<CMiningTurretBehaviour>(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); switch (eAction) { case ENetworkAction.StartFractureLaser: cMiningTurretBehaviour.m_bFractureLaserButtonDown = true; break; case ENetworkAction.StopFractureLaser: cMiningTurretBehaviour.m_bFractureLaserButtonDown = false; break; case ENetworkAction.StartExtractorBeam: cMiningTurretBehaviour.m_bExtracterBeamButtonDown = true; break; case ENetworkAction.StopExtractorBeam: cMiningTurretBehaviour.m_bExtracterBeamButtonDown = false; break; default: Debug.LogError(string.Format("Unknown network action ({0})", eAction)); break; } } } }
protected void ProcessOutgoingPackets() { // Increment outbound timer m_fPacketOutboundTimer += Time.deltaTime; // Compile and send out packets if its time if (m_fPacketOutboundTimer > m_fPacketOutboundInterval) { // Decrement timer m_fPacketOutboundTimer -= m_fPacketOutboundInterval; ++SendCounter; // Send player packets out foreach (KeyValuePair <ulong, CNetworkPlayer> tEntry in s_mNetworkPlayers) { CNetworkPlayer cNetworkPlayer = tEntry.Value; CNetworkStream cNetworkViewStream = new CNetworkStream(); cNetworkViewStream.Write((byte)RakNet.DefaultMessageIDTypes.ID_TIMESTAMP); cNetworkViewStream.Write(RakNet.RakNet.GetTime()); cNetworkViewStream.Write(cNetworkPlayer.NetworkViewStream); // Check stream has outbound data if (cNetworkViewStream.ByteSize >= 11) { //Logger.WriteError("Sent packet to player id ({0}) system address ({1}) of size ({2}) MessageId ({3})", cNetworkPlayer.PlayerId, cNetworkPlayer.SystemAddress, cNetworkViewStream.GetSize(), cNetworkViewStream.ReadByte()); //cNetworkViewStream.SetReadOffset(0); // Dispatch data to player m_cRnPeer.Send(cNetworkViewStream.BitStream, RakNet.PacketPriority.IMMEDIATE_PRIORITY, RakNet.PacketReliability.RELIABLE_SEQUENCED, (char)0, cNetworkPlayer.SystemAddress, false); cNetworkPlayer.ResetNetworkViewSteam(); } } } }
static List <CNetworkPlayer> CheckPlayerDistances(CNetworkPlayer _SourcePlayer) { // Temporary return list of players within range of the source List <CNetworkPlayer> ReturnPlayerList = new List <CNetworkPlayer>(); // Dictionary of all connected players // NOTE: This dictionary includes the source player Dictionary <ulong, CNetworkPlayer> PlayerList = CNetwork.Server.FindNetworkPlayers(); // Loop to iterate through all players including the source foreach (KeyValuePair <ulong, CNetworkPlayer> Player in PlayerList) { // If the current player is not the source player if (Player.Key != _SourcePlayer.PlayerId) { // Add the source's position vector to the current player's vector // If the magnitude of the resulting vector is greater than 10.0f if ((Player.Value.transform.position + _SourcePlayer.transform.position).magnitude >= 10.0f) { Debug.Log((Player.Value.transform.position + _SourcePlayer.transform.position).magnitude.ToString()); // Add the player to the return list ReturnPlayerList.Add(Player.Value); } } } // If the return list is empty if (ReturnPlayerList.Count == 0) { // Invoke an RPC call on the source player Instance.InvokeRpc(_SourcePlayer.PlayerId, "ReceivePlayerMessage", "Server", "There are no players nearby who can hear your message."); } // Return list of players within range of the source return(ReturnPlayerList); }
void OnPlayerJoin(CNetworkPlayer _cPlayer) { // Send created objects to new player CNetwork.Factory.SyncPlayer(_cPlayer); // Server doesn't need this if (!_cPlayer.IsHost) { // Sync current players actor view ids with new player foreach (KeyValuePair<ulong, CNetworkViewId> tEntry in m_mPlayersActors) { InvokeRpc(_cPlayer.PlayerId, "RegisterPlayerActor", tEntry.Key, tEntry.Value); } } // Placeholder Test stuff //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolAk47); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolTorch); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolExtinguisher); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.Fire); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolMedical); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.BlackMatterCell); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.FuelCell); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.PlasmaCell); //CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.PowerCell); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.BioCell); //CNetwork.Factory.CreateObject(CGameResourceLoader.ENetworkRegisteredPrefab.ReplicatorCell); //Place module gun //GameObject tool = CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolModuleGun); //tool.GetComponent<CNetworkView>().SetPosition(new Vector3(-10.0f, -8.0f, -13.0f)); //tool = CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolAk47); //tool.GetComponent<CNetworkView>().SetPosition(new Vector3(-10.0f, -9.0f, -13.0f)); //Place Ratchet //GameObject ratchet = CNetwork.Factory.CreateObject(CGameRegistrator.ENetworkPrefab.ToolRatchet); //ratchet.GetComponent<CNetworkView>().SetPosition(new Vector3(-10.0f, -11.0f, -13.0f)); m_aUnspawnedPlayers.Add(_cPlayer.PlayerId); //Send all dictionary entries to all players. Logger.Write("Created new player actor for player id ({0})", _cPlayer.PlayerId); }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerObject = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); CPlayerBackPack cPlayerBackPack = cPlayerObject.GetComponent<CPlayerBackPack>(); // Process stream data while (_cStream.HasUnreadData) { // Extract action ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); // Handle action switch (eAction) { case ENetworkAction.PickupModule: CNetworkViewId cModuleViewId = _cStream.ReadNetworkViewId(); cPlayerBackPack.PickupModule(_cNetworkPlayer.PlayerId, cModuleViewId); break; case ENetworkAction.DropModule: cPlayerBackPack.DropModule(); break; case ENetworkAction.InsertCell: CNetworkViewId cCellSlotViewId = _cStream.ReadNetworkViewId(); cPlayerBackPack.InsertCell(_cNetworkPlayer.PlayerId, cCellSlotViewId); break; } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId(); GameObject cModuleGunObject = cModuleGunViewId.GameObject; CToolInterface cToolInterface = cModuleGunObject.GetComponent<CToolInterface>(); CModuleGunBehaviour cModuleGunBehaviour = cModuleGunObject.GetComponent<CModuleGunBehaviour>(); switch (eAction) { case ENetworkAction.OpenDui: cModuleGunBehaviour.OpenDui(cToolInterface.OwnerPlayerActor.GetComponent<CPlayerInteractor>().TargetActorObject); break; case ENetworkAction.CloseDui: cModuleGunBehaviour.CloseDui(); break; default: Debug.LogError("Unknown network action"); break; } } }
static List<CNetworkPlayer> CheckPlayerDistances(CNetworkPlayer _SourcePlayer) { // Temporary return list of players within range of the source List<CNetworkPlayer> ReturnPlayerList = new List<CNetworkPlayer>(); // Dictionary of all connected players // NOTE: This dictionary includes the source player Dictionary<ulong, CNetworkPlayer> PlayerList = CNetwork.Server.FindNetworkPlayers(); // Loop to iterate through all players including the source foreach (KeyValuePair<ulong, CNetworkPlayer> Player in PlayerList) { // If the current player is not the source player if (Player.Key != _SourcePlayer.PlayerId) { // Add the source's position vector to the current player's vector // If the magnitude of the resulting vector is greater than 10.0f if ((Player.Value.transform.position + _SourcePlayer.transform.position).magnitude >= 10.0f) { Debug.Log((Player.Value.transform.position + _SourcePlayer.transform.position).magnitude.ToString()); // Add the player to the return list ReturnPlayerList.Add(Player.Value); } } } // If the return list is empty if (ReturnPlayerList.Count == 0) { // Invoke an RPC call on the source player Instance.InvokeRpc(_SourcePlayer.PlayerId, "ReceivePlayerMessage", "Server", "There are no players nearby who can hear your message."); } // Return list of players within range of the source return (ReturnPlayerList); }
void OnPlayerJoin(CNetworkPlayer _cPlayer) { // Tell connecting player which is the ship's network view id InvokeRpc(_cPlayer.PlayerId, "SetShipNetworkViewId", m_cShipViewId); }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { CNetworkViewId cCockpitObjectViewId = _cStream.ReadNetworkViewId(); ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); GameObject cCockpitObject = CNetwork.Factory.FindObject(cCockpitObjectViewId); CCockpit cCockpit = cCockpitObject.GetComponent<CCockpit>(); switch (eAction) { case ENetworkAction.EnterCockpit: cCockpit.HandleEnterCockpit(_cNetworkPlayer.PlayerId); break; case ENetworkAction.LeaveCockpit: cCockpit.HandleLeaveCockpit(_cNetworkPlayer.PlayerId); break; default: Debug.LogError(string.Format("Unknown network action ({0})")); break; } } }
public static void ProcessPlayerSerializedData(CNetworkPlayer _cPlayer, byte[] _baData) { // Create packet stream CNetworkStream cStream = new CNetworkStream(_baData); // Ignore timestamp packet id cStream.IgnoreBytes(1); // Retrieve latency ulong ulLatency = RakNet.RakNet.GetTime() - cStream.ReadULong(); // Ignmore serialized data packet id cStream.IgnoreBytes(1); // Iterate through the packet data while (cStream.HasUnreadData && cStream.NumUnreadBits > 18) { // Extract the target identifier byte bTargetIdentifier = cStream.ReadByte(); // Extract the size of the data ushort usBitSize = cStream.ReadBits<ushort>(10); ushort usByteSize = (ushort)((float)usBitSize / 8.0f); // Extract the data byte[] baData = new byte[usByteSize]; cStream.BitStream.ReadBits(baData, usBitSize); // Create stream for the control CNetworkStream cTargetStream = new CNetworkStream(); cTargetStream.WriteBits(baData, usBitSize); // Have the target process its data s_mThrottledSerializeTargets[bTargetIdentifier].nUnserializeMethod(_cPlayer, cTargetStream); } }
public static void UnserializeCockpitInteractions(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { }
public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { // Retrieve player actors head CPlayerHead cMyActorHead = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent<CPlayerHead>(); // Write my head's x-rotation float fRotationX = _cStream.ReadFloat(); cMyActorHead.m_fHeadEulerX.Set(fRotationX); }
public void SyncPlayer(CNetworkPlayer _cNetworkPlayer) { // Ensure only servers call this function Logger.WriteErrorOn(!CNetwork.IsServer, "Only the server can sync players"); // Sync new player with all the current game objects are their network var values if (!_cNetworkPlayer.IsHost) { Logger.Write("A Player joined. Sending them the objects and states"); foreach (KeyValuePair<CNetworkViewId, TObjectInfo> tEntry in m_mCreatedObjects) { // Tell player to instantiate already created object InvokeRpc(_cNetworkPlayer.PlayerId, "CreateLocalObject", tEntry.Value.usPrefab, tEntry.Key); } // Sync parents for each transform foreach (KeyValuePair<CNetworkViewId, TObjectInfo> tEntry in m_mCreatedObjects) { if (tEntry.Value.cGameObject == null) { Debug.LogError(string.Format("Gameobject({0}) is null. PrefabId({1})", tEntry.Value.cGameObject, tEntry.Value.usPrefab)); } if (tEntry.Value.cGameObject.GetComponent<CNetworkView>() == null) { Debug.LogError(string.Format("Gameobject({0}) does not have a networkview. PrefabId({1})", tEntry.Value.cGameObject, tEntry.Value.usPrefab)); } // Extract the network view from this object CNetworkView cSelfView = tEntry.Value.cGameObject.GetComponent<CNetworkView>(); // Only sync if position is not default if (tEntry.Value.cGameObject.transform.position != Vector3.zero) { cSelfView.SyncTransformPosition(); } // Sync if rotation is not default if (tEntry.Value.cGameObject.transform.eulerAngles != Vector3.zero) { cSelfView.SyncTransformRotation(); } // Sync if scale is not default if (tEntry.Value.cGameObject.transform.localScale != Vector3.zero) { // Sync object's scale cSelfView.SyncTransformScale(); } } // Sync network vars last foreach (KeyValuePair<CNetworkViewId, TObjectInfo> tEntry in m_mCreatedObjects) { // Extract the network view from this object CNetworkView cNetworkView = tEntry.Value.cGameObject.GetComponent<CNetworkView>(); // Tell object to sync all their network vars with the player cNetworkView.SyncNetworkVarsWithPlayer(_cNetworkPlayer.PlayerId); // Have children network views to sync their values foreach (KeyValuePair<byte, CNetworkView> tEntity in cNetworkView.ChildrenNetworkViews) { tEntity.Value.SyncNetworkVarsWithPlayer(_cNetworkPlayer.PlayerId); } } } }
void OnRecievedPlayerMicrophoneAudio(CNetworkPlayer _cPlayer, CNetworkStream _cAudioDataStream) { GameObject playerActor = CGamePlayers.GetPlayerActor(_cPlayer.PlayerId); CNetworkViewId playerViewID = playerActor.GetComponent<CNetworkView>().ViewId; _cAudioDataStream.SetReadOffset(0); byte[] streamData = _cAudioDataStream.ReadBytes(_cAudioDataStream.NumUnreadBytes); CNetworkStream dataStream = new CNetworkStream(); dataStream.Write(streamData); dataStream.Write(playerViewID); Dictionary<ulong,CNetworkPlayer> players = CNetwork.Server.FindNetworkPlayers(); foreach(ulong playerID in players.Keys) { if(m_bReturnToSender) { CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream); } else { if(_cPlayer.PlayerId != playerID) { CNetwork.Server.TransmitMicrophoneAudio(playerID, dataStream); } } } }
public static void UnserializeBeltState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CPlayerBelt cPlayerBelt = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId).GetComponent<CPlayerBelt>(); switch (eAction) { case ENetworkAction.PickupTool: { CNetworkViewId cToolViewId = _cStream.ReadNetworkViewId(); cPlayerBelt.PickupTool(cToolViewId.GameObject); } break; } } }
public static void UnserializeData(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.ActionSendPlayerName: { string sPlayerName = _cStream.ReadString(); //Send all dictionary entries to new player foreach (KeyValuePair<ulong, string> entry in CGamePlayers.s_cInstance.m_mPlayersNames) { //Make sure you don't send RPC to yourself. Foreach loops will not let you modify the collections object (dictionary) you are operating on. if(_cNetworkPlayer.PlayerId != CNetwork.PlayerId) { CGamePlayers.s_cInstance.InvokeRpc(_cNetworkPlayer.PlayerId, "RegisterPlayerName", entry.Key, entry.Value); } } // Send new player name to all other players CGamePlayers.s_cInstance.InvokeRpcAll("RegisterPlayerName", _cNetworkPlayer.PlayerId, sPlayerName); break; } } }
public static void UnserializePlayerState(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); if (cPlayerActor != null) { //while (_cStream.HasUnreadData) { // Retrieve player actor motor CPlayerGroundMotor cPlayerActorMotor = cPlayerActor.GetComponent<CPlayerGroundMotor>(); ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.UpdateStates: { cPlayerActorMotor.m_uiMovementStates = _cStream.ReadByte(); if (cPlayerActor != CGamePlayers.SelfActor) { cPlayerActor.transform.eulerAngles = new Vector3(0.0f, _cStream.ReadFloat(), 0.0f); } else { _cStream.ReadFloat(); } cPlayerActorMotor.m_bStates.Set((byte)cPlayerActorMotor.m_uiMovementStates); } break; default: Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction)); break; } } } }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { if (CGamePlayers.SelfActor == null) { return; } CPlayerInteractor cPlayerInteractor = CGamePlayers.SelfActor.GetComponent<CPlayerInteractor>(); while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cNewTargetViewId = _cStream.ReadNetworkViewId(); switch (eAction) { case ENetworkAction.UpdateTarget: if (cNewTargetViewId != null) { cPlayerInteractor.m_cTargetActorObject = cNewTargetViewId.GameObject; if (cPlayerInteractor.EventServerTargetChange != null) cPlayerInteractor.EventServerTargetChange(cPlayerInteractor.m_cTargetActorObject); // Debug.LogError("Found new target: " + cPlayerInteractor.m_cTargetActorObject); } else { cPlayerInteractor.m_cTargetActorObject = null; if (cPlayerInteractor.EventServerTargetChange != null) cPlayerInteractor.EventServerTargetChange(null); //Debug.LogError("Found new target: " + null); } break; default: Debug.LogError("Unknown network action"); break; } } }
public static void Unserialize(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); CPlayerRagdoll ragdoll = cPlayerActor.GetComponent<CPlayerRagdoll>(); while (_cStream.HasUnreadData) { // Extract action ragdoll.m_bRagdollState.Set(_cStream.ReadByte()); } }
public static void UnserializeIKTarget(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId); if (cPlayerActor != null) { CPlayerIKController cPlayerIKController = cPlayerActor.GetComponent<CPlayerIKController>(); ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte(); switch (eNetworkAction) { case ENetworkAction.SetRightTransform: { Vector3 pos = new Vector3(); Vector3 rot = new Vector3(); pos.x = _cStream.ReadFloat(); pos.y = _cStream.ReadFloat(); pos.z = _cStream.ReadFloat(); cPlayerIKController.m_RightHandTarget.position = pos; rot.x = _cStream.ReadFloat(); rot.y = _cStream.ReadFloat(); rot.z = _cStream.ReadFloat(); cPlayerIKController.m_RightHandTarget.rotation = Quaternion.Euler(rot); cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_RightHandTarget.position); cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_RightHandTarget.rotation.eulerAngles); } break; case ENetworkAction.SetLeftTransform: { Vector3 pos = new Vector3(); Vector3 rot = new Vector3(); pos.x = _cStream.ReadFloat(); pos.y = _cStream.ReadFloat(); pos.z = _cStream.ReadFloat(); cPlayerIKController.m_LeftHandTarget.position = pos; rot.x = _cStream.ReadFloat(); rot.y = _cStream.ReadFloat(); rot.z = _cStream.ReadFloat(); cPlayerIKController.m_LeftHandTarget.rotation = Quaternion.Euler(rot); cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_LeftHandTarget.position); cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_LeftHandTarget.rotation.eulerAngles); } break; default: Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction)); break; } } }