//获取客户端位置请求的处理的代码 public void OnSyncTransformReceived(Client peer, OperationRequest operationRequest, SendParameters sendParameters) { //接收位置并保持起来 byte[] bytes = (byte[])DictTool.GetValue <byte, object>(operationRequest.Parameters, 1); ProtoData.SyncTransformC2S syncTransformC2S = BinSerializer.DeSerialize <ProtoData.SyncTransformC2S>(bytes); peer.playerData.heroData.x = syncTransformC2S.x; peer.playerData.heroData.y = syncTransformC2S.y; peer.playerData.heroData.z = syncTransformC2S.z; peer.playerData.heroData.angleY = syncTransformC2S.angleY; }
//发起位置信息请求 public void SendSyncTransformRequest(Vector3 pos, float angleY) { ProtoData.SyncTransformC2S syncTransformC2S = new ProtoData.SyncTransformC2S(); syncTransformC2S.x = pos.x; syncTransformC2S.y = pos.y; syncTransformC2S.z = pos.z; syncTransformC2S.angleY = angleY; byte[] bytes = BinSerializer.Serialize(syncTransformC2S); //把位置信息x,y,z传递给服务器端 Dictionary <byte, object> data = new Dictionary <byte, object>(); data.Add(1, bytes); PhotonEngine.Peer.OpCustom((byte)MessageCode.SyncTransform, data, true);//把Player位置传递给服务器 }