void uLink_OnSerializeNetworkView (uLink.BitStream stream, uLink.NetworkMessageInfo info) { Debug.Log ("Player count is " + playerCount); if (stream.isWriting) { stream.Write(playerCount); for (int i = 0; i < playerCount; i++) { if (players[i] != null) { stream.Write (uLinkNetworkView.Get(players[i]).viewID); } } } else { playerCount = stream.Read<int>(); for (int i = 0; i < playerCount; i++) { players[i] = uLinkNetworkView.Find(stream.Read<uLink.NetworkViewID>()).gameObject; } } }
protected override void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { base.uLink_OnSerializeNetworkView(stream, info); if (stream.isWriting) { // We own this object and we are the master client. Send the others our data. stream.Write(hitPoints); } else { // Network object, receive data. Every player needs the barrel's hitpoints in sync because // any one of them could be the new master client at any moment. hitPoints = stream.Read<int>(); } }
void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { if (stream.isWriting) { // Send information to all proxies (opponent player's computers) // This code is executed on the creator (server) when server is auth, or on the owner (client) when the server is non-auth. stream.Write(transform.position); stream.Write(character.velocity); stream.Write(transform.rotation); } else { // Update the proxy state when statesync arrives. Vector3 pos = stream.Read<Vector3>(); Vector3 vel = stream.Read<Vector3>(); Quaternion rot = stream.Read<Quaternion>(); UpdateState(pos, vel, rot, info.timestamp); } }
void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { if (stream.isWriting) { if (isBot) { // Send information to all proxies (opponent player's computers) // This code is executed on the creator (server) when server is auth, or on the owner (client) when the server is non-auth. stream.Write(m_Player.Position.Get()); stream.Write(m_Player.gameObject.transform.rotation.eulerAngles.y); } else { // Send information to all proxies (opponent player's computers) // This code is executed on the creator (server) when server is auth, or on the owner (client) when the server is non-auth. stream.Write(m_Player.Position.Get()); stream.Write(m_Player.Rotation.Get()); } if (damageToBeDone > 0f) { netwEvents.DamageOthers(damageToBeDone); damageToBeDone = 0f; } } else { if (isBot) { // Update the proxy state when statesync arrives. Vector3 pos = stream.Read<Vector3>(); float rotationY = stream.Read<float>(); //---------------------------------------------------------------------- // FOLLOWING CODES HANDLE BOT LERP PACKAGE ARRIVAL PROCESSES botLastPos = botNextPos; botNextPos = pos; botLastTimestamp = botNextTimestamp; botNextTimestamp = Time.time; botTimeCovered = 0f; //m_Player.Position.Set(pos); gameObject.transform.rotation = Quaternion.Euler( new Vector3(0f,rotationY,0f) ); //---------------------------------------------------------------------- } else { // Update the proxy state when statesync arrives. Vector3 pos = stream.Read<Vector3>(); Vector2 rot = stream.Read<Vector2>(); //---------------------------------------------------------------------- // FOLLOWING CODES HANDLE PLAYER LERP PACKAGE ARRIVAL PROCESSES playerLastPos = playerNextPos; playerNextPos = pos; playerLastRot = playerNextRot; playerNextRot = rot; playerLastTimestamp = playerNextTimestamp; playerNextTimestamp = Time.time; playerTimeCovered = 0f; //---------------------------------------------------------------------- } } }
void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { if (stream.isWriting) { // Send information to all proxies and the owner (clients) // This code is executed on the creator (server) stream.Write(transform.position); stream.Write(GetComponent<Rigidbody>().rotation); } else { //This code is executed in the clients mostCurrentReceivedState.pos = stream.Read<Vector3>(); mostCurrentReceivedState.rot = stream.Read<Quaternion>(); mostCurrentReceivedState.timestamp = info.timestamp + (interpolationBackTimeMs / 1000); } }
void uLink_OnSerializeNetworkView (uLink.BitStream stream, uLink.NetworkMessageInfo info) { if (stream.isWriting) { stream.Write(targetPosition); stream.Write(targetRotation); } else { targetPosition = stream.Read<Vector3>(); targetRotation = stream.Read<Quaternion>(); } }
protected override void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { base.uLink_OnSerializeNetworkView(stream, info); if (stream.isWriting) { stream.Write(primaryArmPivot.localPosition); stream.Write(primaryArmPivot.localRotation); stream.Write((int)CurrentPosture); stream.Write((int)facingDirection); CharacterWeaponType characterWeaponType = string.IsNullOrEmpty(ActiveWeaponName) ? CharacterWeaponType.None : (CharacterWeaponType)System.Enum.Parse(typeof(CharacterWeaponType), ActiveWeaponName); stream.Write((int)characterWeaponType); CharacterHatType characterHatType = string.IsNullOrEmpty(ActiveHatName) ? CharacterHatType.None : (CharacterHatType)System.Enum.Parse(typeof(CharacterHatType), ActiveHatName); stream.Write((int)characterHatType); CharacterMouthpieceType characterMouthpieceType = string.IsNullOrEmpty(ActiveMouthpieceName) ? CharacterMouthpieceType.None : (CharacterMouthpieceType)System.Enum.Parse(typeof(CharacterMouthpieceType), ActiveMouthpieceName); stream.Write((int)characterMouthpieceType); // Color Color c = characterColor; stream.Write(c.r); stream.Write(c.g); stream.Write(c.b); stream.Write(c.a); // Name stream.Write(gameObject.name); } else { // Network player, receive data primaryArmPivot.localPosition = stream.Read<Vector3>(); correctPrimaryArmPivot = stream.Read<Quaternion>(); this.CurrentPosture = (Posture)stream.Read<int>(); this.facingDirection = (FacingDirection)stream.Read<int>(); // We can't serialize strings so use enumerations CharacterWeaponType characterWeaponType = (CharacterWeaponType)stream.Read<int>(); if (CharacterWeaponType.None == characterWeaponType) { if (!string.IsNullOrEmpty(ActiveWeaponName)) { SetActiveWeapon(null); } } else if (ActiveWeaponName != characterWeaponType.ToString()) { SetActiveWeapon(characterWeaponType.ToString()); } CharacterHatType characterHatType = (CharacterHatType)stream.Read<int>(); if (CharacterHatType.None == characterHatType) { if (!string.IsNullOrEmpty(ActiveHatName)) { SetActiveHat(null); } } else if (ActiveHatName != characterHatType.ToString()) { SetActiveHat(characterHatType.ToString()); } CharacterMouthpieceType characterMouthpieceType = (CharacterMouthpieceType)stream.Read<int>(); if (CharacterMouthpieceType.None == characterMouthpieceType) { if (!string.IsNullOrEmpty(ActiveMouthpieceName)) { SetActiveMouthpiece(null); } } else if (ActiveMouthpieceName != characterMouthpieceType.ToString()) { SetActiveMouthpiece(characterMouthpieceType.ToString()); } // Color Color c = Color.black; c.r = stream.Read<float>(); c.g = stream.Read<float>(); c.b = stream.Read<float>(); c.a = stream.Read<float>(); if (characterColor != c) { characterColor = c; characterTextureAnimator.mainColor = characterColor; primaryArm.renderer.material.SetColor("_Emission", characterColor); } // Name gameObject.name = stream.Read<string>(); } }
protected virtual void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { if (stream.isWriting) { // We own this object (though we may not be the master client): send the others our data stream.Write(transform.position); stream.Write(transform.rotation); } else { // TODO: The server needs to somehow validate these values before they get from the // owner to all the players this.correctPos = stream.Read<Vector3>(); this.correctRot = stream.Read<Quaternion>(); } }
protected void uLink_OnSerializeNetworkView(uLink.BitStream stream, uLink.NetworkMessageInfo info) { if (stream.isWriting) { // We own this player: send the others our data stream.Write(totalSpawnedObjects); stream.Write(spawneeActive); stream.Write(timeEnemyDestroyed); stream.Write(spawnID); } else { // Network player, receive data totalSpawnedObjects = stream.Read<int>(); spawneeActive = stream.Read<bool>(); timeEnemyDestroyed = stream.Read<float>(); spawnID = stream.Read<int>(); } }