yasirkula / UnityIngameDebugConsole

A uGUI based console to see debug messages and execute commands during gameplay in Unity
MIT License
2.11k stars 221 forks source link

Using TextMeshPro #19

Closed StarKen0617 closed 4 years ago

StarKen0617 commented 4 years ago

How could I use textmeshpro in the input field?

Try replacing this private InputField commandInputField; to this private TMP_InputField commandInputField;

But it doesn't work when I try to use some command i Use "using TMPro;" and I also put the "TMP_inputfield" in the hierarchy

yasirkula commented 4 years ago

If there are compilation errors, please post them here. In any case, you'll have to edit the IngameDebugConsole prefab and replace that input field with TextMesh Pro's input field. Then, fix any missing references in the prefab's Inspector.

StarKen0617 commented 4 years ago

There are no compilation errors, I have also changed the prefab, when I write something in the TMP_inputfield and I give it in, nothing happens

yasirkula commented 4 years ago

I'm assuming that there are no runtime errors in the console either. DebugLogManager.OnValidateInput's else if( addedChar == '\n' ) condition is responsible from submitting the command. You should add a Debug.Log there to see if it is getting called. If not, check the value of addedChar with another Debug.Log to see which key is submitted when Enter key is pressed, e.g. Debug.Log(((int) addedChar) + " " + addedChar);.

StarKen0617 commented 4 years ago

Add a Debug.log to the condition else if (addedChar == '\ n') but absolutely nothing happened and also add text to the condition if (clearCommandAfterExecution) and the text did not change either...

Pd: There are no errors in the console nor any errors of execution.

yasirkula commented 4 years ago

You can make the following additions to DebugLogManager.cs:

public TMP_InputField commandInputField;
private bool moveInputFieldCaretToEnd;

private void OnEnable()
{
    commandInputField.onSubmit.AddListener( OnSubmitCommand );
}

private void OnDisable()
{
    commandInputField.onSubmit.RemoveListener( OnSubmitCommand );
}

private void OnSubmitCommand( string text )
{
    // Clear the command field
    if( clearCommandAfterExecution )
        commandInputField.text = "";

    if( text.Length > 0 )
    {
        if( commandHistory.Count == 0 || commandHistory[commandHistory.Count - 1] != text )
            commandHistory.Add( text );

        commandHistoryIndex = -1;

        // Execute the command
        DebugLogConsole.ExecuteCommand( text );

        // Snap to bottom and select the latest entry
        SetSnapToBottom( true );
    }

    commandInputField.ActivateInputField();
    moveInputFieldCaretToEnd = true;
}

private void LateUpdate()
{
    if( moveInputFieldCaretToEnd )
    {
        commandInputField.MoveTextEnd( true );
        moveInputFieldCaretToEnd = false;
    }
}
StarKen0617 commented 4 years ago

Thank you very much, you are the best!