void OnPhotonSerializeView(PhotonStream aStream, PhotonMessageInfo aInfo) { CacheComponents (); if (aStream.isWriting) { // this is our player, we must send out our actual position aStream.SendNext(transform.position); aStream.SendNext(transform.rotation); aStream.SendNext(anim.GetFloat("Speed")); aStream.SendNext(anim.GetBool("Jumping")); aStream.SendNext (anim.GetFloat("AimAngle")); } else { // this is someone elses player, we need to receive their player and update // our version of that player realPosition = (Vector3) aStream.ReceiveNext(); realRotation = (Quaternion) aStream.ReceiveNext(); anim.SetFloat("Speed", (float)aStream.ReceiveNext()); anim.SetBool("Jumping", (bool)aStream.ReceiveNext()); realAimAngle = (float) aStream.ReceiveNext(); if(gotFirstUpdate == false) { transform.position = realPosition; transform.rotation = realRotation; anim.SetFloat("AimAngle", realAimAngle); gotFirstUpdate = true; } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //This is executed on the owner of the PhotonView //The owner sends it's position over the network stream.SendNext(transform.position);//"Encode" it, and send it } else { //Executed on all non-owners //receive a position and set the object to it Vector3 lastReceivedPosition = (Vector3)stream.ReceiveNext(); //We've just recieved the current servers position of this object in 'posReceive'. transform.position = lastReceivedPosition; //To reduce laggy movement a bit you could comment the line above and use position lerping below instead: //It would be even better to save the last received server position and lerp to it in Update because it is executed more often than OnPhotonSerializeView } }
// void Update() { // if (!photonView.isMine) { // transform.position = Vector3.Lerp(transform.position, correctPlayerPosition, 0.1f); // transform.rotation = Quaternion.Lerp (transform.rotation, correctPlayerRotation, 0.1f); // } // } void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { Animator anim = transform.GetComponentInChildren<Animator> (); if (stream.isWriting) { stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(anim.GetFloat("Forward")); stream.SendNext(anim.GetFloat("Turn")); stream.SendNext(anim.GetBool("OnGround")); stream.SendNext(anim.GetFloat("Jump")); stream.SendNext(anim.GetFloat("JumpLeg")); stream.SendNext(anim.GetBool("Guard")); stream.SendNext(anim.GetFloat("Block")); } else { this.correctPlayerPosition = (Vector3) stream.ReceiveNext(); this.correctPlayerRotation = (Quaternion) stream.ReceiveNext(); this.anim.SetFloat("Forward", (float) stream.ReceiveNext()); this.anim.SetFloat("Turn", (float) stream.ReceiveNext()); this.anim.SetBool("OnGround", (bool) stream.ReceiveNext()); this.anim.SetFloat("Jump", (float) stream.ReceiveNext()); this.anim.SetFloat("JumpLeg", (float) stream.ReceiveNext()); this.anim.SetBool("Guard", (bool) stream.ReceiveNext()); this.anim.SetFloat("Block", (float) stream.ReceiveNext()); } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting){ // this is our player, we send of posision data here stream.SendNext(transform.position); //send our posision to the network stream.SendNext(transform.rotation); // send our rotation to the network stream.SendNext(anim.GetFloat("Speed")); stream.SendNext(anim.GetBool("Jumping")); stream.SendNext(anim.GetFloat("AimAngle")); } else { //this is everyone elses players, we recieve their posisions here // right now realPosition holds the player position on the Last frame // instead of simply updating "RealPosition" and continuing to lerp // we MAY want to set out transform.position IMMEDIITLY to this old "realPosition" // then update realPosition realPosition = (Vector3)stream.ReceiveNext(); //recieve others posisions realRotation = (Quaternion)stream.ReceiveNext(); // recieve others rotations anim.SetFloat("Speed", (float)stream.ReceiveNext()); anim.SetBool("Jumping", (bool)stream.ReceiveNext()); realAimAngle = (float)stream.ReceiveNext(); if (gotFirstUpdate == false) { transform.position = realPosition; transform.rotation = realRotation; anim.SetFloat("AimAngle", realAimAngle); gotFirstUpdate = true; } } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting == true) { if (this.m_SynchronizeVelocity == true) { stream.SendNext(this.m_Body.velocity); } if (this.m_SynchronizeAngularVelocity == true) { stream.SendNext(this.m_Body.angularVelocity); } } else { if (this.m_SynchronizeVelocity == true) { this.m_Body.velocity = (Vector3)stream.ReceiveNext(); } if (this.m_SynchronizeAngularVelocity == true) { this.m_Body.angularVelocity = (Vector3)stream.ReceiveNext(); } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data // stream.SendNext((int)controllerScript._characterState); stream.SendNext(transform.position); stream.SendNext(transform.rotation); //stream.SendNext(GetComponent<Rigidbody>().velocity); } else { //Network player, receive data //controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext(); correctPlayerPos = (Vector3)stream.ReceiveNext(); correctPlayerRot = (Quaternion)stream.ReceiveNext(); //GetComponent<Rigidbody>().velocity = (Vector3)stream.ReceiveNext(); if (!appliedInitialUpdate) { appliedInitialUpdate = true; transform.position = correctPlayerPos; transform.rotation = correctPlayerRot; //GetComponent<Rigidbody>().velocity = Vector3.zero; } } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { // This is our player. We need to send our actual position to the network. stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(anim.GetFloat("Speed")); stream.SendNext(anim.GetBool("Jumping")); } else { // This is someone else's player. We need to reciece their position. // Right now, "realPosition" holds the other person's position at the LAST frame. // Instead of simply updating "realPosition" and continuing to lerp, //we MAY want to set our transform.position to immediately to this old "realPosition" //and then update realPosition realPosition = (Vector3)stream.ReceiveNext (); realRotation = (Quaternion)stream.ReceiveNext (); anim.SetFloat ("Speed", (float)stream.ReceiveNext() ); anim.SetBool ("Jumping", (bool)stream.ReceiveNext() ); if(gotFirstUpdate == false) { transform.position = realPosition; transform.rotation = realRotation; gotFirstUpdate = true; } } }
// this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector) public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { // Always send transform (depending on reliability of the network view) if (stream.isWriting) { Vector3 pos = transform.localPosition; Quaternion rot = transform.localRotation; stream.Serialize(ref pos); stream.Serialize(ref rot); } // When receiving, buffer the information else { // Receive latest state information Vector3 pos = Vector3.zero; Quaternion rot = Quaternion.identity; stream.Serialize(ref pos); stream.Serialize(ref rot); lastMovement = (pos - latestCorrectPos) / (Time.time - lastTime); lastTime = Time.time; latestCorrectPos = pos; transform.position = latestCorrectPos; } }
private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { //Debug.Log("============>"); if (stream.isWriting) { stream.SendNext(transform.position); PlayerController player = GetComponent<PlayerController>(); string blockName = player.currentBlock == null ? "" : player.currentBlock.name; stream.SendNext(blockName); } else { PlayerController player = GetComponent<PlayerController>(); this.playerPos = (Vector3)stream.ReceiveNext(); string currentBlock = (string)stream.ReceiveNext(); if (currentBlock != "") { player.transform.parent = null; } else { Node block = GameBoard.FindBlockByName(currentBlock); Debug.Log("===>"+block.name); player.transform.parent = block.transform; } transform.localPosition = this.playerPos; } }
/// <summary> /// Serializing the photon views /// </summary> /// <param name="stream"> the stream of information </param> /// <param name="info"> information about the messages </param> public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { // if it's us tell them where we are, else it's everyone else telling use where they are if (stream.isWriting) { // send pos stuff stream.SendNext(transform.position); stream.SendNext(transform.rotation); // send animation stuff stream.SendNext(Mathf.Abs(motor.movement.velocity.x)); stream.SendNext(motor.grounded); // Input info stream.SendNext(Input.GetButton("Jump")); stream.SendNext(Input.GetButtonUp("Fire1")); } else { // recieve pos realPos = (Vector3)stream.ReceiveNext(); realRot = (Quaternion)stream.ReceiveNext(); // receive anim info velocity = (float)stream.ReceiveNext(); onGround = (bool)stream.ReceiveNext(); // Input info jumping = (bool)stream.ReceiveNext(); shoot = (bool)stream.ReceiveNext(); } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data ControllerPlayer controllerScript = GetComponent<ControllerPlayer>(); stream.SendNext((int)controllerScript._characterState); stream.SendNext(transform.position); stream.SendNext(transform.rotation); Stats statsScript = GetComponent<Stats>(); stream.SendNext(statsScript.Health); stream.SendNext(statsScript.Lives); } else { //Network player, receive data this.correctPlayerPos = (Vector3)stream.ReceiveNext(); this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); ControllerPlayer controllerScript = GetComponent<ControllerPlayer>(); Stats statsScript = GetComponent<Stats>(); controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext(); statsScript.Health = (int)stream.ReceiveNext(); statsScript.Lives = (int)stream.ReceiveNext(); } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { Vector3 pos = transform.localPosition; Quaternion rot = transform.localRotation; stream.Serialize(ref pos); stream.Serialize(ref rot); } else { // Receive latest state information Vector3 pos = Vector3.zero; Quaternion rot = Quaternion.identity; stream.Serialize(ref pos); stream.Serialize(ref rot); this.latestCorrectPos = pos; // save this to move towards it in FixedUpdate() this.onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos this.fraction = 0; // reset the fraction we alreay moved. see Update() transform.localRotation = rot; // this sample doesn't smooth rotation } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data //stream.SendNext((int)controllerScript._characterState); //stream bool for grounded, float for running if (!cam.GetComponent<RTSCamera>()) { stream.SendNext(controllerScript.forwardInput); stream.SendNext(controllerScript.grounded); stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(controllerScript.velocity); } } else { //Network player, receive data //controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext(); //stream bool for grounded, float for running forwardInput = (float)stream.ReceiveNext(); grounded = (bool)stream.ReceiveNext(); correctPlayerPos = (Vector3)stream.ReceiveNext(); correctPlayerRot = (Quaternion)stream.ReceiveNext(); correctPlayerVelocity = (Vector3)stream.ReceiveNext(); } }
public void OnPhotonSerializeView(PhotonStream aStream, PhotonMessageInfo aInfo) { if (aStream.isWriting) { aStream.SendNext(transform.position); aStream.SendNext(transform.rotation.eulerAngles.z); aStream.SendNext(m_health); } else { m_photonPosition = (Vector3)aStream.ReceiveNext(); m_photonRotation = (float)aStream.ReceiveNext(); m_health = (int)aStream.ReceiveNext(); stopWatch.Stop(); if (stopWatch.ElapsedMilliseconds > (1000 / PhotonNetwork.sendRate)) { m_photonReleasedPositions.Add(new TimePosition(m_photonPosition, (float)stopWatch.ElapsedMilliseconds, m_photonRotation)); if (m_once && m_photonReleasedPositions.Count >= 4) { m_once = false; StartCoroutine("ReleasePositions"); } stopWatch.Reset(); } stopWatch.Start(); } }
public void SerializeState( PhotonStream stream, PhotonMessageInfo info ) { // Debug.Log ("Serialized State"); //We only need to synchronize a couple of variables to be able to recreate a good //approximation of the ships position on each client //There is a lot of smoke and mirrors happening here //Check out Part 1 Lesson 2 http://youtu.be/7hWuxxm6wsA for more detailed explanations if( stream.isWriting == true ) { Vector3 pos = transform.position; Quaternion rot = transform.rotation; stream.SendNext( pos ); stream.SendNext( rot ); } else { t=0; // achterlopende position naar nieuwe binnenkomende position lerpen startPosition = transform.position; m_NetworkPosition = (Vector3)stream.ReceiveNext(); m_NetworkRotation = (Quaternion)stream.ReceiveNext(); distance = Vector3.Distance(startPosition,m_NetworkPosition); time = distance/speed; m_LastNetworkDataReceivedTime = info.timestamp; } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //データの送信 stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(this.GetComponent<Renderer>().material.color.r); stream.SendNext(this.GetComponent<Renderer>().material.color.g); stream.SendNext(this.GetComponent<Renderer>().material.color.b); stream.SendNext(this.GetComponent<Renderer>().material.color.a); ti = Time.timeSinceLevelLoad; Debug.LogWarning("r = " + this.GetComponent<Renderer>().material.color.r + " g = " + this.GetComponent<Renderer>().material.color.g + " b = " + this.GetComponent<Renderer>().material.color.b + " a = " + this.GetComponent<Renderer>().material.color.a); } else { //データの受信 transform.position = (Vector3)stream.ReceiveNext(); transform.rotation = (Quaternion)stream.ReceiveNext(); float r = (float)stream.ReceiveNext(); float g = (float)stream.ReceiveNext(); float b = (float)stream.ReceiveNext(); float a = (float)stream.ReceiveNext(); ti = Time.timeSinceLevelLoad - ti; Debug.Log("r = " + r + " g = " + g + " b = " + b + " a = " + a); this.GetComponent<Renderer>().material.color = new Vector4(r, g, b, a); } }
private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data stream.SendNext(transform.position); stream.SendNext(transform.rotation); // animation data int[] animStates = _playerAnim.GetAnimationBooleans(); stream.SendNext(animStates[0]); stream.SendNext(animStates[1]); stream.SendNext(animStates[2]); } else { //Network player, receive data _correctPlayerPos = (Vector3)stream.ReceiveNext(); _correctPlayerRot = (Quaternion)stream.ReceiveNext(); // animation data _playerAnim.ApplyNetworkAnimations((int)stream.ReceiveNext(), (int)stream.ReceiveNext(), (int)stream.ReceiveNext()); syncTime = 0f; syncDelay = Time.time - lastSynchronizationTime; lastSynchronizationTime = Time.time; } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { UnityEngine.Debug.Log("point"); if (stream.isWriting) { var pointText = GameObject.Find("Point").GetComponent<Text>(); string point = pointText.text; // We own this player: send the others our data stream.SendNext(transform.position); stream.SendNext(transform.rotation); UnityEngine.Debug.Log(pointText.text); stream.SendNext(pointText.text); UnityEngine.Debug.Log("point2"); } else { // Network player, receive data this.correctPlayerPos = (Vector3)stream.ReceiveNext(); this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); UnityEngine.Debug.Log((Vector3)stream.ReceiveNext()); var pointText = GameObject.Find("EnemyPoint").GetComponent<Text>(); UnityEngine.Debug.Log("point3"); pointText.text = (string)stream.ReceiveNext(); } }
void HandleReceivingNetworkData(PhotonStream stream, PhotonMessageInfo info) { // Set initial positions instantly. if (!hasInitialUpdate) { isPlayerActive = true; transform.position = realPosition; transform.rotation = realRotation; animator = GetComponent<Animator> (); animator.SetFloat("Speed", 0); animator.SetBool("IsJumping", false); shield = GetComponent<Shield> (); shield.isActive = false; hasInitialUpdate = true; } // Receive updates from other players. gameObject.SetActive((bool)stream.ReceiveNext()); realPosition = (Vector3)stream.ReceiveNext(); realRotation = (Quaternion)stream.ReceiveNext(); animator.SetFloat("Speed", (float)stream.ReceiveNext()); animator.SetBool("IsJumping", (bool)stream.ReceiveNext()); shield.isActive = (bool)stream.ReceiveNext(); }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (PhotonNetwork.isMasterClient) { if (stream.isWriting) { // We own this player: send the others our data stream.SendNext (transform.position); stream.SendNext (transform.rotation); //stream.SendNext (this.GetComponent<DumbStates> ().signalLeft); //stream.SendNext (this.GetComponent<DumbStates> ().signalRight); } } else { // Network player, receive data CorrectPos = (Vector3)stream.ReceiveNext (); CorrectRot = (Quaternion)stream.ReceiveNext (); //signalLeft = (bool)stream.ReceiveNext (); //signalRight = (bool)stream.ReceiveNext (); if (!SignalON && (signalLeft || signalRight)) { if (signalLeft) { //this.GetComponent<DumbStates> ().onLTS (); } if (signalRight) { //this.GetComponent<DumbStates> ().onRTS (); } SignalON = true; } if (SignalON && !(signalLeft || signalRight)) { //this.GetComponent<DumbStates> ().offTurnSignals(); SignalON=false; } } }
/// <summary> /// serialization method of photon /// </summary> /// <param name="stream"></param> /// <param name="info"></param> public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { m_PositionControl.OnPhotonSerializeView(transform.position, stream, info); m_RotationControl.OnPhotonSerializeView(transform.rotation, stream, info); m_ScaleControl.OnPhotonSerializeView(transform.localScale, stream, info); if (isMine == false && m_PositionModel.DrawErrorGizmo == true) { DoDrawEstimatedPositionError(); } if (stream.isWriting) { //We own this player: send the others our data stream.SendNext(gameObject.name); stream.SendNext(HeatTarget.position); stream.SendNext(HeatTarget.rotation); stream.SendNext(Controller.m_PlayerState); stream.SendNext(Controller.grounded); } else { //Network player, receive data RemotePlayerName = (string)stream.ReceiveNext(); HeadPos = (Vector3)stream.ReceiveNext(); HeadRot = (Quaternion)stream.ReceiveNext(); m_state = (PlayerState)stream.ReceiveNext(); m_grounded = (bool)stream.ReceiveNext(); // m_ReceivedNetworkUpdate = true; } }
//Serilize Data Across the network, we want everyone to know where they are void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { //Send to everyone else a local players variables to be synced and recieved by all other players on network if (stream.isWriting) { //send to clients where we are stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(health); //Sync Animation States } else { //Get from clients where they are //Write in the same order we read, if not writing we are reading. realPosition = (Vector3)stream.ReceiveNext(); realRotation = (Quaternion)stream.ReceiveNext(); health = (float)stream.ReceiveNext(); //Sync Animation States } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { Vector3 pos = transform.localPosition; Quaternion rot = transform.localRotation; stream.Serialize(ref pos); stream.Serialize(ref rot); } else { Vector3 pos = Vector3.zero; Quaternion rot = Quaternion.identity; stream.Serialize(ref pos); stream.Serialize(ref rot); latestCorrectPos = pos; onUpdatePos = transform.localPosition; fraction = 0; transform.localRotation = rot; } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { // this is my player. need to send my actual position to the network stream.SendNext(transform.position); stream.SendNext(_charController.velocity); stream.SendNext(transform.rotation); } else { //this is another player. need to get his position data. then update my version of this player Vector3 syncPosition = (Vector3)stream.ReceiveNext(); Vector3 syncVelocity = (Vector3)stream.ReceiveNext(); syncEndRotation = (Quaternion)stream.ReceiveNext(); syncStartRotation = transform.rotation; syncTime = 0f; syncDelay = Time.time - lastSynchronizationTime; lastSynchronizationTime = Time.time; syncEndPosition = syncPosition + syncVelocity * syncDelay; syncStartPosition = transform.position; } }
// this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector) public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // the controlling player of a cube sends only the position Vector3 pos = transform.localPosition; stream.Serialize(ref pos); } else { // other players (not controlling this cube) will read the position and timing and calculate everything else based on this Vector3 updatedLocalPos = Vector3.zero; stream.Serialize(ref updatedLocalPos); double timeDiffOfUpdates = info.timestamp - this.lastTime; // the time that passed after the sender sent it's previous update this.lastTime = info.timestamp; // the movementVector calculates how far the "original" cube moved since it sent the last update. // we calculate this based on the sender's timing, so we exclude network lag. that makes our movement smoother. this.movementVector = (updatedLocalPos - this.latestCorrectPos) / (float)timeDiffOfUpdates; // the errorVector is how far our cube is away from the incoming position update. using this corrects errors somewhat, until the next update arrives. // with this, we don't have to correct our cube's position with a new update (which introduces visible, hard stuttering). this.errorVector = (updatedLocalPos - transform.localPosition) / (float)timeDiffOfUpdates; // next time we get an update, we need this update's position: this.latestCorrectPos = updatedLocalPos; } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data stream.SendNext((int)controllerScript._characterState); stream.SendNext(transform.position); stream.SendNext(transform.rotation); } else { //Network player, receive data controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext(); correctPlayerPos = (Vector3)stream.ReceiveNext(); correctPlayerRot = (Quaternion)stream.ReceiveNext(); // avoids lerping the character from "center" to the "current" position when this client joins if (firstTake) { firstTake = false; this.transform.position = correctPlayerPos; transform.rotation = correctPlayerRot; } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { stream.SendNext(transform.position); stream.SendNext(transform.rotation); if(anim.IsPlaying("Run")) { stream.SendNext(useThisMove = 1); } if(anim.IsPlaying ("Idle")) { stream.SendNext (useThisMove = -1); } if(anim.IsPlaying ("AutoAttack")) { stream.SendNext(useThisMove = -2); } } else { realPosition = (Vector3)stream.ReceiveNext(); realRotation = (Quaternion)stream.ReceiveNext(); useThisMove = (int)stream.ReceiveNext(); } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { stream.SendNext(transform.position); } else { position = (Vector3)stream.ReceiveNext(); } }
/// <summary> /// While script is observed (in a PhotonView), this is called by PUN with a stream to write or read. /// </summary> /// <remarks> /// The property stream.isWriting is true for the owner of a PhotonView. This is the only client that /// should write into the stream. Others will receive the content written by the owner and can read it. /// /// Note: Send only what you actually want to consume/use, too! /// Note: If the owner doesn't write something into the stream, PUN won't send anything. /// </remarks> /// <param name="stream">Read or write stream to pass state of this GameObject (or whatever else).</param> /// <param name="info">Some info about the sender of this stream, who is the owner of this PhotonView (and GameObject).</param> void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { Debug.Log ("OnPhotonSerializeView"); if (stream.isWriting) { Vector3 pos = transform.localPosition; Quaternion rot = transform.localRotation; stream.Serialize(ref pos); stream.Serialize(ref rot); stream.Serialize(ref playerId); int _st = (int)stoneType; stream.Serialize(ref _st); } else { // Receive latest state information Vector3 pos = Vector3.zero; Quaternion rot = Quaternion.identity; int _st = (int)stoneType; stream.Serialize(ref pos); stream.Serialize(ref rot); stream.Serialize(ref playerId); stream.Serialize(ref _st); latestCorrectPos = pos; // save this to move towards it in FixedUpdate() onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos fraction = 0; // reset the fraction we alreay moved. see Update() transform.localRotation = rot; // this sample doesn't smooth rotation stoneType = (StoneType)_st; } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // write time & position to stream stream.SendNext(PhotonNetwork.time); // send orientation stream.SendNext((double)transform.rotation.eulerAngles.y); // get Y-rotation } else { // receive keyframe double time = (double)stream.ReceiveNext(); double orientation = (double)stream.ReceiveNext(); if (m_OrientationKeyframesList == null) m_OrientationKeyframesList = new KeyframeList<double>(); m_OrientationKeyframesList.Add(time, orientation); if (m_OrientationKeyframesList.Count > 2) { //Debug.Log("removing old keyframes"); // remove old keyframes ( let's say 5 seconds old? ) m_OrientationKeyframesList.RemoveAllBefore(time - 5); } } }
// Token: 0x06004F4D RID: 20301 RVA: 0x001AC7DA File Offset: 0x001AABDA private void SerializeVector(PhotonStream stream, Vector3 vect) { Serialization.SerializeVector(stream, vect); }
public abstract void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info);
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { //throw new NotImplementedException(); }
// Token: 0x06004F51 RID: 20305 RVA: 0x001AC7FC File Offset: 0x001AABFC public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { PoseRecorder.PoseEvent poseEvent = new PoseRecorder.PoseEvent(); if (stream.isWriting) { if (this.ragDoll != null && this.ragDoll.IsRagDolled) { PoseRecorder.poseContents = 0; } poseEvent.poseContents = PoseRecorder.poseContents; PoseRecorder.poseContents = 0; stream.SendNext((short)poseEvent.poseContents); if (poseEvent.Contains(PoseRecorder.PoseContents.RootOffset)) { poseEvent.rootOffset = this.offset.position; this.SerializeVector(stream, poseEvent.rootOffset); } if (poseEvent.Contains(PoseRecorder.PoseContents.BaseSkeleton)) { for (int i = 0; i < this.bones.Length; i++) { poseEvent.boneRotations[i] = ((!(this.bones[i] == null)) ? this.bones[i].rotation : Quaternion.identity); this.SerializeQuaternion(stream, poseEvent.boneRotations[i]); } } if (poseEvent.Contains(PoseRecorder.PoseContents.HandGesture)) { int num = 255; int num2 = 255; if (this.handgest != null) { this.handgest.GetRemoteHandGestures(out num, out num2); } stream.SendNext((byte)num); stream.SendNext((byte)num2); } if (poseEvent.Contains(PoseRecorder.PoseContents.HandEffectorPositionOrientationL)) { if (this.ik != null) { this.ik.GetHandEffectorLeft(out poseEvent.leftHandPosition, out poseEvent.leftHandRotation); } this.SerializeVector(stream, poseEvent.leftHandPosition); this.SerializeQuaternion(stream, poseEvent.leftHandRotation); } if (poseEvent.Contains(PoseRecorder.PoseContents.HandEffectorPositionOrientationR)) { if (this.ik != null) { this.ik.GetHandEffectorRight(out poseEvent.rightHandPosition, out poseEvent.rightHandRotation); } this.SerializeVector(stream, poseEvent.rightHandPosition); this.SerializeQuaternion(stream, poseEvent.rightHandRotation); } if (poseEvent.Contains(PoseRecorder.PoseContents.HeadEffectorPositionOrientation)) { if (this.ik != null) { this.ik.GetHeadEffector(out poseEvent.headPosition, out poseEvent.headRotation); } this.SerializeVector(stream, poseEvent.headPosition); this.SerializeQuaternion(stream, poseEvent.headRotation); } if (poseEvent.Contains(PoseRecorder.PoseContents.HipEffectorPositionOrientation)) { if (this.ik != null) { this.ik.GetHipEffector(out poseEvent.hipPosition, out poseEvent.hipRotation); } this.SerializeVector(stream, poseEvent.hipPosition); this.SerializeQuaternion(stream, poseEvent.hipRotation); } if (poseEvent.Contains(PoseRecorder.PoseContents.FootEffectorPositionOrientationL)) { if (this.ik != null) { this.ik.GetFootEffectorLeft(out poseEvent.leftFootPosition, out poseEvent.leftFootRotation); } this.SerializeVector(stream, poseEvent.leftFootPosition); this.SerializeQuaternion(stream, poseEvent.leftFootRotation); } if (poseEvent.Contains(PoseRecorder.PoseContents.FootEffectorPositionOrientationR)) { if (this.ik != null) { this.ik.GetFootEffectorRight(out poseEvent.rightFootPosition, out poseEvent.rightFootRotation); } this.SerializeVector(stream, poseEvent.rightFootPosition); this.SerializeQuaternion(stream, poseEvent.rightFootRotation); } } else { poseEvent.poseContents = (int)((short)stream.ReceiveNext()); if (poseEvent.Contains(PoseRecorder.PoseContents.RootOffset)) { poseEvent.rootOffset = this.DeserializeVector(stream); } if (poseEvent.Contains(PoseRecorder.PoseContents.BaseSkeleton)) { for (int j = 0; j < this.bones.Length; j++) { poseEvent.boneRotations[j] = this.DeserializeQuaternion(stream); } } if (poseEvent.Contains(PoseRecorder.PoseContents.HandGesture)) { poseEvent.handGestureLeft = (byte)stream.ReceiveNext(); poseEvent.handGestureRight = (byte)stream.ReceiveNext(); } if (poseEvent.Contains(PoseRecorder.PoseContents.HandEffectorPositionOrientationL)) { poseEvent.leftHandPosition = this.DeserializeVector(stream); poseEvent.leftHandRotation = this.DeserializeQuaternion(stream); } if (poseEvent.Contains(PoseRecorder.PoseContents.HandEffectorPositionOrientationR)) { poseEvent.rightHandPosition = this.DeserializeVector(stream); poseEvent.rightHandRotation = this.DeserializeQuaternion(stream); } if (poseEvent.Contains(PoseRecorder.PoseContents.HeadEffectorPositionOrientation)) { poseEvent.headPosition = this.DeserializeVector(stream); poseEvent.headRotation = this.DeserializeQuaternion(stream); } if (poseEvent.Contains(PoseRecorder.PoseContents.HipEffectorPositionOrientation)) { poseEvent.hipPosition = this.DeserializeVector(stream); poseEvent.hipRotation = this.DeserializeQuaternion(stream); } if (poseEvent.Contains(PoseRecorder.PoseContents.FootEffectorPositionOrientationL)) { poseEvent.leftFootPosition = this.DeserializeVector(stream); poseEvent.leftFootRotation = this.DeserializeQuaternion(stream); } if (poseEvent.Contains(PoseRecorder.PoseContents.FootEffectorPositionOrientationR)) { poseEvent.rightFootPosition = this.DeserializeVector(stream); poseEvent.rightFootRotation = this.DeserializeQuaternion(stream); } } poseEvent.timeReceived = (double)Time.time; TweenFunctions.RecordValue <PoseRecorder.PoseEvent>(this.eventHistory, poseEvent); }
// Token: 0x06004F50 RID: 20304 RVA: 0x001AC7F4 File Offset: 0x001AABF4 private Quaternion DeserializeQuaternion(PhotonStream stream) { return(Serialization.DeserializeQuaternion(stream)); }
// Token: 0x06004F4F RID: 20303 RVA: 0x001AC7EB File Offset: 0x001AABEB private void SerializeQuaternion(PhotonStream stream, Quaternion quat) { Serialization.SerializeQuaternion(stream, quat); }
// Token: 0x06004F4E RID: 20302 RVA: 0x001AC7E3 File Offset: 0x001AABE3 private Vector3 DeserializeVector(PhotonStream stream) { return(Serialization.DeserializeVector(stream)); }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { }
protected internal void DeserializeComponent(Component component, PhotonStream stream, PhotonMessageInfo info) { if (component == null) { return; } // Use incoming data according to observed type if (component is MonoBehaviour) { ExecuteComponentOnSerialize(component, stream, info); } else if (component is Transform) { Transform trans = (Transform)component; switch (this.onSerializeTransformOption) { case OnSerializeTransform.All: trans.localPosition = (Vector3)stream.ReceiveNext(); trans.localRotation = (Quaternion)stream.ReceiveNext(); trans.localScale = (Vector3)stream.ReceiveNext(); break; case OnSerializeTransform.OnlyPosition: trans.localPosition = (Vector3)stream.ReceiveNext(); break; case OnSerializeTransform.OnlyRotation: trans.localRotation = (Quaternion)stream.ReceiveNext(); break; case OnSerializeTransform.OnlyScale: trans.localScale = (Vector3)stream.ReceiveNext(); break; case OnSerializeTransform.PositionAndRotation: trans.localPosition = (Vector3)stream.ReceiveNext(); trans.localRotation = (Quaternion)stream.ReceiveNext(); break; } } else if (component is Rigidbody) { Rigidbody rigidB = (Rigidbody)component; switch (this.onSerializeRigidBodyOption) { case OnSerializeRigidBody.All: rigidB.velocity = (Vector3)stream.ReceiveNext(); rigidB.angularVelocity = (Vector3)stream.ReceiveNext(); break; case OnSerializeRigidBody.OnlyAngularVelocity: rigidB.angularVelocity = (Vector3)stream.ReceiveNext(); break; case OnSerializeRigidBody.OnlyVelocity: rigidB.velocity = (Vector3)stream.ReceiveNext(); break; } } else if (component is Rigidbody2D) { Rigidbody2D rigidB = (Rigidbody2D)component; switch (this.onSerializeRigidBodyOption) { case OnSerializeRigidBody.All: rigidB.velocity = (Vector2)stream.ReceiveNext(); rigidB.angularVelocity = (float)stream.ReceiveNext(); break; case OnSerializeRigidBody.OnlyAngularVelocity: rigidB.angularVelocity = (float)stream.ReceiveNext(); break; case OnSerializeRigidBody.OnlyVelocity: rigidB.velocity = (Vector2)stream.ReceiveNext(); break; } } else { Debug.LogError("Type of observed is unknown when receiving."); } }
public abstract void Serialize(PhotonStream stream, PhotonMessageInfo info);
/** * OnPhotonSerializeView- syncs player movement across all clients */ public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { networkScript.myOnPhotonSerializeView(stream, info); }
protected internal void SerializeComponent(Component component, PhotonStream stream, PhotonMessageInfo info) { if (component == null) { return; } if (component is MonoBehaviour) { ExecuteComponentOnSerialize(component, stream, info); } else if (component is Transform) { Transform trans = (Transform)component; switch (this.onSerializeTransformOption) { case OnSerializeTransform.All: stream.SendNext(trans.localPosition); stream.SendNext(trans.localRotation); stream.SendNext(trans.localScale); break; case OnSerializeTransform.OnlyPosition: stream.SendNext(trans.localPosition); break; case OnSerializeTransform.OnlyRotation: stream.SendNext(trans.localRotation); break; case OnSerializeTransform.OnlyScale: stream.SendNext(trans.localScale); break; case OnSerializeTransform.PositionAndRotation: stream.SendNext(trans.localPosition); stream.SendNext(trans.localRotation); break; } } else if (component is Rigidbody) { Rigidbody rigidB = (Rigidbody)component; switch (this.onSerializeRigidBodyOption) { case OnSerializeRigidBody.All: stream.SendNext(rigidB.velocity); stream.SendNext(rigidB.angularVelocity); break; case OnSerializeRigidBody.OnlyAngularVelocity: stream.SendNext(rigidB.angularVelocity); break; case OnSerializeRigidBody.OnlyVelocity: stream.SendNext(rigidB.velocity); break; } } else if (component is Rigidbody2D) { Rigidbody2D rigidB = (Rigidbody2D)component; switch (this.onSerializeRigidBodyOption) { case OnSerializeRigidBody.All: stream.SendNext(rigidB.velocity); stream.SendNext(rigidB.angularVelocity); break; case OnSerializeRigidBody.OnlyAngularVelocity: stream.SendNext(rigidB.angularVelocity); break; case OnSerializeRigidBody.OnlyVelocity: stream.SendNext(rigidB.velocity); break; } } else { Debug.LogError("Observed type is not serializable: " + component.GetType()); } }
// Token: 0x06000572 RID: 1394 RVA: 0x0001F0CC File Offset: 0x0001D2CC private void DeserializeDataDiscretly(PhotonStream stream) { for (int i = 0; i < this.m_SynchronizeLayers.Count; i++) { if (this.m_SynchronizeLayers[i].SynchronizeType == PhotonAnimatorView.SynchronizeType.Discrete) { this.m_Animator.SetLayerWeight(this.m_SynchronizeLayers[i].LayerIndex, (float)stream.ReceiveNext()); } } for (int j = 0; j < this.m_SynchronizeParameters.Count; j++) { PhotonAnimatorView.SynchronizedParameter synchronizedParameter = this.m_SynchronizeParameters[j]; if (synchronizedParameter.SynchronizeType == PhotonAnimatorView.SynchronizeType.Discrete) { PhotonAnimatorView.ParameterType type = synchronizedParameter.Type; switch (type) { case PhotonAnimatorView.ParameterType.Float: if (!(stream.PeekNext() is float)) { return; } this.m_Animator.SetFloat(synchronizedParameter.Name, (float)stream.ReceiveNext()); break; case (PhotonAnimatorView.ParameterType) 2: break; case PhotonAnimatorView.ParameterType.Int: if (!(stream.PeekNext() is int)) { return; } this.m_Animator.SetInteger(synchronizedParameter.Name, (int)stream.ReceiveNext()); break; case PhotonAnimatorView.ParameterType.Bool: if (!(stream.PeekNext() is bool)) { return; } this.m_Animator.SetBool(synchronizedParameter.Name, (bool)stream.ReceiveNext()); break; default: if (type == PhotonAnimatorView.ParameterType.Trigger) { if (!(stream.PeekNext() is bool)) { return; } if ((bool)stream.ReceiveNext()) { this.m_Animator.SetTrigger(synchronizedParameter.Name); } } break; } } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { //Debug.Log("syncing"); if (stream.isWriting) { // rotation stream.SendNext(transform.position); // position stream.SendNext(transform.rotation); // animator.Speed stream.SendNext(animator.GetFloat("Speed")); // animator.toTrigger //if (skillManager.enabled) //{ // stream.SendNext(skillManager.currentSkill); // skillManager.currentSkill = "NOSKILL"; //} else //{ // stream.SendNext("NOSKILL"); //} // am I dead? stream.SendNext(playerManager.dead); // team id stream.SendNext(playerManager.teamId); // username stream.SendNext(playerManager.username); // health stream.SendNext(playerManager.health); // kills stream.SendNext(playerManager.kills); // deaths stream.SendNext(playerManager.deaths); } else { receivedPosition = (Vector3)stream.ReceiveNext(); receivedRotation = (Quaternion)stream.ReceiveNext(); float speed = (float)stream.ReceiveNext(); animator.SetFloat("Speed", speed); //string skill = (string)stream.ReceiveNext(); //if (!skill.Equals("NOSKILL")) //{ // animator.SetTrigger(skill); //} isDead = (bool)stream.ReceiveNext(); if (isDead && !deathAnimationPlaying) { animator.SetTrigger("Death"); deathAnimationPlaying = true; } if (!isDead && deathAnimationPlaying) { animator.SetTrigger("Respawn"); deathAnimationPlaying = false; } receivedTeamId = (int)stream.ReceiveNext(); receivedUsername = (string)stream.ReceiveNext(); receivedHealth = (float)stream.ReceiveNext(); receivedKills = (int)stream.ReceiveNext(); receivedDeaths = (int)stream.ReceiveNext(); } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { // Method not really needed, but needs to be overridden due to IPunObservable }
// this function is called several times per second, the master client writes to the stream while the other client reads the data the master client wrote several times a second // once each player has sent or recieved the data, they run the logic of the guard animation themselves public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { // master client sends whether the guard animation is chasing, walking and the guard's current velocity if (stream.IsWriting) { //Debug.Log("SPEED ANIM " + guard.speed); bool isWalking = animator.GetBool(isWalkingHash); bool isChasing = animator.GetBool(isChasingHash); bool hasCaught = animator.GetBool(hasCaughtHash); stream.SendNext(guard.velocity); stream.SendNext(isWalking); stream.SendNext(isChasing); if ((Mathf.Abs(guard.velocity.z) > 0.2f || Mathf.Abs(guard.velocity.x) > 0.2f) && !chasingPlayer) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, true); animator.SetBool(hasCaughtHash, false); } else if ((isWalking || isChasing) && (Mathf.Abs(guard.velocity.z) <= 0.2f || Mathf.Abs(guard.velocity.x) <= 0.2f)) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, false); animator.SetBool(hasCaughtHash, true); } if (chasingPlayer && (Mathf.Abs(guard.velocity.z) > 0.2f || Mathf.Abs(guard.velocity.x) > 0.2f)) { animator.SetBool(isChasingHash, true); animator.SetBool(isWalkingHash, true); animator.SetBool(hasCaughtHash, false); } else if (isChasing && !chasingPlayer) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, true); animator.SetBool(hasCaughtHash, false); } else if (chasingPlayer && (Mathf.Abs(guard.velocity.z) <= 0.2f || Mathf.Abs(guard.velocity.x) <= 0.2f)) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, false); animator.SetBool(hasCaughtHash, true); } } // other client sends whether the guard animation is chasing, walking and the guard's current velocity else if (stream.IsReading) { Vector3 velocity = (Vector3)stream.ReceiveNext(); bool isWalking = (bool)stream.ReceiveNext(); bool isChasing = (bool)stream.ReceiveNext(); if ((Mathf.Abs(velocity.z) > 0.2f || Mathf.Abs(velocity.x) > 0.2f) && !chasingPlayer) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, true); animator.SetBool(hasCaughtHash, false); } else if ((isWalking || isChasing) && (Mathf.Abs(velocity.z) <= 0.2f || Mathf.Abs(velocity.x) <= 0.2f)) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, false); animator.SetBool(hasCaughtHash, true); } if (chasingPlayer && (Mathf.Abs(velocity.z) > 0.2f || Mathf.Abs(velocity.x) > 0.2f)) { animator.SetBool(isChasingHash, true); animator.SetBool(isWalkingHash, true); animator.SetBool(hasCaughtHash, false); } else if (isChasing && !chasingPlayer) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, true); animator.SetBool(hasCaughtHash, false); } else if (chasingPlayer && (Mathf.Abs(velocity.z) <= 0.2f || Mathf.Abs(velocity.x) <= 0.2f)) { animator.SetBool(isChasingHash, false); animator.SetBool(isWalkingHash, false); animator.SetBool(hasCaughtHash, true); } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { SerializeState(stream, info); uMovement.SerializeState(stream, info); }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { //We own this player: send the others our data stream.SendNext(this.transform.position); stream.SendNext(this.transform.rotation); stream.SendNext(m_turret.transform.rotation); stream.SendNext(m_weapons.transform.rotation); stream.SendNext(this.HitPlayer); stream.SendNext(Flags.Encode(new bool[] { this.HasTeleported, this.HasShot, this.SideShot == 1, this.HasHit, this.AddBulletHit })); if (this.AddBulletHit) { stream.SendNext(this.BulletHitLocation); } // Reset flags this.HasTeleported = false; this.HasShot = false; this.HasHit = false; this.AddBulletHit = false; } else { //Network player, receive data m_targetPosition = (Vector3)stream.ReceiveNext(); m_targetRotation = (Quaternion)stream.ReceiveNext(); m_targetTurretRotation = (Quaternion)stream.ReceiveNext(); m_targetWeaponRotation = (Quaternion)stream.ReceiveNext(); this.HitPlayer = (int)stream.ReceiveNext(); int read = (int)stream.ReceiveNext(); bool[] flags = Flags.Decode(read, 5); var didPortal = flags[0]; this.HasShot = flags[1]; this.SideShot = flags[2] ? 1 : 0; this.HasHit = flags[3]; this.AddBulletHit = flags[4]; if (this.AddBulletHit) { this.BulletHitLocation = (Vector3)stream.ReceiveNext(); } if (!m_hasPosition || didPortal) { m_lastPosition = m_targetPosition; m_lastRotation = m_targetRotation; m_lastTurretRotation = m_targetRotation; m_hasPosition = true; } else { m_lastPosition = this.transform.position; m_lastRotation = this.transform.rotation; m_lastTurretRotation = this.m_turret.transform.rotation; } m_lerpTime = 0.0f; m_hasData = true; } }
public void ReceiveElement <T>(PhotonStream stream, ref T _element) => _element = (T)stream.ReceiveNext();
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { // This stream is sending and receiving data to a PhotonView observable if (stream.IsWriting) { // If true, this means the photon view is running on my device and I'm the one to who // Controls this player. We should send our position & rotation data to the the "REMOTE ME" // Which is the version of my player on other peoples devices // NOTE - We extract our own battle arena position so that users can apply theirs. stream.SendNext(rb.position - battleArenaGameObject.transform.position); stream.SendNext(rb.rotation); if (synchronizeVelocity) { stream.SendNext(rb.velocity); } if (synchronizeAngularVelocity) { stream.SendNext(rb.angularVelocity); } } else { // If false, it means the stream is reading. Meaning we're listening to other players. // NOTE - We add our battle arena postion as offset to the other users position networkPosition = (Vector3)stream.ReceiveNext() + battleArenaGameObject.transform.position; networkRotation = (Quaternion)stream.ReceiveNext(); if (isTeleportEnabled) { // If the distance between local & network position is higher than // our teleport threshold, teleport! if (Vector3.Distance(rb.position, networkPosition) > teleportIfDistanceGreaterThan) { rb.position = networkPosition; } } // This segment aims to conpensate the lag caused by the network // See https://doc.photonengine.com/en-us/pun/v2/gameplay/lagcompensation if (synchronizeVelocity || synchronizeAngularVelocity) { // PhotonNetwork = Time accross all devices synced (server time) // SentServerTime = Time where information hads been sent float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.SentServerTime)); if (synchronizeVelocity) { rb.velocity = (Vector3)stream.ReceiveNext(); // Note: The velocity is in meters per second // Timing it by the lag reduces the disrepency networkPosition += rb.velocity * lag; // This distance represent the difference between local position & network position distance = Vector3.Distance(rb.position, networkPosition); } if (synchronizeAngularVelocity) { rb.angularVelocity = (Vector3)stream.ReceiveNext(); networkRotation = Quaternion.Euler(rb.angularVelocity * lag) * networkRotation; angle = Quaternion.Angle(rb.rotation, networkRotation); } } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { //Esta funcion solo es por un fallo que da en el juego Debug.Log("[NetworkManager][OnPhotonSerializeView]" + info.ToString()); }
//----------------------------------------------------------------------------------------------- public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { //플레이어 이름 for (int i = 0; i < playerName.Count; i++) { if (i > playerName.Count - 1) { continue; } stream.SendNext(playerName[i]); } //HP 동기화 for (int i = 0; i < playerHp.Count; i++) { if (i > playerHp.Count - 1) { continue; } stream.SendNext(playerHp[i]); } //킬수 동기화 for (int i = 0; i < playerKill.Count; i++) { if (i > playerKill.Count - 1) { continue; } stream.SendNext(playerKill[i]); } //죽은 횟수 동기화 for (int i = 0; i < playerDead.Count; i++) { if (i > playerDead.Count - 1) { continue; } stream.SendNext(playerDead[i]); } //나를 누가 죽였는지 동기화 for (int i = 0; i < whoPlayerDied.Count; i++) { if (i > whoPlayerDied.Count - 1) { continue; } stream.SendNext(whoPlayerDied[i]); } //내가 누구를 죽였는지 동기화 for (int i = 0; i < whoPlayerKilled.Count; i++) { if (i > whoPlayerKilled.Count - 1) { continue; } stream.SendNext(whoPlayerKilled[i]); } //Dead True/False Check for (int i = 0; i < isPlayerKill.Count; i++) { if (i > isPlayerKill.Count - 1) { continue; } stream.SendNext(isPlayerKill[i]); } //Kill True/False Check for (int i = 0; i < isPlayerDead.Count; i++) { if (i > isPlayerDead.Count - 1) { continue; } stream.SendNext(isPlayerDead[i]); } } //동기화한것들 클라이언트들에게 넘겨주기 else { for (int i = 0; i < playerName.Count; i++) { if (i > playerName.Count - 1) { continue; } playerName[i] = (string)stream.ReceiveNext(); } for (int i = 0; i < playerHp.Count; i++) { if (i > playerHp.Count - 1) { continue; } playerHp[i] = (int)stream.ReceiveNext(); } for (int i = 0; i < playerKill.Count; i++) { if (i > playerKill.Count - 1) { continue; } playerKill[i] = (int)stream.ReceiveNext(); } for (int i = 0; i < playerDead.Count; i++) { if (i > playerDead.Count - 1) { continue; } playerDead[i] = (int)stream.ReceiveNext(); } for (int i = 0; i < whoPlayerDied.Count; i++) { if (i > whoPlayerDied.Count - 1) { continue; } whoPlayerDied[i] = (int)stream.ReceiveNext(); } for (int i = 0; i < whoPlayerKilled.Count; i++) { if (i > whoPlayerKilled.Count - 1) { continue; } whoPlayerKilled[i] = (int)stream.ReceiveNext(); } for (int i = 0; i < isPlayerKill.Count; i++) { if (i > isPlayerKill.Count - 1) { continue; } isPlayerKill[i] = (bool)stream.ReceiveNext(); } for (int i = 0; i < isPlayerDead.Count; i++) { if (i > isPlayerDead.Count - 1) { continue; } isPlayerDead[i] = (bool)stream.ReceiveNext(); } } }
public virtual void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { Loger.LogFormat("OnPhotonSerializeView stream.isWriting={0}", stream.isWriting); }
public void SendElement <T>(PhotonStream stream, T _element) => stream.SendNext(_element);
public override void Serialize(PhotonStream stream, PhotonMessageInfo info) { stream.SendNext(currentHealth); stream.SendNext(isDead); }
private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { onPhotonSerializeView?.OnNext(new Tuple <PhotonStream, PhotonMessageInfo>(stream, info)); }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(playerNum); stream.SendNext(playerName); stream.SendNext(playerHP); //stream.SendNext(playerHPText); stream.SendNext(startingPlayerHP); stream.SendNext(maxPlayerHP); stream.SendNext(playerState); stream.SendNext(selectedAction); stream.SendNext(rawDeckData); //stream.SendNext(deck); //stream.SendNext(hand); //stream.SendNext(activeCard); //stream.SendNext(cookBaseCard); //stream.SendNext(cookSpiceCard); //stream.SendNext(playerPlatePanel); //stream.SendNext(bench); //stream.SendNext(discardPile); //stream.SendNext(playerDeckPanel); //stream.SendNext(playerBenchPanel); //stream.SendNext(playerDeckInfo); stream.SendNext(deckFinishedBuilding); for (int i = 0; i < handBools.Length; i++) { stream.SendNext(handBools[i]); } } else { playerNum = (int)stream.ReceiveNext(); playerName = (string)stream.ReceiveNext(); playerHP = (int)stream.ReceiveNext(); //playerHPText = (Text)stream.ReceiveNext(); startingPlayerHP = (int)stream.ReceiveNext(); maxPlayerHP = (int)stream.ReceiveNext(); playerState = (PlayerState)stream.ReceiveNext(); selectedAction = (Action)stream.ReceiveNext(); rawDeckData = (string)stream.ReceiveNext(); //deck = (Stack<Card>)stream.ReceiveNext(); //hand = (Card[])stream.ReceiveNext(); //activeCard = (Card)stream.ReceiveNext(); //cookBaseCard = (Card)stream.ReceiveNext(); //cookSpiceCard = (Card)stream.ReceiveNext(); //playerPlatePanel = (GameObject)stream.ReceiveNext(); //bench = (Card[])stream.ReceiveNext(); //discardPile = (Stack<Card>)stream.ReceiveNext(); //playerDeckPanel = (GameObject)stream.ReceiveNext(); //playerBenchPanel = (GameObject)stream.ReceiveNext(); //playerDeckInfo = (Text)stream.ReceiveNext(); deckFinishedBuilding = (bool)stream.ReceiveNext(); for (int i = 0; i < handBools.Length; i++) { handBools[i] = (bool)stream.ReceiveNext(); } } }
//ON PHOTON SERIALIZE VIEW protected virtual void OnPhotonSerializeView(PhotonStream _stream, PhotonMessageInfo _messageInfo) { }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { stream.SendNext(playerInfo.moved); stream.SendNext(playerInfo.attacked); stream.SendNext(playerInfo.slowed); stream.SendNext(playerInfo.shocked); stream.SendNext(playerInfo.hasted); stream.SendNext(playerInfo.stunned); stream.SendNext(playerInfo.evading); stream.SendNext(playerInfo.cardsPlayed); stream.SendNext(playerInfo.turnDistanceTraveled); stream.SendNext(playerInfo.stillStandingTurns); stream.SendNext(playerInfo.nextAtkSlows); stream.SendNext(playerInfo.nextAtkShocks); stream.SendNext(playerInfo.nextFreeMove); stream.SendNext(playerInfo.nextFreeBasic); //stream.SendNext(playerInfo.maxHp); stream.SendNext(playerInfo.health); playerManager.UpdateAHBText(); //stream.SendNext(playerInfo.attack); stream.SendNext(playerInfo.block); playerManager.UpdateAHBText(); stream.SendNext(playerInfo.resolve); //stream.SendNext(playerInfo.basicRange); stream.SendNext(playerInfo.basicIsStraight); stream.SendNext(playerInfo.basicIsPiercing); stream.SendNext(playerInfo.moveDist); stream.SendNext(playerInfo.addedMoveDist); stream.SendNext(playerInfo.moveIsCharge); stream.SendNext(playerInfo.addedBasicRange); stream.SendNext(playerInfo.basicRangeMultiplier); stream.SendNext(playerInfo.setBasicRange); stream.SendNext(playerInfo.addedBasicAttack); stream.SendNext(playerInfo.basicAttackMultiplier); stream.SendNext(playerInfo.setBasicAttack); stream.SendNext(playerInfo.addedDamage); stream.SendNext(playerInfo.damageMultiplier); stream.SendNext(playerInfo.setDamage); stream.SendNext(playerInfo.addedWeaponDamage); stream.SendNext(playerInfo.weaponDamageMultiplier); } else { playerInfo.moved = (bool)stream.ReceiveNext(); playerInfo.attacked = (bool)stream.ReceiveNext(); playerInfo.slowed = (int)stream.ReceiveNext(); playerInfo.shocked = (int)stream.ReceiveNext(); playerInfo.hasted = (int)stream.ReceiveNext(); playerInfo.stunned = (int)stream.ReceiveNext(); playerInfo.evading = (int)stream.ReceiveNext(); playerInfo.cardsPlayed = (int)stream.ReceiveNext(); playerInfo.turnDistanceTraveled = (int)stream.ReceiveNext(); playerInfo.stillStandingTurns = (int)stream.ReceiveNext(); playerInfo.nextAtkSlows = (bool)stream.ReceiveNext(); playerInfo.nextAtkShocks = (bool)stream.ReceiveNext(); playerInfo.nextFreeMove = (bool)stream.ReceiveNext(); playerInfo.nextFreeBasic = (bool)stream.ReceiveNext(); //playerInfo.maxHp = (int)stream.ReceiveNext(); playerInfo.health = (int)stream.ReceiveNext(); playerManager.UpdateAHBText(); //playerInfo.attack = (int)stream.ReceiveNext(); playerInfo.block = (int)stream.ReceiveNext(); playerManager.UpdateAHBText(); playerInfo.resolve = (int)stream.ReceiveNext(); // playerInfo.basicRange = (int)stream.ReceiveNext(); playerInfo.basicIsStraight = (bool)stream.ReceiveNext(); playerInfo.basicIsPiercing = (bool)stream.ReceiveNext(); playerInfo.moveDist = (int)stream.ReceiveNext(); playerInfo.addedMoveDist = (int)stream.ReceiveNext(); playerInfo.moveIsCharge = (bool)stream.ReceiveNext(); int abr = (int)stream.ReceiveNext(); if (playerInfo.addedBasicRange != abr) { playerInfo.addedBasicRange = abr; playerManager.SetAllAttackableOutlines(); } float brm = (float)stream.ReceiveNext(); if (playerInfo.basicRangeMultiplier != brm) { playerInfo.basicRangeMultiplier = brm; playerManager.SetAllAttackableOutlines(); } int sbr = (int)stream.ReceiveNext(); if (playerInfo.setBasicRange != sbr) { playerInfo.setBasicRange = sbr; playerManager.SetAllAttackableOutlines(); } playerInfo.addedBasicAttack = (int)stream.ReceiveNext(); playerInfo.basicAttackMultiplier = (float)stream.ReceiveNext(); playerInfo.setBasicAttack = (int)stream.ReceiveNext(); playerInfo.addedDamage = (int)stream.ReceiveNext(); playerInfo.damageMultiplier = (float)stream.ReceiveNext(); playerInfo.setDamage = (int)stream.ReceiveNext(); playerInfo.addedWeaponDamage = (int)stream.ReceiveNext(); playerInfo.weaponDamageMultiplier = (float)stream.ReceiveNext(); } }
public override void Deserialize(PhotonStream stream, PhotonMessageInfo info) { currentHealth = (float)stream.ReceiveNext(); isDead = (bool)stream.ReceiveNext(); }