public override int GetHashCode() { int hash = 1; if (changeCase_ == ChangeOneofCase.PlayerJoin) { hash ^= PlayerJoin.GetHashCode(); } if (changeCase_ == ChangeOneofCase.PlayerLeave) { hash ^= PlayerLeave.GetHashCode(); } if (changeCase_ == ChangeOneofCase.HostLeave) { hash ^= HostLeave.GetHashCode(); } if (token_ != null) { hash ^= Token.GetHashCode(); } hash ^= (int)changeCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
void OnClientReady(ClientReady ready, Connection conn) { if (conn.state == ConnState.WaitForReady) { conn.state = ConnState.InGame; Player p = lm.AddPlayer(ControllerType.Remote, NewPlayerId(), conn.playerName); conn.playerId = p.id; //发送游戏状态 InitServerGameInfo info = new InitServerGameInfo(); //此客户端的玩家信息 info.clientLocalPlayer = p.AchievePlayerInfo(); //其他玩家的信息 info.elsePlayers = new PlayerInfo[lm.playerCount - 1]; lm.AchievePlayerInfo(info.elsePlayers, p.id); Server.SendMessage(new GameMsg(GameMsg.MsgType.InitServerGameInfo, info), conn.connId, UnityEngine.Networking.QosType.ReliableSequenced); //通知其他玩家 PlayerJoin join = new PlayerJoin(); join.info = info.clientLocalPlayer; GameMsg msg = new GameMsg(GameMsg.MsgType.PlayerJoin, join); SendToAllClientsInGame(msg, conn.connId, UnityEngine.Networking.QosType.ReliableSequenced); } }
private void HandlePlayerJoin(string incomingUserID, string incomingUsername) { //If joining is not allowed then tell user and exit if (!joinAllowed) { TwitchChatClient.Instance.SendChatMessageTargeted(incomingUsername, "Joining the minigame is not currently allowed!"); return; } //Add the user to our user list - if they are not already if (!joinedUsers.ContainsKey(incomingUserID)) { TwitchUser user = new TwitchUser(incomingUserID, incomingUsername); joinedUsers.Add(incomingUserID, user); //Tell the user that we have added them TwitchChatClient.Instance.SendChatMessageTargeted(incomingUsername, "You have been added to the game!"); PlayerJoin?.Invoke(incomingUsername); //We just added a new user, check if we have reached our max player count if we have then stop new joins if (joinedUsers.Count == maxPlayersInList) { SetAllowJoin(false, "Max players reached"); } } }
void Start() { playerJoins = new List <PlayerJoin>(); for (int i = 0; i < 4; i++) { PlayerJoin playerJoin = Instantiate(playerJoinUI, Vector3.zero, Quaternion.identity, playerJoinContainer.transform).GetComponent <PlayerJoin>(); playerJoin.playerNum = i; playerJoins.Add(playerJoin); } }
protected void Awake() { instance = this; playersJoined = new List <NewPlayerInfo>(); numbers = new string[] { "One", "Two", "Three", "Four" }; interactAction = asset.FindAction("InteractPressed"); interactAction.performed += JoinPlayer; interactAction.Enable(); }
public void Datahandle(byte[] bytes) { BaseNetObject bno = NetBaseTool.BytesToObject(bytes) as BaseNetObject; if (bno is SystemNetObject) { SystemNetObject systemNetObject = bno as SystemNetObject; if (systemNetObject.GetType() == typeof(Msg)) { Console.WriteLine(systemNetObject); } else if (systemNetObject.GetType() == typeof(GetMyUserData)) { MyUserData = (systemNetObject as GetMyUserData).userData; } else if (systemNetObject.GetType() == typeof(CreateRoomS2C)) { transmit = (systemNetObject as CreateRoomS2C).PlayerId; wait.Set(); } else if (systemNetObject.GetType() == typeof(JoinRoomS2C)) { transmit = (systemNetObject as JoinRoomS2C); wait.Set(); } else if (systemNetObject.GetType() == typeof(GetRoomListS2C)) { transmit = (systemNetObject as GetRoomListS2C).rooms; wait.Set(); } else if (systemNetObject.GetType() == typeof(PlayerJoinS2C)) { PlayerJoin?.Invoke((systemNetObject as PlayerJoinS2C).playerId); } else if (systemNetObject.GetType() == typeof(PlayerLeaveS2C)) { PlayerLeave?.Invoke((systemNetObject as PlayerLeaveS2C).playerId); } else if (systemNetObject.GetType() == typeof(GameStart)) { StartAction?.Invoke(); } } else { GameNetObject gno = bno as GameNetObject; if (gno == null) { throw new ArgumentException(bno.GetType() + " Can't Used"); } ReceiveAction?.Invoke(gno); } //防止死锁 // wait.Set(); }
void OnDateEvent(Protocol.GameMsg msg, int connection) { if (msg.type == GameMsg.MsgType.PlayerJoin) { //新增玩家 PlayerJoin join = msg.content as PlayerJoin; if (join != null) { OnRemotePlayerJoin(join); } } else if (msg.type == GameMsg.MsgType.PlayerQuit) {//移出 PlayerQuit quit = msg.content as PlayerQuit; if (quit != null) { OnRemotePlayerQuit(quit); } } else if (msg.type == GameMsg.MsgType.ServerGameState) { //更新 ServerGameState state = msg.content as ServerGameState; if (state != null) { OnUpdateGameInfo(state); } } else if (msg.type == GameMsg.MsgType.InitServerGameInfo) { //开始游戏 InitServerGameInfo state = msg.content as InitServerGameInfo; if (state != null) { OnInitClientGame(state); } } else if (msg.type == GameMsg.MsgType.Damage) { HitPlayer hit = msg.content as HitPlayer; if (hit != null) { OnDamage(hit); } } else if (msg.type == GameMsg.MsgType.Shoot) { PlayerShoot shoot = msg.content as PlayerShoot; if (shoot != null) { OnShoot(shoot); } } }
void OnRemotePlayerJoin(PlayerJoin join) { if (initRecieved) { PlayerInfo remoteInfo = join.info; if (remoteInfo != null) { Player remotePlayer = lm.AddPlayer(ControllerType.Remote, remoteInfo.id, remoteInfo.name); RemotePlayerController rpc = remotePlayer.GetComponent <RemotePlayerController>(); rpc.ApplyRemoteInfo(remoteInfo); } } }
void Update() { CheckPlayersJoining(); if (ReadyToStart() && Input.GetButtonDown("StartButton1")) { for (int i = 0; i < lobbyPlayers.Length; i++) { PlayerJoin playerJoin = lobbyPlayers[i].gameObject.GetComponent <PlayerJoin>(); playerJoin.m_LockedJoin = true; } StartCoroutine(StartGame()); } }
void CheckPlayersJoining() { m_NumReady = 0; for (int i = 0; i < lobbyPlayers.Length; i++) { PlayerJoin playerJoin = lobbyPlayers[i].gameObject.GetComponent <PlayerJoin>(); m_ReadyPlayers[playerJoin.m_PlayerNumber - 1] = playerJoin.joined; } for (int j = 0; j < m_ReadyPlayers.Length; j++) { if (m_ReadyPlayers[j]) { m_NumReady++; } } }
void OnEnable() { container = PlayerConfigurationContainer.getInstance(); players = container.Configurations; players.Clear(); InputManager.OnDeviceDetached += OnDeviceDetached; playerJoin = GetComponent <PlayerJoin> (); selectKeyboardListenerP1 = CharacterSelectActions.CreateWithKeyboardBindingsToSelectCharacter(Key.A, Key.D, Key.LeftShift); selectKeyboardListenerP2 = CharacterSelectActions.CreateWithKeyboardBindingsToSelectCharacter(Key.LeftArrow, Key.RightArrow, Key.RightShift); joinKeyboardListener = CharacterSelectActions.CreateWithKeyboardBindingsToJoin(); joystickListener = CharacterSelectActions.CreateWithJoystickBindings(); keyboardP1 = PlayerActions.CreateWithKeyboardBindingsForPlayerOne(); keyboardP2 = PlayerActions.CreateWithKeyboardBindingsForPlayerTwo(); }
public void MergeFrom(RoomStateChangePayload other) { if (other == null) { return; } if (other.token_ != null) { if (token_ == null) { Token = new global::Prisel.Protobuf.UpdateToken(); } Token.MergeFrom(other.Token); } switch (other.ChangeCase) { case ChangeOneofCase.PlayerJoin: if (PlayerJoin == null) { PlayerJoin = new global::Prisel.Protobuf.PlayerInfo(); } PlayerJoin.MergeFrom(other.PlayerJoin); break; case ChangeOneofCase.PlayerLeave: PlayerLeave = other.PlayerLeave; break; case ChangeOneofCase.HostLeave: if (HostLeave == null) { HostLeave = new global::Prisel.Protobuf.RoomStateChangePayload.Types.HostLeaveData(); } HostLeave.MergeFrom(other.HostLeave); break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public void AddAI() { if (AIIdList.Count < 3) { int id = NewPlayerId(); Player player = lm.AddPlayer(ControllerType.LocalAI, id, "AI id:" + id); AIIdList.Add(id); if (inGameClientPlayerCount > 0) { //通知其他玩家 PlayerJoin join = new PlayerJoin(); join.info = player.AchievePlayerInfo(); GameMsg msg = new GameMsg(GameMsg.MsgType.PlayerJoin, join); SendToAllClientsInGame(msg, UnityEngine.Networking.QosType.ReliableSequenced); } } else { UIManager um = UnityHelper.GetUIManager(); um.AddScrollMessage("AI数量达到上限"); } }
public static void OnPlayerJoin(PlayerJoinEventArgs args) { PlayerJoin?.Invoke(args); }
public void AddPlayer(Player player) { _players.Add(player); PlayerJoin?.Invoke(player); }