Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        ClientNetEvents.UpdatePlayerList.AddListener(PlayerListUpdated);
        ClientNetEvents.ChatMessageReceived.AddListener(WriteChatMessage);
        ClientNetEvents.UpdateHostBox.AddListener(UpdateHostBox);
        ClientNetEvents.UpdateActiveRoleList.AddListener(UpdateActiveRoleList);
        ClientNetEvents.FlipGameScene.AddListener(Switching);

        ChatBoxInputField.onSubmit.AddListener(SendChatMessage);

        if (NetworkingGlobal.FirstLobby)
        {
            NetworkingGlobal.FirstLobby = false;

            if (!(NetworkingGlobal.ServerInstance != null ?
                  NetworkingGlobal.InitializeClientInstance(IPAddress.Loopback, 7235) :
                  NetworkingGlobal.InitializeClientInstance(NetworkingGlobal.ClientConnectIP, NetworkingGlobal.ClientConnectPort)))
            {
                InvokerObj.Instance.ShowError("The client failed to connect to the server. Please make sure you're using the correct IP address and port and that your setup isn't busted, then try again.");
            }
        }
        else
        {
            foreach (NetWerewolfPlayer p in NetworkingGlobal.ConnectedPlayers)
            {
                PlayerListUpdated(p.PlayerID, false);
            }
        }

        foreach (string rHash in NetworkingGlobal.LoadedRoleHashes)
        {
            LobbyHostRoleHelper h = Instantiate(HostRoleItemPrefab, LoadedRolesListContent);
            h.SetupTextAndEvent(rHash, false);
        }

        ChatTextField.autoSizeTextContainer = true;

        UpdateHostBox(NetworkingGlobal.LocalPlayer.IsHost);
    }
Example #2
0
    private void UpdateActiveRoleList(string roleHash, bool remove)
    {
        // TODO: non-host role list

        if (remove)
        {
            int activeIndex = hostRolePanels.FindIndex(x => x.RoleHash == roleHash);

            if (activeIndex == -1)
            {
                return;
            }

            InvokerObj.Invoke(() =>
            {
                Destroy(hostRolePanels[activeIndex].gameObject);
                hostRolePanels.RemoveAt(activeIndex);

                Destroy(clientRolePanels[activeIndex].gameObject);
                clientRolePanels.RemoveAt(activeIndex);
            });
        }
        else
        {
            InvokerObj.Invoke(() =>
            {
                LobbyHostRoleHelper rp = Instantiate(HostRoleItemPrefab, HostRolesListContent);
                rp.SetupTextAndEvent(roleHash, true);
                hostRolePanels.Add(rp);

                LobbyHostRoleHelper rpc = Instantiate(ClientRoleItemPrefab, ClientRolesListContent);
                rpc.SetupTextAndEvent(roleHash, false);
                clientRolePanels.Add(rpc);
            });
        }
    }