Example #1
0
    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();

        }
    }
Example #2
0
    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;
            }

        }
    }
    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();
            }
        }
    }
    // 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;
        }
    }
Example #5
0
    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;
            }
        }
    }
Example #6
0
    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
        }
    }
    /// <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();
        }
    }
Example #8
0
    //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


        }
    }
Example #9
0
        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);
                }
            }
        }
	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
		if(stream.isWriting) {
			stream.SendNext(transform.position);
		} else {
			position = (Vector3)stream.ReceiveNext();
		}
	}
Example #11
0
    void OnPhotonInstantiate(PhotonMessageInfo msg)
    {
        // This is our own player
        if (photonView.isMine)
        {
            //camera.main.enabled=false;

            localPlayer = true;

            Destroy(GameObject.Find("LevelCamera"));

            Machinegun gun = transform.GetComponentInChildren < Machinegun>();
            gun.localPlayer = true;

        }
        // This is just some remote controlled player, don't execute direct
        // user input on this. DO enable multiplayer controll
        else
        {
            name += msg.sender.name;

            transform.Find("CrateCamera").gameObject.active = false;

            FPSWalker4 tmp2 = GetComponent<FPSWalker4>() as FPSWalker4;
            tmp2.enabled = false;
            MouseLook tmp5 = GetComponent<MouseLook>() as MouseLook;
            tmp5.enabled = false;
        }
    }
Example #12
0
    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;
        }
    }
Example #13
0
    // 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;
        }
    }
	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;

        }
    }
        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();
            }
        }
Example #16
0
    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;

                        }
                }
    }
Example #17
0
	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;
		}
	}
Example #18
0
    /// <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;
        }
    }
 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();
         }
 }
        void InventoryPlayerPickedUpItem(int ufpsItemID, int ufpsPlayerID, Vector3 itemPosition, Quaternion itemRotation, PhotonMessageInfo info)
        {
            List<vp_ItemPickup> pickups;
            if (!vp_MPPickupManager.Instance.Pickups.TryGetValue(ufpsItemID, out pickups))
                return;

            if (pickups[0].gameObject != null)
                vp_Utility.Activate(pickups[0].gameObject, false);

            Debug.Log("Client looted item with UFPS ID: " + ufpsItemID);
            
            vp_MPNetworkPlayer player;
            if (!vp_MPNetworkPlayer.PlayersByID.TryGetValue(ufpsPlayerID, out player))
                return;

            if (player == null)
                return;

            if (player.Collider == null)
                return;

            foreach (vp_ItemPickup p in pickups)
            {
                var a = p as ObjectTriggererItemUFPS;
                a.TryGiveToPlayer(player.Collider, p.Amount, false);
                Debug.Log("Giving UFPS item to player - ItemID: " + a.ID);
            }
        }
Example #21
0
    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();
        }
    }
Example #22
0
    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();

        }
    }
Example #23
0
    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;
        }
    }
    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();
    }
Example #25
0
 public void SendOK(int id, int pNum, int chNum, int tNum, int cNum, bool un, PhotonMessageInfo info)
 {
     print ("id:" + id.ToString () + "pNum:" + pNum.ToString () + "cNum:" + cNum.ToString () + "tNum:" + tNum);
     if (un)
         gameInfo.SetInfo (id, pNum, chNum, tNum, cNum);
     setOK [id] = un ? true : false;
 }
Example #26
0
 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);
     }
 }    
    //    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());
        }
    }
    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)
    {
        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

        }
    }
Example #30
0
    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;
			}

        }
    }