2017-02-25 8 views
0

이 코드는 다른 사람으로부터 원시 데이터를 받아 변환합니다. 지금 당장 다른 플레이어가 추가 한 오브젝트를 다른 플레이어가 두 번째 플레이어 화면에 추가 한 오브젝트에 추가해야합니다.피어 투 피어 (Peer to Peer) 연결을 통해 GameObject가 가진 어떤 부모에 관한 데이터를 전달합니까?

public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data) 
{ 
    byte messageVersion = (byte)data[0]; 
    // Let's figure out what type of message this is. 
    char messageType = (char)data[1]; 
    if (messageType == 'U' && data.Length == _updateMessageLength) 
    { 
     float posX = System.BitConverter.ToSingle(data, 2); 
     float posY = System.BitConverter.ToSingle(data, 6); 


     // We'd better tell our GameController about this. 
     if (updateListener != null) 
     { 
      updateListener.UpdateReceived(senderId, posX, posY); 
     } 
    } 
} 

이 코드는 google play 서비스를 통해 다른 플레이어에게 메시지를 보냅니다.

public void SendMyUpdate(GameObject childObj) 
{ 
    _updateMessage.Clear(); 
    _updateMessage.Add(_protocolVersion); 
    _updateMessage.Add((byte)'U'); 
    _updateMessage.AddRange(System.BitConverter.GetBytes(childObj)); 

    byte[] messageToSend = _updateMessage.ToArray(); 

    PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false, messageToSend); 
} 

이 게임은 박하 사탕 발가락 같은 간단한 게임을 위해 박하 사탕 발가락

답변

0

처럼, 당신이 훨씬 더 기본적인 수준의 게임 상태를 전달 추천 할 것입니다.

게임의 상태가 3x3 문자 배열로되어 있다고 가정합니다. 배열의 각 요소는 플레이어가 자신의 행동을 수행 할 때마다, 당신은 배열의 클라이언트의 로컬 복사본을 업데이트 이제 하나

' ' 
'X' 
'O' 

입니다. 그런 다음이 3x3 어레이를 네트워크를 통해 쉽게 보낼 수 있습니다. 수신 클라이언트는 그에 따라 배열을 업데이트 할 수 있습니다.

+0

다른 플레이어에게 넘겨 주기로 결정했지만 여전히 데이터가 나타나지 않아 디버그가 트리거되지 않습니다. 나는 adb logcat을 사용하고있다. –