Exemplo n.º 1
0
    void Update()
    {
        // show while in lobby and while not creating a character
        if (manager.state == NetworkState.Lobby && !uiCharacterCreation.IsVisible())
        {
            panel.SetActive(true);

            // characters available message received already?
            if (manager.charactersAvailableMsg != null)
            {
                CharactersAvailableMsg.CharacterPreview[] characters = manager.charactersAvailableMsg.characters;

                // start button: calls AddPLayer which calls OnServerAddPlayer
                // -> button sends a request to the server
                // -> if we press button again while request hasn't finished
                //    then we will get the error:
                //    'ClientScene::AddPlayer: playerControllerId of 0 already in use.'
                //    which will happen sometimes at low-fps or high-latency
                // -> internally ClientScene.AddPlayer adds to localPlayers
                //    immediately, so let's check that first
                startButton.gameObject.SetActive(manager.selection != -1);
                startButton.onClick.SetListener(() => {
                    // add player
                    CharacterSelectMsg message = new CharacterSelectMsg {
                        index = manager.selection
                    };
                    ClientScene.AddPlayer(manager.client.connection, message);

                    // clear character selection previews
                    manager.ClearPreviews();

                    // make sure we can't select twice and call AddPlayer twice
                    panel.SetActive(false);
                });

                // delete button
                deleteButton.gameObject.SetActive(manager.selection != -1);
                deleteButton.onClick.SetListener(() => {
                    CharacterDeleteMsg message = new CharacterDeleteMsg {
                        index = manager.selection
                    };
                    manager.client.Send(CharacterDeleteMsg.MsgId, message);
                });

                // create button
                createButton.interactable = characters.Length < manager.characterLimit;
                createButton.onClick.SetListener(() => {
                    panel.SetActive(false);
                    uiCharacterCreation.Show();
                });

                // quit button
                quitButton.onClick.SetListener(() => { NetworkManagerMMO.Quit(); });
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Exemplo n.º 2
0
    void OnServerCharacterDelete(NetworkConnection conn, CharacterDeleteMsg message)
    {
        //print("OnServerCharacterDelete " + conn);

        // only while in lobby (aka after handshake and not ingame)
        if (lobby.ContainsKey(conn))
        {
            string        account    = lobby[conn];
            List <string> characters = Database.singleton.CharactersForAccount(account);

            // validate index
            if (0 <= message.value && message.value < characters.Count)
            {
                // delete the character
                print("delete character: " + characters[message.value]);
                Database.singleton.CharacterDelete(characters[message.value]);

                // addon system hooks
                Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnServerCharacterDelete_", message);

                // send the new character list to client
                conn.Send(MakeCharactersAvailableMessage(account));
            }
            else
            {
                print("invalid character index: " + account + " " + message.value);
                ServerSendError(conn, "invalid character index", false);
            }
        }
        else
        {
            print("CharacterDelete: not in lobby: " + conn);
            ServerSendError(conn, "CharacterDelete: not in lobby", true);
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        // only update if visible
        if (!panel.activeSelf)
        {
            return;
        }

        // hide if disconnected or if a local player is in the game world
        if (!NetworkClient.active || Utils.ClientLocalPlayer() != null)
        {
            Hide();
        }

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(slotPrefab.gameObject, characters.characterNames.Length, content);

        // refresh all
        var prefabs = manager.GetPlayerClasses();

        for (int i = 0; i < characters.characterNames.Length; ++i)
        {
            var prefab = prefabs.Find(p => p.name == characters.characterClasses[i]);
            var slot   = content.GetChild(i).GetComponent <UICharacterSelectionSlot>();

            // name and icon
            slot.nameText.text = characters.characterNames[i];
            slot.image.sprite  = prefab.GetComponent <Player>().classIcon;

            // select button: calls AddPLayer which calls OnServerAddPlayer
            int icopy = i; // needed for lambdas, otherwise i is Count
            slot.selectButton.onClick.SetListener(() => {
                var message = new CharacterSelectMsg {
                    index = icopy
                };
                ClientScene.AddPlayer(manager.client.connection, 0, message);
            });

            // delete button: sends delete message
            slot.deleteButton.onClick.SetListener(() => {
                var message = new CharacterDeleteMsg {
                    index = icopy
                };
                manager.client.Send(CharacterDeleteMsg.MsgId, message);
            });
        }

        createButton.interactable = characters.characterNames.Length < manager.characterLimit;
        createButton.onClick.SetListener(() => {
            Hide();
            FindObjectOfType <UICharacterCreation>().Show();
        });

        quitButton.onClick.SetListener(() => { Application.Quit(); });

        // addon system hooks
        Utils.InvokeMany(typeof(UICharacterSelection), this, "Update_");
    }
Exemplo n.º 4
0
    void Update()
    {
        // only update if visible
        if (!panel.activeSelf)
        {
            return;
        }

        // hide if disconnected or if a local player is in the game world
        if (!NetworkClient.active || Utils.ClientLocalPlayer() != null)
        {
            Hide();
        }

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(slotPrefab, characters.characterNames.Length, content);

        // refresh all
        var prefabs = ((NetworkManagerMMO)NetworkManager.singleton).GetPlayerClasses();

        for (int i = 0; i < characters.characterNames.Length; ++i)
        {
            var prefab = prefabs.Find(p => p.name == characters.characterClasses[i]);
            var entry  = content.GetChild(i);

            var txt = entry.GetChild(0).GetComponent <Text>();
            txt.text = characters.characterNames[i];

            var imgClass = entry.GetChild(1).GetComponent <Image>();
            imgClass.sprite = prefab.GetComponent <Player>().classIcon;

            var buttonSelect = entry.GetChild(2).GetComponent <Button>();
            int icopy        = i; // needed for lambdas, otherwise i is Count
            buttonSelect.onClick.SetListener(() => {
                // use ClientScene.AddPlayer with a parameter, which calls
                // OnServerAddPlayer on the server.
                var msg = new CharacterSelectMsg {
                    index = icopy
                };
                ClientScene.AddPlayer(manager.client.connection, 0, msg);
            });

            var buttonDelete = entry.GetChild(3).GetComponent <Button>();
            buttonDelete.onClick.SetListener(() => {
                // send delete message
                var msg = new CharacterDeleteMsg {
                    index = icopy
                };
                manager.client.Send(CharacterDeleteMsg.MsgId, msg);
            });
        }
        createButton.interactable = characters.characterNames.Length < manager.charLimit;
    }
Exemplo n.º 5
0
    void OnServerCharacterDelete(NetworkMessage netMsg)
    {
        print("OnServerCharacterDelete " + netMsg.conn);
        CharacterDeleteMsg message = netMsg.ReadMessage <CharacterDeleteMsg>();

        // only while in lobby (aka after handshake and not ingame)
        if (lobby.ContainsKey(netMsg.conn))
        {
            string        account    = lobby[netMsg.conn];
            List <string> characters = Database.CharactersForAccount(account);

            // validate index
            if (0 <= message.index && message.index < characters.Count)
            {
                // delete the character
                print("delete character: " + characters[message.index]);
                Database.CharacterDelete(characters[message.index]);

                // addon system hooks
                Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnServerCharacterDelete_", message);

                // send the new character list to client
                characters = Database.CharactersForAccount(account);
                CharactersAvailableMsg reply = MakeCharactersAvailableMessage(account);
                netMsg.conn.Send(CharactersAvailableMsg.MsgId, reply);
            }
            else
            {
                print("invalid character index: " + account + " " + message.index);
                ClientSendPopup(netMsg.conn, "invalid character index", false);
            }
        }
        else
        {
            print("CharacterDelete: not in lobby: " + netMsg.conn);
            ClientSendPopup(netMsg.conn, "CharacterDelete: not in lobby", true);
        }
    }
 void OnServerCharacterDelete(NetworkConnection conn, CharacterDeleteMsg message)
 {
     if (lobby.ContainsKey(conn))
     {
         string        account    = lobby[conn];
         List <string> characters = Database.singleton.CharactersForAccount(account);
         if (0 <= message.value && message.value < characters.Count)
         {
             print("delete character: " + characters[message.value]);
             Database.singleton.CharacterDelete(characters[message.value]);
             conn.Send(MakeCharactersAvailableMessage(account));
         }
         else
         {
             print("invalid character index: " + account + " " + message.value);
             ServerSendError(conn, "invalid character index", false);
         }
     }
     else
     {
         print("CharacterDelete: not in lobby: " + conn);
         ServerSendError(conn, "CharacterDelete: not in lobby", true);
     }
 }
Exemplo n.º 7
0
 void OnServerCharacterDelete_Example(CharacterDeleteMsg message)
 {
 }
    void Update()
    {
        // show while in lobby and while not creating a character
        if (manager.state == NetworkState.Lobby && !uiCharacterCreation.IsVisible())
        {
            panel.SetActive(true);

            // characters available message received already?
            if (manager.charactersAvailableMsg != null)
            {
                // instantiate/destroy enough slots
                CharactersAvailableMsg.CharacterPreview[] characters = manager.charactersAvailableMsg.characters;
                UIUtils.BalancePrefabs(slotPrefab.gameObject, characters.Length, content);

                // refresh all
                List <Player> prefabs = manager.GetPlayerClasses();
                for (int i = 0; i < characters.Length; ++i)
                {
                    Player prefab = prefabs.Find(p => p.name == characters[i].className);
                    UICharacterSelectionSlot slot = content.GetChild(i).GetComponent <UICharacterSelectionSlot>();

                    // name and icon
                    slot.nameText.text = characters[i].name;
                    slot.image.sprite  = prefab.GetComponent <Player>().classIcon;

                    // select button: calls AddPLayer which calls OnServerAddPlayer
                    // -> button sends a request to the server
                    // -> if we press button again while request hasn't finished
                    //    then we will get the error:
                    //    'ClientScene::AddPlayer: playerControllerId of 0 already in use.'
                    //    which will happen sometimes at low-fps or high-latency
                    // -> internally ClientScene.AddPlayer adds to localPlayers
                    //    immediately, so let's check that first
                    slot.selectButton.interactable = ClientScene.localPlayer == null;
                    int icopy = i; // needed for lambdas, otherwise i is Count
                    slot.selectButton.onClick.SetListener(() => {
                        CharacterSelectMsg message = new CharacterSelectMsg {
                            index = icopy
                        };
                        ClientScene.AddPlayer(manager.client.connection, message);

                        // make sure we can't select twice and call AddPlayer twice
                        panel.SetActive(false);
                    });

                    // delete button: sends delete message
                    slot.deleteButton.onClick.SetListener(() => {
                        CharacterDeleteMsg message = new CharacterDeleteMsg {
                            index = icopy
                        };
                        manager.client.Send(CharacterDeleteMsg.MsgId, message);
                    });
                }

                createButton.interactable = characters.Length < manager.characterLimit;
                createButton.onClick.SetListener(() => {
                    panel.SetActive(false);
                    uiCharacterCreation.Show();
                });

                quitButton.onClick.SetListener(() => { NetworkManagerMMO.Quit(); });
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Exemplo n.º 9
0
    void Update()
    {
        // show if connected, not in world, not in charcreation
        if (manager.IsClientConnected() && !Utils.ClientLocalPlayer() && !uiCharacterCreation.IsVisible())
        {
            panel.SetActive(true);

            // characters available message received already?
            if (manager.charactersAvailableMsg != null)
            {
                // instantiate/destroy enough slots
                CharactersAvailableMsg.CharacterPreview[] characters = manager.charactersAvailableMsg.characters;
                UIUtils.BalancePrefabs(slotPrefab.gameObject, characters.Length, content);

                // refresh all
                List <Player> prefabs = manager.GetPlayerClasses();
                for (int i = 0; i < characters.Length; ++i)
                {
                    Player prefab = prefabs.Find(p => p.name == characters[i].className);
                    UICharacterSelectionSlot slot = content.GetChild(i).GetComponent <UICharacterSelectionSlot>();

                    // name and icon
                    slot.nameText.text = characters[i].name;
                    slot.image.sprite  = prefab.GetComponent <Player>().classIcon;

                    // select button: calls AddPLayer which calls OnServerAddPlayer
                    int icopy = i; // needed for lambdas, otherwise i is Count
                    slot.selectButton.onClick.SetListener(() => {
                        CharacterSelectMsg message = new CharacterSelectMsg {
                            index = icopy
                        };
                        ClientScene.AddPlayer(manager.client.connection, 0, message);

                        // make sure we can't select twice and call AddPlayer twice
                        panel.SetActive(false);
                    });

                    // delete button: sends delete message
                    slot.deleteButton.onClick.SetListener(() => {
                        CharacterDeleteMsg message = new CharacterDeleteMsg {
                            index = icopy
                        };
                        manager.client.Send(CharacterDeleteMsg.MsgId, message);
                    });
                }

                createButton.interactable = characters.Length < manager.characterLimit;
                createButton.onClick.SetListener(() => {
                    panel.SetActive(false);
                    uiCharacterCreation.Show();
                });

                quitButton.onClick.SetListener(() => { NetworkManagerMMO.Quit(); });
            }

            // addon system hooks
            Utils.InvokeMany(typeof(UICharacterSelection), this, "Update_");
        }
        else
        {
            panel.SetActive(false);
        }
    }
Exemplo n.º 10
0
    // CHARACTER SELECTION /////////////////////////////////////////////////////
    void UpdateCharacterSelection()
    {
        // only update if visible
        if (!characterSelectionPanel.activeSelf)
        {
            return;
        }

        // hide if disconnected
        if (!NetworkClient.active)
        {
            HideCharacterSelection();
        }

        // disable character selection as soon as a player is in the world
        if (IsLocalPlayerInWorld())
        {
            HideCharacterSelection();
        }

        // update UI
        for (int i = 0; i < characterSelectionContent.childCount; ++i)
        {
            var entry = characterSelectionContent.GetChild(i);

            // get the character
            if (i < characters.Length)
            {
                entry.gameObject.SetActive(true);

                var txt = entry.GetChild(0).GetComponent <Text>();
                txt.text = characters[i];

                var btnSelect = entry.GetChild(1).GetComponent <Button>();
                btnSelect.interactable = characters.Length < manager.charLimit;
                int icopy = i; // needed for lambdas, otherwise i is Count
                btnSelect.onClick.SetListener(() => {
                    // use ClientScene.AddPlayer with a parameter, which calls
                    // OnServerAddPlayer on the server.
                    var msg   = new CharacterSelectMsg();
                    msg.index = icopy;
                    ClientScene.AddPlayer(manager.client.connection, 0, msg);
                });

                var btnDelete = entry.GetChild(2).GetComponent <Button>();
                btnDelete.onClick.SetListener(() => {
                    // send delete message
                    var msg   = new CharacterDeleteMsg();
                    msg.index = icopy;
                    manager.client.Send(CharacterDeleteMsg.MsgId, msg);
                });
            }
            else
            {
                entry.gameObject.SetActive(false);
            }
        }
        if (characters.Length > characterSelectionContent.childCount)
        {
            Debug.LogWarning("not enough UI slots for character selection");
        }
    }