Exemplo n.º 1
0
    void Update()
    {
        // text input
        string input         = Input.inputString.ToLower();
        bool   enteredString = false;

        foreach (char c in input)
        {
            if (lines[selectedLineIndex].Length >= charLimit)
            {
                break;
            }
            if (legalChars.Contains(c.ToString().ToLower()))
            {
                enteredString = true;
                if (caretCharIndex < lines[selectedLineIndex].Length)
                {
                    lines[selectedLineIndex] = lines[selectedLineIndex].Insert(caretCharIndex, c.ToString());
                }
                else
                {
                    lines[selectedLineIndex] += c;
                }
                caretCharIndex++;
                lastKeyTime = Time.time;
            }
        }

        if (enteredString)
        {
            AudioM.PlayKeyPress(false);
        }

        HandleControlInput();

        UpdateDisplay();
    }
Exemplo n.º 2
0
    void HandleControlInput()
    {
        bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

        // New line
        if (Input.GetKeyDown(KeyCode.Return))
        {
            AudioM.PlayKeyPress(true);
            bool specialCommandEntered = OnTextEntered(selectedLineIndex);
            if (specialCommandEntered)
            {
                caretCharIndex = lines[selectedLineIndex].Length;
            }
            else
            {
                lastKeyTime = Time.time;
                if (lines.Count < maxNumLinesOnScreen)
                {
                    if (selectedLineIndex < lines.Count - 1)
                    {
                        lines.Insert(selectedLineIndex + 1, "");
                    }
                    else
                    {
                        lines.Add("");
                    }
                    selectedLineIndex++;
                    caretCharIndex = 0;
                }
                else
                {
                    selectedLineIndex++;
                    selectedLineIndex = Mathf.Clamp(selectedLineIndex, 0, maxNumLinesOnScreen - 1);
                    caretCharIndex    = lines [selectedLineIndex].Length;
                }
            }
        }

        // Backspace
        if (CustomInput.instance.GetKeyPress(KeyCode.Backspace))
        {
            lastKeyTime = Time.time;
            if (lines[selectedLineIndex].Length == 0)
            {
                if (lines.Count != 1)
                {
                    lines.RemoveAt(selectedLineIndex);
                    if (selectedLineIndex > 0)
                    {
                        selectedLineIndex--;
                        caretCharIndex = lines[selectedLineIndex].Length;
                        AudioM.PlayKeyPress(false);
                    }
                }
            }
            else
            {
                if (caretCharIndex > 0)
                {
                    AudioM.PlayKeyPress(false);
                    caretCharIndex--;
                    lines[selectedLineIndex] = lines[selectedLineIndex].Remove(caretCharIndex, 1);
                }
            }
        }

        int lineIndexOld = selectedLineIndex;
        int charIndOld   = caretCharIndex;

        // Arrow keys
        if (CustomInput.instance.GetKeyPress(KeyCode.UpArrow))
        {
            lastKeyTime = Time.time;
            if (shift)
            {
                selectedLineIndex = 0;
            }
            else
            {
                selectedLineIndex = Mathf.Clamp(selectedLineIndex - 1, 0, int.MaxValue);
            }
            caretCharIndex = lines[selectedLineIndex].Length;
        }
        if (CustomInput.instance.GetKeyPress(KeyCode.DownArrow))
        {
            lastKeyTime = Time.time;
            if (shift && lines.Count > 0)
            {
                selectedLineIndex = lines.Count - 1;
            }
            else
            {
                selectedLineIndex = Mathf.Clamp(selectedLineIndex + 1, 0, lines.Count - 1);
            }

            caretCharIndex = lines[selectedLineIndex].Length;
        }


        if (CustomInput.instance.GetKeyPress(KeyCode.LeftArrow))
        {
            lastKeyTime = Time.time;
            if (shift)
            {
                caretCharIndex = 0;
            }
            else
            {
                caretCharIndex = Mathf.Clamp(caretCharIndex - 1, 0, int.MaxValue);
            }
        }
        if (CustomInput.instance.GetKeyPress(KeyCode.RightArrow))
        {
            lastKeyTime = Time.time;
            if (shift)
            {
                caretCharIndex = lines[selectedLineIndex].Length;
            }
            else
            {
                caretCharIndex = Mathf.Clamp(caretCharIndex + 1, 0, Mathf.Max(0, lines[selectedLineIndex].Length));
            }
        }

        if (selectedLineIndex != lineIndexOld || caretCharIndex != charIndOld)
        {
            AudioM.PlayKeyPress(false);
        }
    }
Exemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     instance = this;
     a        = GetComponent <AudioSource> ();
 }