예제 #1
0
    //DW
    //
    void Start()
    {
        MultiplayerManager mm = MultiplayerManager.GetInstance();

        Cursor.lockState = CursorLockMode.None;
        Cursor.visible   = true;

        if (SaveLoad.Load())
        {
            mm.localPlayerName = Game.current.name;
            mm.networkAddress  = Game.current.IPaddress;
        }
        if (mm != null)
        {
            HostNameField.text = mm.localPlayerName;
            JoinNameField.text = mm.localPlayerName;
            IPField.text       = mm.networkAddress;
        }
        //just in case input is locked
        InputWrapper.ReleaseKeyboard();
        InputWrapper.ReleaseMouse();
    }
예제 #2
0
    private void Update()
    {
        //if the player presses down the button to access the chat
        if (Input.GetButtonDown(messageSendKey)) //Special permissions - bypass InputWrapper
        {
            //if already typing, player is trying to send a message
            //or close the window if their text is empty
            if (inputField.IsActive())
            {
                //make sure the player has entered a message that isn't just whitespace
                if (playerCurrentChatValue.Length > 0 && Regex.Replace(playerCurrentChatValue, @"\s+", "").Length > 0)
                {
                    ChatMessage newMessage = new ChatMessage();
                    newMessage.message    = playerCurrentChatValue;
                    newMessage.playerName = mpManager.localPlayerName;
                    newMessage.hour       = System.DateTime.Now.Hour;
                    newMessage.minute     = System.DateTime.Now.Minute;

                    //tell the handler to send the message to the other clients
                    chatHandler.SendOutMessage(newMessage);

                    inputField.text        = String.Empty;
                    playerCurrentChatValue = String.Empty;
                }
                //deactivate the chat entry area
                inputField.DeactivateInputField();
                chatEnterField.SetActive(false);
                InputWrapper.ReleaseKeyboard();
            }
            //if not typing already
            //open the chat entry area so they can begin typing
            else
            {
                chatEnterField.SetActive(true);
                inputField.Select();
                inputField.ActivateInputField();
                InputWrapper.CaptureKeyboard();
            }
        }
        else if (Input.GetKeyDown(KeyCode.Escape)) //allow canceling message with escape
        {
            //deactivate the chat entry area
            inputField.DeactivateInputField();
            chatEnterField.SetActive(false);
            InputWrapper.ReleaseKeyboard();
        }

        //update the UI with whatever chat messages are currently in the array
        //System.Object[] array = chatQueue.ToArray();
        //Array.Reverse(array);
        //for (int i = 0; i < textSlots.Length; i++)
        //{
        //    if (i < chatQueue.Count)
        //    {
        //        textSlots[i].text = ChatHandler.ChatMessageToString(((ChatMessage)array[i]));
        //    }
        //    else
        //    {
        //        textSlots[i].text = String.Empty;
        //    }
        //}
    }