如何让Unity3D支持中文输入输出
1个回答
2015-12-06 · 知道合伙人软件行家
关注
展开全部
其实很简单只需要GUI使用中文字体就行了,不好意思忙了一周白忙了心里郁闷中
代码如下自己测试(字体到win下字体中找小于9m的中文字体即可);
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
public GUISkin gskin;
private string inputStr="";
private Vector2 scrollPosition;
private string result=""; //结果
void Start () {
inputStr="直接输入中文";
}
// update is called once per frame
void update () {
}
void OnGUI()
{
GUI.skin=gskin;
inputStr=GUI.TextField(new Rect(200, 154, 200, 30), inputStr, 25);
GUI.Box(new Rect(200,50,200,100),"");
GUILayout.BeginArea(new Rect(200,50,200,100));
scrollPosition = GUILayout.BeginScrollView (scrollPosition);
string[] list=result.Split('*');
foreach (string entry in list)
{
GUILayout.BeginHorizontal();
GUILayout.Label(entry);
GUILayout.FlexibleSpace ();
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView ();
GUILayout.EndArea();
if(Event.current.type == EventType.keyDown && Event.current.character == '
& #39; && inputStr.Length > 0)
{
result+=inputStr+"*";
inputStr = "";
scrollPosition.y = 1000000;
}
}
}
代码如下自己测试(字体到win下字体中找小于9m的中文字体即可);
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
public GUISkin gskin;
private string inputStr="";
private Vector2 scrollPosition;
private string result=""; //结果
void Start () {
inputStr="直接输入中文";
}
// update is called once per frame
void update () {
}
void OnGUI()
{
GUI.skin=gskin;
inputStr=GUI.TextField(new Rect(200, 154, 200, 30), inputStr, 25);
GUI.Box(new Rect(200,50,200,100),"");
GUILayout.BeginArea(new Rect(200,50,200,100));
scrollPosition = GUILayout.BeginScrollView (scrollPosition);
string[] list=result.Split('*');
foreach (string entry in list)
{
GUILayout.BeginHorizontal();
GUILayout.Label(entry);
GUILayout.FlexibleSpace ();
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView ();
GUILayout.EndArea();
if(Event.current.type == EventType.keyDown && Event.current.character == '
& #39; && inputStr.Length > 0)
{
result+=inputStr+"*";
inputStr = "";
scrollPosition.y = 1000000;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询