如何让Unity3D支持中文输入输出

大神们帮我分析下,如何让Unity3D支持中文输入输出
最新回答
甜警司

2024-09-23 00:55:41

其实很简单只需要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;
}

}
}