目錄
1 舊版文本輸入框 legacy InputField?
1.1 新建一個文本輸入框
1.2?InputField 的子物體構成
1.3 input field的的component
1.4 input Field的屬性
2 過渡 transition
4 占位文本 placeholder
5 文本 text
5.1 文本內容,用戶來input
5.2 內容類型 content type
5.3 line type?
5.4? 光標 caret相關
5.5 其他
6 相關觸發事件
7 代碼
7.1 UI相關代碼必須先引用? UnityEngine.UI
7.2 聲明?InputField類型的變量,然后在unity里拖動和獲取到這個控件
7.3? 然后再 inputField下面的創建新事件,并關聯到腳本的對應函數
7.4 測試代碼
8 新版TMP InputField
8.1 子物體的構成,結構有變換,功能差不多
8.2? 屬性有一些不同,大部分相同
8.3 事件不一樣
9 新版?TMP InputField 代碼差別
9.1 改變,新包?TMPro
9.2 改變,新類型TMP_InputField
9.3 其他綁定方式類似
9.4 代碼實測
1 舊版文本輸入框 legacy InputField?
1.1 新建一個文本輸入框
1.2?InputField 的子物體構成
主物體/主控件 InputField 下面包含2個文本
- 一個是place holder? //占位文本
- 一個是text? ? ? ? ? ? ?? //就是用戶輸入時的顯示文本
1.3 input field的的component
- rect transform
- canvas render
- image
- input Field
1.4 input Field的屬性
- actable 可交互性
- 如果不可交互,就無法選中了,類純看的圖片
2 過渡 transition
- 過渡 transition
- 類前面的button
3 控件導航 navigation
- 多個控件之間的導航,類前面的button
- 沒仔細看,以后再說
4 占位文本 placeholder
- 點擊 placeholder? 會跳轉到子物體placeholder?
- 然后在placeholder? 上面修改文本內容
5 文本 text
5.1 文本內容,用戶來input
- 就是用戶的文本輸入的內容
- 注意是用戶來input
- 一般這里不應該填寫內容,如果填寫了就會覆蓋 place holder
- 而且需要用戶自己刪掉,可能是提示必須填的文本格式?
- 雖然不填內容,等用戶來填寫
- 但是各種對文本的 控制,都可以提前設置
- 比如
- character limit 字符數限制
5.2 內容類型 content type
- 整數int
- 小數
- 密碼, 會自動屏蔽為***
- 字母
- 電郵
- 等等
5.3 line type?
5.4? 光標 caret相關
5.5 其他
移動時輸入會彈出一個鍵盤?
6 相關觸發事件
- on? value changed
- on submit
- on end edit
7 代碼
7.1 UI相關代碼必須先引用? UnityEngine.UI
- 開頭需要添加
- using UnityEngine.UI
7.2 聲明?InputField類型的變量,然后在unity里拖動和獲取到這個控件
- 腳本中,先聲明 public InputField inputField1;
- 因為這個腳本掛載canvas上面
- 然后拖動關聯到canvas下面的腳本的公共變量上
- 注意,需要讓unity可讀到顯示,都必須聲明為public
7.3? 然后再 inputField下面的創建新事件,并關聯到腳本的對應函數
- 然后再 inputField下面的創建新事件 on value changed
- 把腳本所在的canvas掛上去
- 從右邊找到 腳本,然后找到腳本里的新建的函數 inputTextChanged
7.4 測試代碼
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class TestUI : MonoBehaviour
{public InputField inputField1;// Start is called before the first frame updatevoid Start(){using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class TestUI : MonoBehaviour
{public InputField inputField1;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}// Update is called once per framepublic void buttonClick(){Debug.Log("buttonClick");}public void InputTextChanged(){Debug.Log("InputTextChanged");Debug.Log(inputField1.text);}}}// Update is called once per framevoid Update(){}// Update is called once per framepublic void buttonClick(){Debug.Log("buttonClick");}public void InputTextChanged(){Debug.Log("InputTextChanged");Debug.Log(inputField1.text);}}
8 新版TMP InputField
8.1 子物體的構成,結構有變換,功能差不多
8.2? 屬性有一些不同,大部分相同
8.3 事件不一樣
- on value changed
- on end edit
- on select
- on deselect
9 新版?TMP InputField 代碼差別
9.1 改變,新包?TMPro
- using TMPro;
- 因為TMP使用的包不一樣
9.2 改變,新類型TMP_InputField
- public TMP_InputField inputField2;
- 文本框的類型,完全不同