Пример #1
0
    void ClickedJoinGame()
    {
        //This gets the latest values on the screen
        //Our JoinGameScreen cVE defaults these values but player name can be updated
        //We set these VisualElement variables OnClick instead of OnEnable because this way
        //we don't need to make a variable for player name for every view, just 1 and set which view
        //we get it from OnClick (which is when we need it)
        m_GameIpLabel = m_JoinGameScreen.Q <Label>("game-ip");
        m_PlayerName  = m_JoinGameScreen.Q <TextField>("player-name");

        //Now we grab the values from the VisualElements
        var gameIp     = m_GameIpLabel.text;
        var playerName = m_PlayerName.value;

        //When we click "Join Game" that means we want to be only a client
        ClientLauncher(playerName, gameIp);

        //This function will trigger the MainScene
        StartGameScene();
    }
Пример #2
0
    void OnEnable()
    {
        //Here we set our variables for our different views so we can then add call backs to their buttons
        m_titleScreenManagerVE = m_TitleUIDocument.rootVisualElement;
        m_HostGameScreen       = m_titleScreenManagerVE.Q <HostGameScreen>("HostGameScreen");
        m_JoinGameScreen       = m_titleScreenManagerVE.Q <JoinGameScreen>("JoinGameScreen");
        m_ManualConnectScreen  = m_titleScreenManagerVE.Q <ManualConnectScreen>("ManualConnectScreen");

        //Host Game Screen callback
        m_HostGameScreen.Q("launch-host-game")?.RegisterCallback <ClickEvent>(ev => ClickedHostGame());
        //Join Game Screen callback
        m_JoinGameScreen.Q("launch-join-game")?.RegisterCallback <ClickEvent>(ev => ClickedJoinGame());
        //Manual Connect Screen callback
        m_ManualConnectScreen.Q("launch-connect-game")?.RegisterCallback <ClickEvent>(ev => ClickedConnectGame());
    }