Example #1
0
 private bool verifyEndInput()
 {
     return(EndInput.ToLower() == endRef);
 }
Example #2
0
    private IEnumerator Handler()
    {
        SetColor(Color.green);
        StartInput?.Invoke(this);
        ShowQuad();

        while (Input.GetMouseButton(0) || Input.GetMouseButton(1))
        {
            yield return(null);
        }

        string input = label.text;
        int    count = input.Length;
        bool   done  = false;

        while (!done)
        {
            string current = Input.inputString;

            if (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
            {
                done = true;
            }
            else if (count > 0 && Input.GetKeyDown(KeyCode.Backspace))
            {
                string changed = input.Remove((count--) - 1, 1);
                input = changed.Trim();
            }
            else if (!string.IsNullOrEmpty(current))
            {
                int    parsedInt = -1;
                char[] chars     = current.ToCharArray();

                bool isPunctuation = false;

                for (int i = 0; chars.Length > i && !isPunctuation; i++)
                {
                    if (chars[i] == '.')
                    {
                        isPunctuation = true;
                    }
                }

                bool isNumber = int.TryParse(current, out parsedInt);
                bool valid    = _contentMode == ContentMode.TextAndNumbers || (_contentMode == ContentMode.Text && !isNumber) || (_contentMode == ContentMode.Numbers && (isNumber || isPunctuation));

                if (valid)
                {
                    input  = input + current;
                    count += current.Length;
                }
            }

            label.SetText(input);
            yield return(null);
        }

        SetColor(Color.white);
        EndInput?.Invoke(this);
        _handler = null;
        HideQuad();
    }