2014-05-08 19 views
0

這是一款多層遊戲,我需要發送服務器的位置和旋轉值,然後再從那裏取回.Google只允許通過字節發送。這就是我想要的。如何發送transform.position和transform.rotation值?

float aa; 
float bb; 
float cc; 


byte[] xx =new byte[5]; 
byte[] yy =new byte[5]; 
byte[] zz =new byte[5]; 

Update() 
{ 
aa=transform.postion.x; 
bb=transform.postion.y; 
cc = transform.postion.z; 

xx = System.BitConverter.GetBytes (aa); 
yy = System.BitConverter.GetBytes(bb); 
zz = System.BitConverter.GetBytes(cc); 

PlayGamesPlatform.Instance.RealTime..SendMessageToAll(false,xx); 
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false,yy); 
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(false,zz); 

} 

如果我這樣發送,我怎麼知道發送的數據是什麼?

public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data) { 
if(data[0]==(byte)'R') 
{ 
    //Convert back the data 
    float xyz = System.BitConverter.ToSingle(data,0); 
} 
} 

所以我的問題是如何通過Unity3D發送位置值和輪換在Google Play多人遊戲?你們好嗎?這種方法沒有給出任何編譯錯誤,但我有強烈的感覺,這是不正確的方式,有比這更好的方法。

+0

你有沒有得到任何解決方案? –

回答

0

在你的例子中使用State Synchronization會容易得多。但是,請注意,在多人遊戲中工作總是一種折衷的遊戲,您必須確定要實現的目標。大規模RTS的網絡代碼與快節奏的FPS完全不同。

+0

我正在使用Google Play多人遊戲服務。 – user1506106