private void OnConnectCallback(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; string MethodName = p.GetString(startIndex, ref startIndex); int returnCode = p.GetInt(startIndex, ref startIndex); if (returnCode == 0) { Debug.Log("连接成功"); UIManager.Instance.ShowUI(UIid.MainUI); MessageCenter.Send(EMessageType.PlayerName, inputField.text); UIManager.Instance.HideTheUI(this.uiId, () => { }); } else { Debug.Log("连接失败"); UIManager.Instance.ShowUI(UIid.TipsUI); object[] param = new object[2]; param[0] = "连接失败\n可能原因:昵称已被使用、服务器问题 或 网络故障"; param[1] = "知道了"; MessageCenter.Send_Multparam(EMessageType.TipsUI, param); } }
/// <summary> /// 请求获得道具数据 /// </summary> public void RequestItemData() { BytesProtocol p = new BytesProtocol(); p.SpliceString("GetMapItemData"); NetworkManager.Send(p); }
protected override void OnEnable() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("GetRoomInfo"); NetworkManager.ServerConnection.Send(protocol, GetRoomInfo); }
/// <summary> /// 发送玩家被毒圈伤害消息 /// </summary> public static void SendPlayerPoison() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("PlayerPoison"); Send(protocol); }
private void RequestStartGame() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("RequestStartGame"); NetworkManager.ServerConnection.Send(protocol, OnRequestStartGameBack); }
private void StartGame() { if (inputField.text == "") { UIManager.Instance.ShowUI(UIid.TipsUI); object[] param = new object[2]; param[0] = "昵称不可以为空"; param[1] = "知道了"; MessageCenter.Send_Multparam(EMessageType.TipsUI, param); return; } //未连接则连接 if (NetworkManager.ServerConnection.connectionStatus != Connect.ConnectionStatus.Connected) { NetworkManager.ServerConnection.protocol = new BytesProtocol(); NetworkManager.ServerConnection.ConnectToServer(clientConf.Host, clientConf.Port); } BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("Connect"); protocol.SpliceString(inputField.text); NetworkManager.PlayerName = inputField.text; NetworkManager.ServerConnection.Send(protocol, OnConnectCallback); //UIManager.Instance.ShowUI(UIid.LoadingUI); //MessageCenter.Send(EMessageType.Loading, 1); }
/// <summary> /// 更新网络玩家数据 /// </summary> /// <param name="protocol"></param> public void UpdatePlayerInfo(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); string playerName = p.GetString(startIndex, ref startIndex); float HP = p.GetFloat(startIndex, ref startIndex); float posX = p.GetFloat(startIndex, ref startIndex); float posY = p.GetFloat(startIndex, ref startIndex); float posZ = p.GetFloat(startIndex, ref startIndex); float rotX = p.GetFloat(startIndex, ref startIndex); float rotY = p.GetFloat(startIndex, ref startIndex); float rotZ = p.GetFloat(startIndex, ref startIndex); string CurrentAction = p.GetString(startIndex, ref startIndex); //自己的消息 if (playerName == NetworkManager.PlayerName) { BagManager.Instance.characterStatus.HP = HP; } if (ScenePlayers.ContainsKey(playerName)) { ScenePlayers[playerName].SetPlayerInfo(HP, CurrentAction); ScenePlayers[playerName].SetPlayerTransform(posX, posY, posZ, rotX, rotY, rotZ); } }
/// <summary> /// 发送请求下落点 /// </summary> public static void SendReqDroppoint() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("Droppoint"); Send(protocol); }
public static BaseProtocol GetHeartBeat() { BytesProtocol bytesProtocol = new BytesProtocol(); bytesProtocol.SpliceString("HeartBeat"); return(bytesProtocol); }
/// <summary> /// 获取地图道具随机数种子 /// </summary> private void OnGetMapItemDataBack(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); Seed = p.GetInt(startIndex, ref startIndex); object[] param = new object[2]; param[0] = "正在接收道具数据..."; param[1] = 0; MessageCenter.Send_Multparam(EMessageType.LoadingUI, param); if (Seed != 0) { //220个物品生成点的随机数 RandomList = InitTotalProbabilityValue(ProbabilityValue); param[0] = "道具数据接收完毕"; param[1] = 0; MessageCenter.Send_Multparam(EMessageType.LoadingUI, param); GenerateItem(); } else { Debug.LogError("Seed异常 " + Seed.ToString() + " 无法加载"); } }
/// <summary> /// 发送获取玩家列表消息 /// </summary> public static void SendGetPlayersInfo() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("GetPlayersInfo"); ServerConnection.Send(protocol); }
/// <summary> /// 地图加载完毕时上报服务端统计 /// </summary> public static void SendMapLoaded() { BytesProtocol p = new BytesProtocol(); p.SpliceString("MapLoaded"); ServerConnection.Send(p); }
/// <summary> /// 获取玩家列表回调 /// </summary> public void OnGetPlayersInfo(BaseProtocol baseProtocol) { BytesProtocol p = baseProtocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); int Playernum = p.GetInt(startIndex, ref startIndex); UnityEngine.Object playerprefab = Resources.Load("NetPlayerPrefab"); GameObject tmp_player = null; for (int i = 0; i < Playernum; i++) { string playerName = p.GetString(startIndex, ref startIndex); //自己不需要更新 if (playerName != NetworkManager.PlayerName) { tmp_player = Instantiate(playerprefab) as GameObject; tmp_player.name = playerName; tmp_player.transform.SetParent(transform); NetworkPlayer nPlayer = tmp_player.GetComponent <NetworkPlayer>(); nPlayer.SetPlayerName(playerName); ScenePlayers.Add(playerName, nPlayer); nPlayer.LastUpdateTime = NetworkManager.GetTimeStamp(); } } }
private void RefreshRoom() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("GetRoomList"); NetworkManager.ServerConnection.Send(protocol); }
/// <summary> /// 玩家死亡处理 /// </summary> /// <param name="protocol"></param> private void OnPlayerKilled(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); //杀手名 string KillerName = p.GetString(startIndex, ref startIndex); //被杀玩家名 string KilledPlayerName = p.GetString(startIndex, ref startIndex); //玩家死亡处理 if (KilledPlayerName == NetworkManager.PlayerName) { UIManager.Instance.ShowUI(UIid.FinishUI); object[] param = new object[3]; param[0] = "无畏之争——无谓之争"; param[1] = "你被 " + KillerName + " 击杀"; param[2] = " "; MessageCenter.Send_Multparam(EMessageType.FinishUI, param); CameraBase.Instance.isFollowing = false; return; } DelPlayer(KilledPlayerName); }
private void CreateRoom() { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("CreateRoom"); NetworkManager.ServerConnection.Send(protocol, OnCreateRoomBack); }
/// <summary> /// 发送玩家可以开玩 /// </summary> public static void SendPlayerReady() { BytesProtocol ready = new BytesProtocol(); ready.SpliceString("PlayerReady"); ready.SpliceString(NetworkManager.PlayerName); Send(ready); }
/// <summary> /// 发送装备武器ID /// </summary> public static void SendPlayerEquipWeapon(int ItemID) { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("PlayerEquipWeapon"); protocol.SpliceInt(ItemID); Send(protocol); }
/// <summary> /// 发送门打开消息 /// </summary> /// <param name="DoorID">门ID</param> public static void SendDoorOpen(int DoorID) { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("DoorOpen"); protocol.SpliceInt(DoorID); Send(protocol); }
public void JoinRoom(int RoomIndex) { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("JoinRoom"); protocol.SpliceInt(RoomIndex); NetworkManager.ServerConnection.Send(protocol, OnJoinRoomBack); }
/// <summary> /// 玩家离开 /// </summary> public void PlayerLeave(string playerName) { BytesProtocol p = new BytesProtocol(); p.SpliceString("LeaveRoom"); NetworkManager.Send(p, OnLeaveRoomBack); DelPlayer(playerName); }
/// <summary> /// 发送拾取物品消息 /// </summary> public static void SendPickItem(int GroundItemID) { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("PickItem"); protocol.SpliceInt(GroundItemID); Send(protocol); }
/// <summary> /// 发送击中玩家消息 /// </summary> /// <param name="Name">玩家名</param> /// <param name="Damage">伤害值</param> public static void SendPlayerHitSomeone(string Name, float Damage) { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("PlayerHitSomeone"); protocol.SpliceString(Name); protocol.SpliceFloat(Damage); ServerConnection.Send(protocol); }
private void OnStartGameBack(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); UIManager.Instance.ShowUI(UIid.LoadingUI); MessageCenter.Send(EMessageType.LoadingScene, new object()); }
/// <summary> /// 发送 玩家有害状态 /// </summary> public static void SendPlayerGetBuff(string playerName, BuffType buffType, float buffTime) { BytesProtocol p = new BytesProtocol(); p.SpliceString("PlayerGetBuff"); p.SpliceString(playerName); p.SpliceInt((int)buffType); p.SpliceFloat(buffTime); Send(p); }
/// <summary> /// 发送扔物品消息 /// </summary> public static void SendDropItem(int GroundItemID, Transform trans) { BytesProtocol protocol = new BytesProtocol(); protocol.SpliceString("DropItem"); protocol.SpliceInt(GroundItemID); protocol.SpliceFloat(trans.position.x); protocol.SpliceFloat(trans.position.y); protocol.SpliceFloat(trans.position.z); Send(protocol); }
public void OnCirclefieldTimeBack(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); int HoldTime = p.GetInt(startIndex, ref startIndex); //HUDUI倒计时显示 countdownTime = HoldTime; Moving = false; }
/// <summary> /// 游戏物品被拾取处理 /// </summary> /// <param name="protocol"></param> public void OnPickItem(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); int GroundItemID = p.GetInt(startIndex, ref startIndex); if (Items.ContainsKey(GroundItemID)) { Items[GroundItemID].Hide(); } }
private void OnLeaveRoomBack(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); int returnCode = p.GetInt(startIndex, ref startIndex); if (returnCode == 0) { UIManager.Instance.ShowUI(UIid.MainUI); } }
/// <summary> /// 开门 /// </summary> /// <param name="protocol"></param> public void OnDoorOpen(BaseProtocol protocol) { BytesProtocol p = protocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); int DoorID = p.GetInt(startIndex, ref startIndex); if (itemSpawnPoint.DoorSpawnPoints[DoorID] != null) { Doors[DoorID].gameObject.GetComponent <DoorControl>().ControlDoor(); } }