public InputField fff;
// Use this for initialization
void Start () {
}
public void test()
{
fff.selectionAnchorPosition = 0;
fff.selectionFocusPosition = 100;
fff.Select ();
是这个意思吧,,,,,,,,
在网上找到了答案:http://answers.unity3d.com/quest ... -an-inputfield.html
MoveTextEnd 可以让caret移动到最后,但是必须在此帧结束的时候,或者下一帧里才可以
我试验了下,做了个InputField的封装,可以实现你要的功能:
[AppleScript]
纯文本查看
复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
|
using
UnityEngine;
using
UnityEngine.UI;
using
System.Collections;
using
UnityEngine.EventSystems;
public
class
InputFieldWrapper
:
InputField
{
public override void OnSelect
(
BaseEventData eventData
)
{
base.OnSelect
(
eventData
)
;
MoveTextEnd
(
false
)
;
}
IEnumerator MoveTextEnd_NextFrame
(
)
{
yield
return
0
;
/
/
Skip
the
first
frame
in
which this
is
called.
MoveTextEnd
(
false
)
;
/
/
Do this during
the
next frame.
}
}
|
using
UnityEngine;
using
System.Collections;
using
UnityEngine.UI;
using
UnityEngine.EventSystems;
public
class
NewBehaviourScript : MonoBehaviour, ISelectHandler
{
void
ISelectHandler.OnSelect(BaseEventData eventData)
{
StartCoroutine(MoveTextEnd());
}
IEnumerator MoveTextEnd()
{
yield
return
null
;
GetComponent<InputField>().MoveTextEnd(
false
);
}
}
|
将这个脚本挂在inputfiled上就可以了