TextMeshPro

4/3/2024 Unity3d

TextMeshPro:

TextMeshProUGUI、TMP_InputField

code

---------------------------------------------------------------------
-- MakerSpaceV5 (C) CompanyName, All Rights Reserved
-- Created by: zcg
-- Date: 2023-01-11 10:39:14
---------------------------------------------------------------------
TMPro = CS.TMPro
local inputTxt
function Start()
    --text
    local txtTf=  transform:Find("txtContent")
    local txt = txtTf:GetComponent(typeof(TMPro.TextMeshProUGUI)) -- txtTf:GetComponent(typeof(CS.TMPro.TextMeshProUGUI))   
    txt.text ="123456"  --or -- txt:SetText("123456")    
    
    --InputField
    local txtTf=  transform:Find("InputField (TMP)")
    inputTxt = txtTf:GetComponent(typeof(TMPro.TMP_InputField)) 
    inputTxt.text = "hello"
    --InputField event
    inputTxt.onValueChanged:AddListener(OnChanged)
    inputTxt.onEndEdit:AddListener(OnEndEdit)
    
     --InputField placeholder
    local placeholder= inputTxt.placeholder:GetComponent(typeof(TMPro.TextMeshProUGUI))
    placeholder:SetText("test TMP_InputField")
end

function OnChanged(arg0)
    print('OnChanged',arg0)
end

function OnEndEdit(arg0)
    print('OnEndEdit',arg0)
end

function OnDestroy()
    inputTxt.onValueChanged:RemoveListener(OnChanged);
    inputTxt.onEndEdit:RemoveListener(OnEndEdit);
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

Last Updated: Thu, 11 Apr 2024 06:54:22 GMT