纳金网
标题:
终结版中文输入测试代码
[打印本页]
作者:
她。
时间:
2012-4-25 09:26
标题:
终结版中文输入测试代码
Unity3D作为web3d游戏开发利器一直为人称道,但其对中文输入的问题也一直为人诟病,不过这将成为历史!
测试地址如下:http://test.vrsh.cn/hello.html
具体实现方法如下:
其实很简单只需要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 == '
' && inputStr.Length > 0)
{
result+=inputStr+"*";
inputStr = "";
scrollPosition.y = 1000000;
}
}
}
作者:
王者再临
时间:
2012-12-30 04:10
学习了,虽然还是有难度,谢谢楼主的用心
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5