public void SendHealth(float health) { PlayInfoData playInfo = new PlayInfoData(user.UserId, user.UserName, localTransform, false, (int)health, 15f); ProtocalData data = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo); Send(data); }
public void AddPlayer(PlayInfoData data) { Color color = tankColors[PlayerList.Count]; GameObject tank = gameManager.AddTank(PlayerList.Count + 1, color, data.PlayName, data.UserId, data.GetPosition(), data.GetRotation()); PlayerList.Add(data.UserId, tank); gameManager.m_PlayerList.AddItem(tank.name, color); }
public void SendFire(float force) { Complete.TankHealth th = this.player.GetComponent <Complete.TankHealth>(); var health = th.GetCurrentHealth(); PlayInfoData playInfo = new PlayInfoData(user.UserId, user.UserName, localTransform, true, (int)health, force); ProtocalData data = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo); Send(data); }
private void SendLocalPlayer() { Complete.TankHealth th = this.player.GetComponent <Complete.TankHealth>(); var health = th.GetCurrentHealth(); PlayInfoData playInfo = new PlayInfoData(user.UserId, user.UserName, player.transform, false, (int)health, 15f); ProtocalData data = new ProtocalData(ActionCode.MsgPlayInfoData, playInfo); Send(data); }
/// <summary> /// 玩家退出事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PlayerLogOutEvent(object sender, ProtocalData e) { PlayInfoData playInfo = ProtoBufSerializable.Decode <PlayInfoData>(e.Bytes); GameObject tank; if (PlayerList.TryGetValue(playInfo.UserId, out tank)) { RemovePlayer(playInfo.UserId); gameManager.RemoveTank(playInfo.UserId); gameManager.m_PlayerList.RemoveItem(tank.name); UnityEngine.Object.DestroyObject(tank); } }
public override void OnResponse(ProtocalData msg) { PlayInfoData playInfo = ProtoBufSerializable.Decode <PlayInfoData>(msg.Bytes); if (PlayerManager.Instance.LocalPlayer.UserId == playInfo.UserId) { return; } GameObject tank; if (PlayerManager.Instance.PlayerList.TryGetValue(playInfo.UserId, out tank)) { tank.GetComponent <Complete.TankMovement>().RemoteTransform(playInfo.GetPosition(), playInfo.GetRotation()); if (playInfo.Shoot) { tank.GetComponent <Complete.TankShooting>().Fire(playInfo.Force); } tank.GetComponent <Complete.TankHealth>().SyncHealth(playInfo.ServerHealth); } else { PlayerManager.Instance.AddPlayer(playInfo); } }