コード例 #1
0
    /// <summary>
    /// Handles the messages recieves from the client, and converts theses to unity inputs
    /// </summary>
    /// <param name="msg"></param>
    private void ConvertToInput(string [] msg)
    {
        for (int i = 0; i < msg.Length; i++)
        {
            string  input = msg [i];
            KeyCode inputButton;
            bool    pressed = true;

            if (input.Contains("-"))
            {
                pressed = false;
                input   = input.Remove(0, 1);
            }

            if (Enum.TryParse <KeyCode>(input, out inputButton))
            {
                if (pressed)
                {
                    ActiveInputs.Add(inputButton);
                }
                else
                {
                    ActiveInputs.Remove(inputButton);
                }
                OnNewInputsRecieved.Invoke(ActiveInputs);
            }
        }
    }
コード例 #2
0
    void HandleInputMessage(string msg)
    {
        Vector2 moveDir = Vector2.zero;

        string [] msgSplit = msg.Split(':');

        for (int i = 0; i < msgSplit.Length; i++)
        {
            string  input = msgSplit [i];
            KeyCode inputButton;
            bool    pressed = true;

            if (input.Contains("-"))
            {
                pressed = false;
                input   = input.Remove(0, 1);
            }

            if (Enum.TryParse <KeyCode>(input, out inputButton))
            {
                if (pressed)
                {
                    ActiveInputs.Add(inputButton);
                }
                else
                {
                    ActiveInputs.Remove(inputButton);
                }
                OnNewInputsRecieved.Invoke(ActiveInputs);
            }
        }
    }