void SelectHandler(Peer peer, byte[] data) { SelectObj selectObj = MessagePackSerializer.Deserialize <SelectObj>(data); if (selectObj.Type < UnitType.HatsuneMiku || selectObj.Name == "" || selectObj.Team == Team.Yellow) { return; } if (state == NetworkState.Lobby) { peers[peer.ID] = new GameClient(peer, selectObj.Name, selectObj.Team, selectObj.Type, selectObj.Ready, -1); } else if (state == NetworkState.Countdown) { peers[peer.ID].Ready = selectObj.Ready; if (!selectObj.Ready) { state = NetworkState.Lobby; } } else { peers[peer.ID] = new GameClient(peer, selectObj.Name, selectObj.Team, selectObj.Type, false, -1); } SendLobby(PacketFlags.Reliable); }
public void Set() { SelectObj selectObj = new SelectObj() { Type = type, Name = nameInputField.text, Team = _team, Ready = _ready }; Send(MessageType.Select, MessagePackSerializer.Serialize(selectObj), PacketFlags.Reliable); }
void LobbyHandler(byte[] data) { LobbyObj lobbyObj = MessagePackSerializer.Deserialize <LobbyObj>(data); if (!applyPlayerSelectObj && playerSelectObj == null) { playerSelectObj = lobbyObj.PeerSelectObj; if (state == SceneState.Lobby) { type = playerSelectObj.Type; SetUnitTypeIcon(type); _name = playerSelectObj.Name; nameInputField.text = playerSelectObj.Name; _team = playerSelectObj.Team; SetTeamButtonColor(_team); _ready = playerSelectObj.Ready; SetReadyButtonColor(_ready); applyPlayerSelectObj = true; playerSelectObj = null; } } if (state == SceneState.Lobby) { if (lobbyObj.State == 0) { lobbyTitle.text = "Before Battle"; } else if (lobbyObj.State == 1) { lobbyTitle.text = lobbyObj.Timer.ToString("F0"); } else { lobbyTitle.text = "In Battle"; } bluePlayerNodeInstances.ForEach(x => Destroy(x)); bluePlayerNodeInstances.Clear(); redPlayerNodeInstances.ForEach(x => Destroy(x)); redPlayerNodeInstances.Clear(); foreach (SelectObj selectObj in lobbyObj.SelectObjs) { if (selectObj.Team == Team.Blue) { GameObject instance = Instantiate(playerNodePrefab, blueContentRectTransform); instance.GetComponent <PlayerNode>().SetData(selectObj.Type, selectObj.Team, selectObj.Name, selectObj.Ready); bluePlayerNodeInstances.Add(instance); } else { GameObject instance = Instantiate(playerNodePrefab, redContentRectTransform); instance.GetComponent <PlayerNode>().SetData(selectObj.Type, selectObj.Team, selectObj.Name, selectObj.Ready); redPlayerNodeInstances.Add(instance); } } } else if (state == SceneState.Main) { SceneManager.LoadScene("Lobby"); } }
public void TriggeredStart() { Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); Enum.TryParse(SceneManager.GetActiveScene().name, out state); if (state == SceneState.Title) { hostInputField = GameObject.Find("HostInputField").GetComponent <TMP_InputField>(); portInputField = GameObject.Find("PortInputField").GetComponent <TMP_InputField>(); hostInputField.text = GetYAMLObject(@"YAML\ClientConfig.yml").GetData <string>("Host"); portInputField.text = GetYAMLObject(@"YAML\ClientConfig.yml").GetData <int>("Port").ToString(); GameObject.Find("Button").GetComponent <Button>().onClick.AddListener(ConnectClick); successImage = GameObject.Find("Button").transform.Find("Background").Find("SuccessImage").gameObject; successTimer = 0; blackScreen = GameObject.Find("BlackScreen").GetComponent <Image>(); applyPlayerSelectObj = false; playerSelectObj = null; } else if (state == SceneState.Lobby) { RectTransform iconRoot = GameObject.Find("IconRoot").GetComponent <RectTransform>(); int count = 0; Vector2 initPos = new Vector2(32f, -32f); foreach (UnitType type in Enum.GetValues(typeof(UnitType))) { if (type >= UnitType.HatsuneMiku) { int x = count % 8; int y = count / 8; GameObject instance = Instantiate(championSelectIconPrefab, iconRoot); instance.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1); instance.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1); instance.GetComponent <RectTransform>().pivot = new Vector2(0, 1); instance.GetComponent <RectTransform>().anchoredPosition = initPos + new Vector2(x * 100, y * -100); instance.GetComponent <ChampionSelectIcon>().SetData(type, this); count++; } } lobbyTitle = GameObject.Find("LobbyTitle").GetComponent <Text>(); blueContentRectTransform = GameObject.Find("BlueContent").GetComponent <RectTransform>(); redContentRectTransform = GameObject.Find("RedContent").GetComponent <RectTransform>(); selectedChampionIconImage = GameObject.Find("SelectedChampionIconImage").GetComponent <Image>(); nameInputField = GameObject.Find("NameInputField").GetComponent <InputField>(); setNameButton = GameObject.Find("SetNameButton").GetComponent <Button>(); GameObject.Find("SetNameButton").GetComponent <Button>().onClick.AddListener(SetNameButtonPressed); teamButton = GameObject.Find("TeamButton").GetComponent <Button>(); GameObject.Find("TeamButton").GetComponent <Button>().onClick.AddListener(SetTeamButtonPressed); readyButton = GameObject.Find("ReadyButton").GetComponent <Button>(); GameObject.Find("ReadyButton").GetComponent <Button>().onClick.AddListener(ReadyButtonPressed); chatUI = GameObject.Find("ChatUI").GetComponent <ChatUI>(); chatUI.SetClientNetwork(client); GameObject.Find("SendButton").GetComponent <Button>().onClick.AddListener(chatUI.Send); if (!applyPlayerSelectObj && playerSelectObj != null) { type = playerSelectObj.Type; SetUnitTypeIcon(type); _name = playerSelectObj.Name; nameInputField.text = playerSelectObj.Name; _team = playerSelectObj.Team; SetTeamButtonColor(_team); _ready = playerSelectObj.Ready; SetReadyButtonColor(_ready); applyPlayerSelectObj = true; playerSelectObj = null; } } else { unitManager = GameObject.Find("UnitManager").GetComponent <UnitManager>(); chatUI = GameObject.Find("ChatUI").GetComponent <ChatUI>(); chatUI.SetClientNetwork(client); applyPlayerSelectObj = false; playerSelectObj = null; } }