예제 #1
0
    /// <summary>
    /// Serialises data to each player
    /// Note not called if only player in the room
    /// </summary>
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (!m_initialised)
        {
            return;
        }

        if (stream.isWriting)
        {
            stream.SendNext(m_networkedTimePassed);
            stream.SendNext((int)m_gameManager.GetState());

            for (int i = 0; i < m_nodes.Count; ++i)
            {
                stream.SendNext(m_nodes[i].OwnerID);
                stream.SendNext(m_nodes[i].TimeStamp);
            }
        }
        else
        {
            m_networkedTimePassed = (float)stream.ReceiveNext();
            m_networkedState      = (GameState)stream.ReceiveNext();

            for (int i = 0; i < m_nodes.Count; ++i)
            {
                int    ownerID   = (int)stream.ReceiveNext();
                double timestamp = (double)stream.ReceiveNext();
                m_nodes[i].TrySetOwner(ownerID, timestamp);
            }
        }
    }