Monday, October 17, 2022
HomeGame Developmentunity - Caret not seen with TMP_InputField created from script

unity – Caret not seen with TMP_InputField created from script


I am modding an Unity sport. I haven’t got entry to its supply, to any Unity editor or property. All I’ve is BepInEx and a few C# scripting, plus no matter Visible Studio can decompile from dlls.

I create an TMP_InputField when the person presses Enter as follows:

var canvas = new GameObject("CommandConsoleCanvas");
var c = canvas.AddComponent<Canvas>();
c.renderMode = RenderMode.ScreenSpaceOverlay;

var inputField = new GameObject("CommandConsoleInput");
inputField.remodel.father or mother = canvas.remodel;

var inputFieldText = inputField.AddComponent<TMP_InputField>();
var txt = inputField.AddComponent<TextMeshProUGUI>();
inputFieldText.textComponent = txt;

inputFieldText.fontAsset = fontAsset;
inputFieldText.pointSize = 20;
inputFieldText.textual content = "instance...";
inputFieldText.enabled = true;
inputFieldText.caretColor = Colour.white;
inputFieldText.caretWidth = 4;
inputFieldText.selectionColor = Colour.white;
inputFieldText.onFocusSelectAll = false;

var rect = inputField.GetComponent<RectTransform>();
rect.localPosition = new Vector3(0, 0, 0);
rect.sizeDelta = new Vector2(400, 25);

inputFieldText.Choose();
inputFieldText.ActivateInputField();

This type of works. I can see the textual content and sort in. Nonetheless, there is not any caret and no indication of the present choice.

How can I make the caret and present choice render?

There have to be some settings or parts I am lacking however cannot determine it out by way of Googling and looking out on the API.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments