Serialize() public method

Will read or write the value, depending on the stream's isWriting value.
public Serialize ( PhotonPlayer, &obj ) : void
obj PhotonPlayer,
return void
コード例 #1
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        int  count     = gameObject.transform.childCount;
        bool available = isAvailable;

        stream.Serialize(ref available);
        stream.Serialize(ref count);
        if (stream.isReading)
        {
            isAvailable = available;
            if (!available)
            {
                GameObject.Find("CardHand" + PlayerPrefs.GetString("LoginUser", "Unknown")).GetComponent <HandPhoton>().isAvailable = true;
            }
            if (GameObject.Find("CardHand" + PlayerPrefs.GetString("LoginUser", "Unknown")).transform.childCount == 0 && count == 0)
            {
                GameObject.Find("Modal").transform.GetChild(0).gameObject.SetActive(true);
                int mineScore  = Int32.Parse(GameObject.Find("Score" + PlayerPrefs.GetString("LoginUser", "Unknown")).GetComponentInChildren <Text>().text);
                int enemyScore = Int32.Parse(GameObject.Find("ScoreBox(Clone)").GetComponentInChildren <Text>().text);
                if (mineScore > enemyScore)
                {
                    GameObject.Find("FinalModal").GetComponentInChildren <Text>().text = "Безоговорочная победа!";
                }
                else
                {
                    GameObject.Find("FinalModal").GetComponentInChildren <Text>().text = "Бесславное поражение!";
                }
            }
        }
    }
コード例 #2
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        Vector3    playerPos = character.transform.position;
        Quaternion playerRot = character.transform.rotation;

        Quaternion cameraRot = camera.transform.rotation;


        stream.Serialize(ref playerPos);
        stream.Serialize(ref playerRot);
        stream.Serialize(ref cameraRot);
        if (stream.isReading)
        {
            oldPosition  = transform.position;
            oldPlayerRot = transform.rotation;
            newPosition  = playerPos;
            newPlayerRot = playerRot;
            offsetTime   = 0;
            isSync       = true;

            oldCamerarRot = camera.transform.rotation;
            newCameraRot  = cameraRot;

            //    character.transform.position = playerPos;
            //   character.transform.rotation = playerRot;

            //   camera.transform.rotation = cameraRot;
        }
    }
コード例 #3
0
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3    pos = transform.localPosition;
            Quaternion rot = transform.localRotation;
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            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);

            correctHeadPos  = pos;
            correctHeadRot  = rot;
            onUpdateHeadPos = transform.localPosition;
            onUpdateHeadRot = transform.localRotation;
            fraction        = 0;
        }
    }
コード例 #4
0
ファイル: Item.cs プロジェクト: aabbdev/Darknet
    // void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        Vector3 syncVelocity = Vector3.zero;

        // Store current position.
        syncPosition = gameObject.transform.position;

        // If sending data
        if (stream.isWriting)
        {
            // stream.Serialize allows for variable to be serialized and sent to other clients.
            // Order of variables streamed should be the same when sending and receiving to avoid value mixups.
            stream.Serialize(ref syncPosition);
        }
        // If receiving data
        else
        {
            // stream.Serialize allows for variables to be serialized and received by clients.
            stream.Serialize(ref syncPosition);

            // Synchronization adjustment.
            syncTime  = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            // Store start position for future calls.
            syncStartPosition = syncPosition + syncVelocity * syncDelay;
            // Store data locally
            syncEndPosition = syncPosition;
        }
    }
コード例 #5
0
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        Debug.Log("merp");
        if (stream.IsWriting)
        {
            Vector3    pos = GetPosition();
            Quaternion rot = GetRotation();
            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);

            if (!photonView.IsMine)
            {
                //Debug.Log(string.Format("Received Position ({0})", pos.ToString()));
                Sync(pos, rot);
            }
            else
            {
                Debug.Log("View is mine :(");
            }
        }
    }
コード例 #6
0
ファイル: StoneNetwork.cs プロジェクト: hekk/sprint_workshop
    /// <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;
        }
    }
コード例 #7
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)
    {
        // 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;
        }
    }
コード例 #8
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)
    {
        // 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;
        }
    }
コード例 #9
0
        void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            int    pid  = 0;
            string path = null;

            if (stream.isWriting)
            {
                NetworkReference nref = NetworkReference.FromTransform(transform.parent);
                pid  = nref.parentHandleId;
                path = nref.pathFromParent;

                // Send update

                stream.Serialize(ref pid);
                stream.Serialize(ref path);
            }
            else
            {
                // Receive updated state information

                stream.Serialize(ref pid);
                stream.Serialize(ref path);

                newState.timestamp = info.timestamp;
                newState.parentId  = pid;
                newState.path      = path;
            }
        }
コード例 #10
0
ファイル: CubeExtra.cs プロジェクト: CanPayU/SuperSwungBall
    // 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;
        }
    }
コード例 #11
0
    // Token: 0x0600024E RID: 590 RVA: 0x0000F84C File Offset: 0x0000DA4C
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3    localPosition = base.transform.localPosition;
            Quaternion localRotation = base.transform.localRotation;
            stream.Serialize(ref localPosition);
            stream.Serialize(ref localRotation);
            stream.SendNext(Environment.TickCount);
            return;
        }
        Vector3    zero     = Vector3.zero;
        Quaternion identity = Quaternion.identity;

        stream.Serialize(ref zero);
        stream.Serialize(ref identity);
        for (int i = this.m_BufferedState.Length - 1; i >= 1; i--)
        {
            this.m_BufferedState[i] = this.m_BufferedState[i - 1];
        }
        CubeInter.State state;
        state.timestamp         = info.timestamp;
        state.pos               = zero;
        state.rot               = identity;
        this.m_BufferedState[0] = state;
        this.m_TimestampCount   = Mathf.Min(this.m_TimestampCount + 1, this.m_BufferedState.Length);
        for (int j = 0; j < this.m_TimestampCount - 1; j++)
        {
            if (this.m_BufferedState[j].timestamp < this.m_BufferedState[j + 1].timestamp)
            {
                Debug.Log("State inconsistent");
            }
        }
    }
コード例 #12
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        // наша позиция и поворот
        Vector3    position = transform.position;
        Quaternion rotation = transform.rotation;

        // сериализуем/передаём в поток нашу позицию
        stream.Serialize(ref position);
        stream.Serialize(ref rotation);

        // если сейчас вызван метод с потоком на чтение
        if (stream.isReading)
        {
            //transform.position = position;
            oldPos     = transform.position;
            newPos     = position;
            offsetTime = 0f; // обновили позицию и сбрасываем время
            isSynch    = true;

            //transform.rotation = rotation;
            old_rotation        = transform.rotation;
            new_rotation        = rotation;
            offsetTime_rotation = 0f;
        }
    }
コード例 #13
0
ファイル: CubeLerp.cs プロジェクト: thom0730/TK_1615
    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
        }
    }
コード例 #14
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;
        }
    }
コード例 #15
0
ファイル: CubeLerp.cs プロジェクト: apekshadarbari/PokerFace
    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
        }
    }
コード例 #16
0
    /// <summary>
    /// Serialization method. Used to sync properties every frame.
    /// </summary>
    /// <param name="stream"></param>
    /// <param name="info"></param>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (myBullet == null)
        {
            return;
        }

        Vector3 positionAndRotation = Vector3.zero;

        if (stream.isWriting)
        {
            positionAndRotation.x = myBullet.transform.position.x;
            positionAndRotation.y = myBullet.transform.eulerAngles.y;
            positionAndRotation.z = myBullet.transform.position.z;

            stream.Serialize(ref positionAndRotation);
        }
        else
        {
            stream.Serialize(ref positionAndRotation);

            Vector3    receivedPosition = new Vector3(positionAndRotation.x, this.transform.position.y, positionAndRotation.z);
            Quaternion receivedRotation = Quaternion.Euler(this.transform.eulerAngles.x, positionAndRotation.y, this.transform.eulerAngles.z);

            myBullet.OnNetworkUpdate(receivedPosition, receivedRotation);
        }
    }
コード例 #17
0
ファイル: Ball.cs プロジェクト: planteaj/class_examples
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     Debug.Log("serializing " + this.name + " " + stream.IsWriting);
     stream.Serialize(ref networkPosition);
     stream.Serialize(ref networkRotation);
     stream.Serialize(ref health);
 }
コード例 #18
0
ファイル: CubeExtra.cs プロジェクト: VN0/SimpleWars
    // 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;
        }
    }
コード例 #19
0
 public override void Serialize(PhotonStream stream, PhotonMessageInfo info)
 {
     stream.Serialize(ref parentNetRef.parentHandleId);
     stream.Serialize(ref parentNetRef.pathFromParent);
     //if (HasChanged() || stream.isReading) {
     //    Debug.Log("PARENT " + (stream.isWriting ? "Sent " : "Recvd ") + this + " --> " + parentNetRef);
     //}
 }
コード例 #20
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     //Получение данных о позиции и повороте текущего персонажа и отправка этих данных другим пользователям
     networkPos = transform.position;
     networkRot = bottom.transform.rotation;
     stream.Serialize(ref networkPos);
     stream.Serialize(ref networkRot);
 }
コード例 #21
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     stream.Serialize(ref networkPosition);
     stream.Serialize(ref networkRotation);
     stream.Serialize(ref networkVelocity);
     stream.Serialize(ref networkAngularVelocity);
     stream.Serialize(ref networkUseGravity);
 }
コード例 #22
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        // Send data to server
        if (stream.isWriting)
        {
            Vector3 pos = transform.position;
            Quaternion rot = transform.rotation;
            //Vector3 velocity = Vector3.zero;  //rigidbody.velocity;
            //Vector3 angularVelocity = Vector3.zero; // rigidbody.angularVelocity;

            stream.Serialize(ref pos);
            //stream.Serialize(ref velocity);
            stream.Serialize(ref rot);
            //stream.Serialize(ref angularVelocity);
        }
        // Read data from remote client
        else
        {
            Vector3 pos = Vector3.zero;
            Vector3 velocity = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            Vector3 angularVelocity = Vector3.zero;
            stream.Serialize(ref pos);
            //stream.Serialize(ref velocity);
            stream.Serialize(ref rot);
            //stream.Serialize(ref angularVelocity);

            // Shift the buffer sideways, deleting state 20
            for (int i=m_BufferedState.Length-1;i>=1;i--)
            {
                m_BufferedState[i] = m_BufferedState[i-1];
            }

            // Record current state in slot 0
            State state;
            state.timestamp = info.timestamp;
            state.pos = pos;
            state.velocity = velocity;
            state.rot = rot;
            state.angularVelocity = angularVelocity;
            m_BufferedState[0] = state;

            // Update used slot count, however never exceed the buffer size
            // Slots aren't actually freed so this just makes sure the buffer is
            // filled up and that uninitalized slots aren't used.
            m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);

            // Check if states are in order, if it is inconsistent you could reshuffel or
            // drop the out-of-order state. Nothing is done here
            for (int i=0;i<m_TimestampCount-1;i++)
            {
                if (m_BufferedState[i].timestamp < m_BufferedState[i+1].timestamp)
                    Debug.Log("State inconsistent");
            }
        }
    }
コード例 #23
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);
            if(anim != null)
            {
                float zVel = anim.GetFloat("Z_Vel");
                float xVel = anim.GetFloat("X_Vel");
                bool jumping = anim.GetBool("Jumping");
                stream.Serialize(ref zVel);
                stream.Serialize(ref xVel);
                stream.Serialize(ref jumping);
            }
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            if(anim != null)
            {
                float zVel = 0;
                float xVel = 0;
                bool jumping = false;
                stream.Serialize(ref zVel);
                stream.Serialize(ref xVel);
                stream.Serialize(ref jumping);
                anim.SetFloat("Z_Vel",zVel);
                anim.SetFloat("X_Vel",xVel);
                anim.SetBool("Jumping",jumping);
            }

            latestCorrectPos = pos;                 // save this to move towards it in Update()
            onUpdatePos = transform.localPosition;  // we interpolate from here to latestCorrectPos
            latestCorrectRot = rot;     			// same with rotation
            onUpdateRot = transform.localRotation;
            fraction = 0;                           // reset the fraction we alreay moved. see Update()

            if(firstUpdate)
            {
                transform.localPosition = pos;
                transform.localRotation = rot;
                firstUpdate = false;
            }
        }
    }
コード例 #24
0
ファイル: PlayerController.cs プロジェクト: RAYLIATOR/Studio3
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.IsWriting)
     {
         stream.Serialize(ref health);
     }
     else
     {
         stream.Serialize(ref health);
     }
 }
コード例 #25
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.IsWriting)
     {
         stream.Serialize(ref currentHoldTime);
     }
     else
     {
         stream.Serialize(ref currentHoldTime);
     }
 }
コード例 #26
0
ファイル: PhotonBody.cs プロジェクト: jonigata/Tcf
 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     stream.Serialize(ref position);
     stream.Serialize(ref prevPosition);
     stream.Serialize(ref orientation);
     stream.Serialize(ref prevOrientation);
     if (!stream.isWriting)
     {
         sendTime = info.timestamp;
     }
 }
コード例 #27
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.Serialize(ref Kappa);
     }
     else
     {
         stream.Serialize(ref Kappa);
     }
 }
コード例 #28
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.Serialize(ref text);
     }
     else
     {
         text = "";
         stream.Serialize(ref text);              // pos被填充。必须在某个地方使用
     }
 }
コード例 #29
0
    private void OnPhotonSerializeView(PhotonStream Stream, PhotonMessageInfo Info)
    {
        // Send data to server
        if (Stream.isWriting)
        {
            // Not sending data when in slow-motion or fast-motion.
            if (Time.timeScale != NormalTimeScale)
                return;

            var Position = rigidbody.position;
            var Rotation = rigidbody.rotation;
            var Velocity = rigidbody.velocity;
            var AngularVelocity = rigidbody.angularVelocity;

            Stream.Serialize(ref Position);
            Stream.Serialize(ref Velocity);
            Stream.Serialize(ref Rotation);
            Stream.Serialize(ref AngularVelocity);
        }
        // Read data from remote client
        else
        {
            var Position = Vector3.zero;
            var Velocity = Vector3.zero;
            var Rotation = Quaternion.identity;
            var AngularVelocity = Vector3.zero;

            Stream.Serialize(ref Position);
            Stream.Serialize(ref Velocity);
            Stream.Serialize(ref Rotation);
            Stream.Serialize(ref AngularVelocity);

            // Shift the buffer sideways, deleting the last state.
            for (var i = BufferedStates.Length - 1; i >= 1; i--)
                BufferedStates[i] = BufferedStates[i - 1];

            // Record current state in slot 0
            BufferedStates[0] = new RigidBodyState(Info.timestamp, Position, Velocity, Rotation, AngularVelocity);

            // Update used slot count, however never exceed the buffer size
            // Slots aren't actually freed so this just makes sure the buffer is
            // filled up and that uninitalized slots aren't used.
            UsedBufferedStatesCount = Mathf.Min(UsedBufferedStatesCount + 1, BufferedStates.Length);

            // Check if states are in order, if it is inconsistent you could reshuffel or
            // drop the out-of-order state. Nothing is done here
            for (var i = 0; i < UsedBufferedStatesCount - 1; i++)
            {
                if (BufferedStates[i].Timestamp < BufferedStates[i + 1].Timestamp)
                    Debug.Log("State inconsistent");
            }
        }
    }
コード例 #30
0
        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            Vector3 pos = transform.position;

            stream.Serialize(ref pos);
            transform.position = pos;

            Quaternion rot = transform.rotation;

            stream.Serialize(ref rot);
            transform.rotation = rot;
        }
コード例 #31
0
ファイル: Player.cs プロジェクト: Vsailor/Maze
 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     Vector3 pos = transform.position;
     Quaternion rot = transform.rotation;
     stream.Serialize(ref pos);
     stream.Serialize(ref rot);
     if (stream.isReading)
     {
         transform.position = pos;
         transform.rotation = rot;
     }
 }
コード例 #32
0
ファイル: CameraMove.cs プロジェクト: farty/NOM-game
    void OnPhotonSerializeViev(PhotonStream stream, PhotonMessageInfo info)
    {
        Vector3    pos = transform.position;
        Quaternion rot = transform.rotation;

        stream.Serialize(ref pos);
        stream.Serialize(ref rot);
        if (stream.isReading)
        {
            transform.position = pos;
            transform.rotation = rot;
        }
    }
コード例 #33
0
		// in an "observed" script:
		public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
		{
			if (stream.isWriting)
			{
				Vector3 pos = this.transform.localPosition;
				stream.Serialize(ref pos);
			}
			else
			{
				Vector3 pos = Vector3.zero;
				stream.Serialize(ref pos);  // pos gets filled-in. must be used somewhere
			}
		}
コード例 #34
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         Vector3 pos = transform.localPosition;
         stream.Serialize(ref pos);
     }
     else
     {
         Vector3 pos = Vector3.zero;
         stream.Serialize(ref pos);  // pos gets filled-in. must be used somewhere
     }
 }
コード例 #35
0
ファイル: Drone.cs プロジェクト: alanmckeon/Battleships
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         Vector3 pos = transform.localPosition;
         stream.Serialize(ref pos);
     }
     else
     {
         Vector3 pos = Vector3.zero;
         stream.Serialize(ref pos);
     }
 }
コード例 #36
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.IsWriting)
     {
         stream.Serialize(ref _pressCount);
         minigame.UpdateTugOfWar();
     }
     else
     {
         stream.Serialize(ref _pressCount);
         minigame.UpdateTugOfWar();
     }
 }
コード例 #37
0
ファイル: CubeInter.cs プロジェクト: ashomk/beerpong
    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);
            stream.SendNext(Environment.TickCount);
        }
            // 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);            
            
            int localTimeOfSend = (int)stream.ReceiveNext();
            //Debug.Log("timeDiff" + (Environment.TickCount - localTimeOfSend) + " update age: " + (PhotonNetwork.time - info.timestamp));

            // Shift buffer contents, oldest data erased, 18 becomes 19, ... , 0 becomes 1
            for (int i = this.m_BufferedState.Length - 1; i >= 1; i--)
            {
                this.m_BufferedState[i] = this.m_BufferedState[i - 1];
            }


            // Save currect received state as 0 in the buffer, safe to overwrite after shifting
            State state;
            state.timestamp = info.timestamp;
            state.pos = pos;
            state.rot = rot;
            this.m_BufferedState[0] = state;

            // Increment state count but never exceed buffer size
            this.m_TimestampCount = Mathf.Min(this.m_TimestampCount + 1, this.m_BufferedState.Length);

            // Check integrity, lowest numbered state in the buffer is newest and so on
            for (int i = 0; i < this.m_TimestampCount - 1; i++)
            {
                if (this.m_BufferedState[i].timestamp < this.m_BufferedState[i + 1].timestamp)
                {
                    Debug.Log("State inconsistent");
                }
            }
        }
    }
コード例 #38
0
 // used as Observed component in a PhotonView, this only reads/writes the position
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.IsWriting)
     {
         int data = players;
         stream.Serialize(ref data);
     }
     else
     {
         int data = 0;
         stream.Serialize(ref data);  // pos gets filled-in. must be used somewhere
         players = data;
     }
 }
コード例 #39
0
 /**
  * Serialises state changes for client.
  * Currently, the whole state is sent, even if only part of the state changed.
  */
 protected virtual void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (DetectChange() && stream.isWriting)
     {
         Vector2 pos      = transform.position;
         float   rotation = transform.rotation.eulerAngles.z;
         stream.Serialize(ref pos);
         stream.Serialize(ref rotation);
     }
     else if (!stream.isWriting)
     {
         Debug.LogWarning("Server object is receiving positional info from client");
     }
 }
コード例 #40
0
        void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            bool curActive = this.gameObject.GetActive();

            if (stream.isWriting)
            {
                if (HasChanged())
                {
                    stream.Serialize(ref curActive);
                    stream.Serialize(ref grabOwner);
                    stream.Serialize(ref grabParent);
                    stream.Serialize(ref grabAttachPath);
                }
            }
            else
            {
                stream.Serialize(ref curActive);
                stream.Serialize(ref grabOwner);
                stream.Serialize(ref grabParent);
                stream.Serialize(ref grabAttachPath);
                this.gameObject.SetActive(curActive);
                if (oldGrabParent != grabParent || oldGrabAttachPath != grabAttachPath)
                {
                    PerformGrab();
                }
            }
            MemorizeState();
        }
コード例 #41
0
    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);
            stream.SendNext(Environment.TickCount);
        }
        // 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);

            //int localTimeOfSend = (int)stream.ReceiveNext();
            //Debug.Log("timeDiff" + (Environment.TickCount - localTimeOfSend) + " update age: " + (PhotonNetwork.time - info.timestamp));

            // Shift buffer contents, oldest data erased, 18 becomes 19, ... , 0 becomes 1
            for (int i = this.m_BufferedState.Length - 1; i >= 1; i--)
            {
                this.m_BufferedState[i] = this.m_BufferedState[i - 1];
            }


            // Save currect received state as 0 in the buffer, safe to overwrite after shifting
            State state;
            state.timestamp         = info.timestamp;
            state.pos               = pos;
            state.rot               = rot;
            this.m_BufferedState[0] = state;

            // Increment state count but never exceed buffer size
            this.m_TimestampCount = Mathf.Min(this.m_TimestampCount + 1, this.m_BufferedState.Length);

            // Check integrity, lowest numbered state in the buffer is newest and so on
            for (int i = 0; i < this.m_TimestampCount - 1; i++)
            {
                if (this.m_BufferedState[i].timestamp < this.m_BufferedState[i + 1].timestamp)
                {
                    Debug.Log("State inconsistent");
                }
            }
        }
    }
コード例 #42
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        string  score = gameObject.GetComponentInChildren <Text>().text;
        Vector3 pos   = transform.position;

        stream.Serialize(ref pos);
        stream.Serialize(ref score);
        if (stream.isReading)
        {
            pos.y = -pos.y;
            transform.position = pos;
            transform.parent   = GameObject.Find("NumberCanvas").transform;
            gameObject.GetComponentInChildren <Text>().text = score;
        }
    }
コード例 #43
0
 // used as Observed component in a PhotonView, this only reads/writes the position
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.IsWriting)
     {
         Vector3 pos = transform.localPosition;
         stream.Serialize(ref pos);
         stream.SendNext(Health);
     }
     else
     {
         Vector3 pos = Vector3.zero;
         stream.Serialize(ref pos);  // pos gets filled-in. must be used somewhere
         Health = (float)stream.ReceiveNext();
     }
 }
コード例 #44
0
ファイル: Item.cs プロジェクト: Gahzi/ZeroMark
    /// <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>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3 pos = transform.localPosition;
            Quaternion rot = transform.rotation;
            int hlth = health;
            //ItemType itmType = itemType;
            float rspwnTime = respawnTime;
            float rspwnStrt = respawnStart;
            int st = (int)state;
            float dsbleTime = disableTime;
            int tm = (int)team;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref hlth);
            stream.Serialize(ref rspwnTime);
            stream.Serialize(ref rspwnStrt);
            stream.Serialize(ref st);
            stream.Serialize(ref dsbleTime);
            stream.Serialize(ref tm);
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            int hlth = 0;
            float rspwnTime = 0;
            float rspwnStrt = 0;
            int st = 0;
            float dsbleTime = 0;
            int tm = 0;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref hlth);
            stream.Serialize(ref rspwnTime);
            stream.Serialize(ref rspwnStrt);
            stream.Serialize(ref st);
            stream.Serialize(ref dsbleTime);
            stream.Serialize(ref tm);

            transform.position = pos;
            transform.rotation = rot;          // this sample doesn't smooth rotation
            health = hlth;
            respawnTime = rspwnTime;
            respawnStart = rspwnStrt;
            state = (ItemState)st;
            disableTime = dsbleTime;
            team = (Team)tm;
        }
    }
コード例 #45
0
ファイル: PlayerCulling.cs プロジェクト: minhdu/mmo-client
	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			networkCulling.SetGroup(photonView);
			Vector3 pos = transform.position;
			Quaternion rot = transform.rotation;
			stream.Serialize(ref pos);
			stream.Serialize(ref rot);
		}
		else
		{
			Vector3 pos = transform.position;
			Quaternion rot = transform.rotation;
			stream.Serialize(ref pos);
			stream.Serialize(ref rot);
			SetPositionRotation(pos,rot); //Your own synchronization code (or just directly set the position/rotation for now)
		}
	}
コード例 #46
0
ファイル: KillTag.cs プロジェクト: Gahzi/ZeroMark
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            int _val = pointValue;
            Vector3 _pos = transform.position;
            Vector3 _scl = transform.localScale;

            stream.Serialize(ref _val);
            stream.Serialize(ref _pos);
            stream.Serialize(ref _scl);
        }
        else
        {
            int _val = 0;
            Vector3 _pos = Vector3.zero;
            Vector3 _scl = Vector3.one;

            stream.Serialize(ref _val);
            stream.Serialize(ref _pos);
            stream.Serialize(ref _scl);

            pointValue = _val;
            transform.position = _pos;
            transform.localScale = _scl;
        }
    }
コード例 #47
0
    /// <summary>
    /// Serialization method. Used to sync properties every frame.
    /// </summary>
    /// <param name="stream"></param>
    /// <param name="info"></param>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (myBullet == null) return;

        Vector3 positionAndRotation = Vector3.zero;

        if (stream.isWriting)
        {
            positionAndRotation.x = myBullet.transform.position.x;
            positionAndRotation.y = myBullet.transform.eulerAngles.y;
            positionAndRotation.z = myBullet.transform.position.z;

            stream.Serialize(ref positionAndRotation);
        }
        else
        {
            stream.Serialize(ref positionAndRotation);

            Vector3 receivedPosition = new Vector3(positionAndRotation.x, this.transform.position.y, positionAndRotation.z);
            Quaternion receivedRotation = Quaternion.Euler(this.transform.eulerAngles.x, positionAndRotation.y, this.transform.eulerAngles.z);

            myBullet.OnNetworkUpdate(receivedPosition, receivedRotation);
        }
    }
コード例 #48
0
    /// <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>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        //timeout_timer = TIMEOUT_MAX;

        if (stream.isWriting)
        {
            Vector3 pos = transform.position;
            Quaternion rot = transform.rotation;
            Vector3 scale = transform.localScale;

            if(debug)
            {
                print("sending pos: " + pos.ToString() + " rot: " + rot.ToString() + " scale: " + scale.ToString() + "rand: " + Random.Range(0.1f, 100.0f));
            }

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref scale);
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            Vector3 scale = Vector3.zero;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref scale);

            if(debug)
            {
                print("receiving pos: " + pos.ToString() + " rot: " + rot.ToString() + " scale: " + scale.ToString() + "rand: " + Random.Range(0.1f, 100.0f));
            }

            latestCorrectPos = pos;                 // save this to move towards it in FixedUpdate()
            latestCorrectRot = rot;
            latestCorrectScale = scale;

            onUpdatePos = transform.position;  // we interpolate from here to latestCorrectPos
            onUpdateRot = transform.rotation;
            onUpdateScale = transform.localScale;
            fraction = 0;                           // reset the fraction we alreay moved. see Update()
        }
    }
コード例 #49
0
    /// <summary>
    /// Serialization method. Used to sync properties every frame.
    /// </summary>
    /// <param name="stream"></param>
    /// <param name="info"></param>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (myPlayer == null) return;

        Vector3 positionAndRotation = Vector3.zero;
        int actualStateCode = 0;

        Vector2 velocity = Vector3.zero;

        if (stream.isWriting)
        {
            positionAndRotation.x = myPlayer.transform.position.x;
            positionAndRotation.y = myPlayer.childTransform.eulerAngles.y;
            positionAndRotation.z = myPlayer.transform.position.z;

            stream.Serialize(ref positionAndRotation);

            actualStateCode = myPlayer.actualState.GetHashCode();

            velocity = new Vector2(myPlayer.GetComponent<Rigidbody>().velocity.x, myPlayer.GetComponent<Rigidbody>().velocity.z);
            stream.Serialize(ref velocity);

            stream.Serialize(ref actualStateCode);
        }
        else
        {
            stream.Serialize(ref positionAndRotation);

            Vector3 receivedPosition = new Vector3(positionAndRotation.x,this.transform.position.y,positionAndRotation.z);
            Quaternion receivedRotation = Quaternion.Euler(this.transform.eulerAngles.x,positionAndRotation.y,this.transform.eulerAngles.z);

            myPlayer.transform.position = receivedPosition;
            myPlayer.childTransform.rotation = receivedRotation;

            stream.Serialize(ref velocity);

            myPlayer.OnNetworkUpdate(receivedPosition, receivedRotation,velocity);

            stream.Serialize(ref actualStateCode);

            myPlayer.ChangeState((PlayerStates)actualStateCode);

        }
    }
コード例 #50
0
ファイル: KBPlayer.cs プロジェクト: Gahzi/ZeroMark
    /// <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>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3 pos = transform.localPosition;
            Quaternion rot = upperBody.transform.rotation;
            int kt = currentPoints;
            int kc = killCount;
            int dc = deathCount;
            int ttg = totalPointsGained;
            int ttl = totalPointsLost;
            int ttb = totalPointsBanked;
            int hlth = health;
            int mxhlth = stats.health;
            bool wtngFrRspwn = waitingForRespawn;
            int tm = (int)team;
            float invltime = invulnerabilityTime;

            int[] amms = new int[guns.Length];

            for (int i = 0; i < guns.Length; i++)
            {
                amms[i] = guns[i].ammo;
            }

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref kt);
            stream.Serialize(ref kc);
            stream.Serialize(ref dc);
            stream.Serialize(ref ttg);
            stream.Serialize(ref ttl);
            stream.Serialize(ref ttb);
            stream.Serialize(ref hlth);
            stream.Serialize(ref mxhlth);
            stream.Serialize(ref wtngFrRspwn);
            stream.Serialize(ref tm);
            stream.Serialize(ref invltime);

            for (int j = 0; j < amms.Length; j++)
            {
                stream.Serialize(ref amms[j]);
            }
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            int kt = 0;
            int kc = 0;
            int dc = 0;
            int ttg = 0;
            int ttl = 0;
            int ttb = 0;
            int hlth = 0;
            int mxhlth = 0;
            bool wtngFrRspwn = false;
            int tm = 0;
            float invltime = 0.0f;
            int[] amms = new int[guns.Length];

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref kt);
            stream.Serialize(ref kc);
            stream.Serialize(ref dc);
            stream.Serialize(ref ttg);
            stream.Serialize(ref ttl);
            stream.Serialize(ref ttb);
            stream.Serialize(ref hlth);
            stream.Serialize(ref mxhlth);
            stream.Serialize(ref wtngFrRspwn);
            stream.Serialize(ref tm);
            stream.Serialize(ref invltime);

            for (int i = 0; i < amms.Length; i++)
            {
                stream.Serialize(ref amms[i]);
            }

            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()

            upperBody.transform.rotation = rot;          // this sample doesn't smooth rotation
            currentPoints = kt;
            killCount = kc;
            deathCount = dc;
            totalPointsGained = ttg;
            totalPointsLost = ttl;
            totalPointsBanked = ttb;
            health = hlth;
            waitingForRespawn = wtngFrRspwn;
            team = (Team)tm;
            invulnerabilityTime = invltime;

            for (int j = 0; j < amms.Length; j++)
            {
                guns[j].ammo = amms[j];
            }
        }
    }
コード例 #51
0
ファイル: PlayerControl.cs プロジェクト: Ruugard/CuriousPanda
    /// <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>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3 pos = transform.localPosition;
            Quaternion rot = transform.localRotation;
            float speed = anim.GetFloat("Speed");
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref speed);
            stream.Serialize(ref facingRight);
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            float speed = 0;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref speed);
            stream.Serialize(ref facingRight);

            mLatestCorrectPos = pos;                 // save this to move towards it in FixedUpdate()
            mOnUpdatePos = transform.localPosition;  // we interpolate from here to latestCorrectPos
            mFraction = 0;                           // reset the fraction we alreay moved. see Update()

            transform.localRotation = rot;          // this sample doesn't smooth rotation

            anim.SetFloat("Speed", speed);
            SetFacingDirection(facingRight);
        }
    }
コード例 #52
0
ファイル: NetworkDrone.cs プロジェクト: eleurent/KestrelFPV
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3 position = transform.localPosition;
            Vector3 velocity = GetComponent<Rigidbody>().velocity;
            Vector3 acceleration = GetComponent<ControllerManager>().getAcceleration();
            Quaternion rotation = transform.localRotation;
            Vector3 angularVelocity = GetComponent<Rigidbody>().angularVelocity;
            float power = GetComponent<PropellersController>().getPower();
            stream.Serialize(ref position);
            stream.Serialize(ref velocity);
            stream.Serialize(ref acceleration);
            stream.Serialize(ref rotation);
            stream.Serialize(ref angularVelocity);
            stream.Serialize(ref power);
        }
        else
        {
            // Receive latest state information
            Vector3 position = Vector3.zero;
            Vector3 velocity = Vector3.zero;
            Vector3 acceleration = Vector3.zero;
            Quaternion rotation = Quaternion.identity;
            Vector3 angularVelocity = Vector3.zero;
            float power = 0;

            stream.Serialize(ref position);
            stream.Serialize(ref velocity);
            stream.Serialize(ref acceleration);
            stream.Serialize(ref rotation);
            stream.Serialize(ref angularVelocity);
            stream.Serialize(ref power);

            lastPosition = position;
            lastVelocity = velocity;
            lastAcceleration = acceleration;
            lastRotation = rotation;
            lastAngularVelocity = angularVelocity;
            lastPower = power;

            estPosition = lastPosition;
            estVelocity = lastVelocity;

            lastUpdateTimestamp = info.timestamp;
        }
    }
コード例 #53
0
ファイル: GameManager.cs プロジェクト: Gahzi/ZeroMark
    //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>
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            int gmState = (int)state;
            int rdTmScre = redTeamScore;
            int blTmScre = blueTeamScore;
            int rdCptrs = redCaptures;
            int blCptrs = blueCaptures;
            float strtTime = startTime;
            float gmTime = gameTime;
            float gmTimeMax = gameTimeMax;

            stream.Serialize(ref gmState);
            stream.Serialize(ref rdTmScre);
            stream.Serialize(ref blTmScre);
            stream.Serialize(ref rdCptrs);
            stream.Serialize(ref blCptrs);
            stream.Serialize(ref strtTime);
            stream.Serialize(ref gmTime);
            stream.Serialize(ref gmTimeMax);
        }
        else
        {
            // Receive latest state information
            int gmState = (int)state;
            int rdTmScre = redTeamScore;
            int blTmScre = blueTeamScore;

            int rdCptrs = redCaptures;
            int blCptrs = blueCaptures;
            float strtTime = startTime;
            float gmTime = gameTime;
            float gmTimeMax = gameTimeMax;

            stream.Serialize(ref gmState);
            stream.Serialize(ref rdTmScre);
            stream.Serialize(ref blTmScre);
            stream.Serialize(ref rdCptrs);
            stream.Serialize(ref blCptrs);
            stream.Serialize(ref strtTime);
            stream.Serialize(ref gmTime);
            stream.Serialize(ref gmTimeMax);

            state = (GameState)gmState;
            redTeamScore = rdTmScre;
            blueTeamScore = blTmScre;

            redCaptures = rdCptrs;
            blueCaptures = blCptrs;
            startTime = strtTime;
            gameTime = gmTime;
            gameTimeMax = gmTimeMax;
        }
    }
コード例 #54
0
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.Serialize(ref ReadyTimer);
         stream.Serialize(ref MatchStarted);
     }
     else
     {
         stream.Serialize(ref ReadyTimer);
         stream.Serialize(ref MatchStarted);
     }
 }
コード例 #55
0
ファイル: TankDamage.cs プロジェクト: gus5345/Unity_DomainWar
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        stream.Serialize(ref nowtankHp); // 한번에 두개를 다 처리하는 부분 , HP 동기화 부분

        //↓↓↓↓↓ HP게이지와 텍스트 HP를 HP양의 따라 색깔별로 구별하는 부분
        if(pv.isMine) // 자기 자신만 하게끔 , 이걸 안하면 다른 플레이어의 HP가 한번 들어옴
        {
            textHp.text = nowtankHp.ToString();
            hpColor = (float)nowtankHp / (float)tankHp;
            if (hpColor <= 0.4f)
            {
                textHp.color = Color.red;
            }
            else if (hpColor <= 0.6f)
            {
                textHp.color = Color.magenta;
            }
            else if (hpColor <= 1.0f)
            {
                textHp.color = Color.green;
            }
        }
    }
コード例 #56
0
ファイル: Player.cs プロジェクト: santiamchristian/compro2016
 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.Serialize(ref currentGate);
             stream.Serialize(ref currentLap);
         stream.Serialize(ref Ready);
     }
     else
     {
         stream.Serialize(ref currentGate);
         stream.Serialize(ref currentLap);
         stream.Serialize(ref Ready);
     }
 }
コード例 #57
0
    protected void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        //stream.isWriting
        if (!rigidbody) return;
        if (stream.isWriting)
        {
            syncPos = rigidbody.position;
            syncRot = rigidbody.rotation;
            syncVel = rigidbody.velocity;
            syncAng = rigidbody.angularVelocity;
        }
        stream.Serialize(ref syncPos);
        stream.Serialize(ref syncRot);
        stream.Serialize(ref syncVel);
        stream.Serialize(ref syncAng);
        if (GameType.weapons)
        {
            stream.Serialize(ref distanceToCursor2);
            stream.Serialize(ref TargetPlayerId);
        }
        if (stream.isReading)
        {

            if (Vector3.Distance(rigidbody.position, syncPos) > clampMax && Time.time - collisionTime > 1)
            {
                transform.position = syncPos;
                transform.rotation = syncRot;
            }
            syncPos += syncVel * Mathf.Min(.2f, ping);
            Debug.DrawLine(pos, syncPos, Color.yellow, 2);
            rigidbody.velocity = syncVel;
            rigidbody.angularVelocity = syncAng;
            offsetPos = syncPos - pos;
            if (Mathf.Abs(offsetPos.y) < .1f) offsetPos.y = 0;
            offsetRot = syncRot * Quaternion.Inverse(rot);
        }

        ping = Mathf.Lerp(ping, Mathf.Max(0, (float)(PhotonNetwork.time - info.timestamp)), .1f);
    }
コード例 #58
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);
            stream.Serialize(ref moveSpeed);
            stream.Serialize(ref myVelocity);
            stream.Serialize(ref rotationSpeed);
            stream.Serialize(ref isRotatingRight);

        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref moveSpeed);
            stream.Serialize(ref myVelocity);
            stream.Serialize(ref rotationSpeed);
            stream.Serialize(ref isRotatingRight);

            latestCorrectPos = pos;
            latestCorrectRot = rot;
            onUpdatePos = transform.localPosition;
            onUpdateRot = transform.localRotation;
            fraction = 0;

        }
    }
コード例 #59
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        // Always send transform(depending on reliability of the network view)
        if (stream.isWriting)
        {
            Vector2 pos = (Vector2)transform.localPosition;
        Vector2 velocity = playerControl.velocity;
        bool isFacingRight = playerControl.facingRight;
            stream.Serialize(ref pos);
            stream.Serialize(ref velocity);
        stream.Serialize(ref isFacingRight);
        }
        // When receiving, buffer the information
        else
        {
            // Receive latest state information
            Vector2 pos = Vector2.zero;
        Vector2 velocity = Vector2.zero;
        bool isFacingRight = false;
            stream.Serialize(ref pos);
        stream.Serialize(ref velocity);
        stream.Serialize(ref isFacingRight);

        //Make proper face direction
        playerControl.UpdateFaceDir(isFacingRight);

            // Shift buffer contents, oldest data erased, 18 becomes 19, ... , 0 becomes 1
            for (int i = m_BufferedState.Length - 1; i >= 1; i--)
            {
                m_BufferedState[i] = m_BufferedState[i - 1];
            }

            // Save currect received state as 0 in the buffer, safe to overwrite after shifting
            State state;
            state.timestamp = info.timestamp;
            state.pos = pos;
        state.velocity = velocity;
            m_BufferedState[0] = state;

            // Increment state count but never exceed buffer size
            m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);

            // Check integrity, lowest numbered state in the buffer is newest and so on
            for (int i = 0; i < m_TimestampCount - 1; i++)
            {
                if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
                    Debug.Log("State inconsistent");
            }
        }
    }
コード例 #60
0
    protected void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        var v = vel;
        var sk = skid;
        syncPos = pos;
        syncRot = rot;
        stream.Serialize(ref v);
        stream.Serialize(ref sk);
        if (_Loader.dm)
        {
            stream.Serialize(ref distanceToCursor2);
            stream.Serialize(ref TargetPlayerId);
        }
        stream.Serialize(ref syncPos);
        stream.Serialize(ref syncRot);
        //}
        if (stream.isReading)
        {
            if (stopAudio != null)
                stopAudio.volume = sk; 
            vel = v;
            //ping = Mathf.Max(0, (float)(PhotonNetwork.time - info.timestamp));
            ping = Mathf.Lerp(ping, Mathf.Max(0, (float)(PhotonNetwork.time - info.timestamp)), .1f);
            if (_Loader.mpCollisions)
            {
                if (Vector3.Distance(rigidbody.position, syncPos) > clampMax)
                {
                    transform.position = syncPos;
                    transform.rotation = syncRot;
                }
                else
                {
                    var c = Time.time - collisionTime > 1;
                    if (Vector3.Distance(rigidbody.position, syncPos) > clampMax && c)
                    {
                        transform.position = syncPos;
                        transform.rotation = syncRot;
                    }
                    syncPos += vel * ping;
                    Debug.DrawLine(pos, syncPos, Color.yellow, 2);
                    rigidbody.velocity = vel;
                    offsetPos = syncPos - pos;
                    offsetRot = syncRot * Quaternion.Inverse(rot);
                }
                Debug.DrawLine(pos, syncPos, Color.yellow, 2);
            }
            else
            {
                for (int i = m_BufferedState.Length - 1; i >= 1; i--)
                    m_BufferedState[i] = m_BufferedState[i - 1];

                float f = Mathf.Min(2, (float)(PhotonNetwork.time - m_BufferedState[0].timestamp) + .2f);
                interpolationBackTime = setting.lagNetw ? 3 : Mathf.Lerp(interpolationBackTime, f, interpolationBackTime > f ? .01f : .5f);
                State state;
                state.timestamp = info.timestamp;
                state.pos = syncPos;
                state.rot = syncRot;
                m_BufferedState[0] = state;
                m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);
                for (int i = 0; i < m_TimestampCount - 1; i++)
                    if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
                        Debug.Log("State inconsistent");
            }

        }

    }