I'm modding an Unity game. I don't have access to its source, to any Unity editor or assets. All I have is BepInEx and some C# scripting, plus whatever Visual Studio can decompile from dlls.
I create an TMP_InputField when the user presses Enter as follows:
var canvas = new GameObject("CommandConsoleCanvas");
var c = canvas.AddComponent<Canvas>();
c.renderMode = RenderMode.ScreenSpaceOverlay;
var inputField = new GameObject("CommandConsoleInput");
inputField.transform.parent = canvas.transform;
var inputFieldText = inputField.AddComponent<TMP_InputField>();
var txt = inputField.AddComponent<TextMeshProUGUI>();
inputFieldText.textComponent = txt;
inputFieldText.fontAsset = fontAsset;
inputFieldText.pointSize = 20;
inputFieldText.text = "example...";
inputFieldText.enabled = true;
inputFieldText.caretColor = Color.white;
inputFieldText.caretWidth = 4;
inputFieldText.selectionColor = Color.white;
inputFieldText.onFocusSelectAll = false;
var rect = inputField.GetComponent<RectTransform>();
rect.localPosition = new Vector3(0, 0, 0);
rect.sizeDelta = new Vector2(400, 25);
inputFieldText.Select();
inputFieldText.ActivateInputField();
This sort of works. I can see the text and type in. However, there is no caret and no indication of the current selection.
How can I make the caret and current selection render?
There must be some settings or components I'm missing but can't figure it out via Googling and looking at the API.