Esempio n. 1
0
        public void OnEndEdit()
        {
            Gamepad pad = Gamepad.current;

            if (!Input.GetKeyDown(KeyCode.Return) && !(pad != null && pad.startButton.wasPressedThisFrame))
            {
                return;
            }

            string command = commandInput.text;

            if (command == string.Empty)
            {
                return;
            }

            Debug.Log($"Command: {command}");

            string result = CommandList.ExecuteCommand(command);

            Debug.Log($"Result: {result}");

            string output = outputText.text;

            if (result != string.Empty)
            {
                output += $"\n{result}";
            }
            if (output.Length > maxOutputLength)
            {
                int index = output.IndexOf('\n', output.Length - maxOutputLength);
                output = output.Remove(0, index + 1);
            }
            outputText.text = output;

            if (undoLastOriginal != null)
            {
                if (undo.Count == 50)
                {
                    undo.RemoveFirst();
                }
                undo.AddLast(undoLastOriginal);
                undoLastOriginal = null;
            }

            int cnt = redo.Count - 1;

            for (int i = 0; i < cnt; i++)
            {
                if (undo.Count == 50)
                {
                    undo.RemoveFirst();
                }
                undo.AddLast(redo.Last.Value);
                redo.RemoveLast();
            }

            if (undo.Count == 50)
            {
                undo.RemoveFirst();
            }
            undo.AddLast(command);

            redo.Clear();

            commandInput.text = "";
            commandInput.ActivateInputField();
        }