打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
u3d笔记B2输入
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public class inputtext : MonoBehaviour {

public string MyEnterString="testtestest";
public Rect MyEnterTextRect;
public Rect mRect;
public Rect mRect2;
//private Camera cmaera;
// Use this for initialization
private Vector3 worldP1;
private Vector3 worldP2;//世界图片高度坐标。
private float hx;
private float hy;
private float hyy;//GUI宽高度
private float hxx;
private Vector2 position1;//gui坐标
private Vector2 position2;


int fonth;
public float scalex=1;
public int offsetx=0;
public int offsety;
int TimeInterval; //时间间隔。
int TimeI= System.DateTime.Now.Second;//当前时间。


public bool sumf= false;
public bool textinte = true ;
public bool lineout = false;

public Color xcolor=Color.black;
//public GameObject x1;
//public GameObject x2;
GUIStyle bb=new GUIStyle();
void Start () {


// xcolor=xcolor;
//GUI.Label(new Rect(10,20,100,200), MyEnterString);

//得到图片的大小
//hy=gameObject.transform.GetComponent<Renderer>.bounds.size.y; //高度。
hy=gameObject.transform.GetComponent<Renderer>().bounds.size.y;
hx=gameObject.transform.GetComponent<Renderer>().bounds.size.x;//宽度。
worldP1 = new Vector3 (transform.position.x-(hx/2), transform.position.y+(hy/2),transform.position.z);
worldP2 = new Vector3 (transform.position.x+(hx/2), transform.position.y-(hy/2),transform.position.z);//右上角位置
//x1.transform.position=worldP1;
//x2.transform.position=worldP2;
//两个位置转换为屏幕坐标。
position1 = Camera.main.WorldToScreenPoint (worldP1);
position2 = Camera.main.WorldToScreenPoint (worldP2);
//求出对角在屏幕上的宽度
hxx =position2.x-position1.x;
hyy= position1.y-position2.y;
// Debug.Log ("--"+hxx+"__"+hyy+"----------"+position1+"--"+position2);
//mRect=new Rect(position1.x+2,Screen.height-position1.y, 100, -hyy*2);
//gui坐标和屏幕坐标相反。所以再改。
//mRect=new Rect(position1.x+2+offsetx,Screen.height-position1.y+offsety, hxx+offsetx*2, hyy);
// mRect=new Rect(position1.x+offsetx,Screen.height-position1.y+offsety, hxx-offsetx, hyy);
//int testxx=(int)(Screen.height-position1.y+offsety);
// Debug.Log(testxx);
//mRect=new Rect(10,20,100,200);

}
// Update is called once per frame
void Update () {
}
void OnGUI()
{



mRect=new Rect(position1.x+2+offsetx,Screen.height-position1.y+offsety, hxx-offsetx, hyy);
int ra=(int)xcolor.r;
int rg=(int)xcolor.g;
int rb=(int)xcolor.b;

bb.normal.background = null;    //这是设置背景填充的
// Debug.Log("color"+ra+rg+rb);
bb.normal.textColor=new Color(ra,rg,rb);   //设置字体颜色的
// bb.normal.textColor = Color.yellow;

//bb.normal.textColor=new color((int)xcolor.r,(int)xcolor.g,(int)xcolor.b);
fonth=(int)Mathf.Ceil( hyy*scalex);
Debug.Log(fonth);
bb.fontSize = fonth;
//bb.fontSize = (int)Mathf.Ceil((hyy)*scalex);  
if (lineout == false) 
{
bb.wordWrap=true;
}
else
{
bb.wordWrap=false;

}

//GUI.TextArea(mRect, MyEnterString,20);
GUI.Label(mRect, MyEnterString,bb);
if (textinte)
{
GUI.SetNextControlName("user");
MyEnterString = GUI.TextField(mRect, MyEnterString,5,bb);
//if (sumf)   MyEnterString= Regex.Replace(MyEnterString, "[^0-9]", "");

if (sumf)   MyEnterString= Regex.Replace(MyEnterString, "[^a-z,A-Z]", "");
}
}
public void SetString(string x)
{
TimeInterval= Mathf.Abs( System.DateTime.Now.Second-TimeI) ;
TimeI= System.DateTime.Now.Second;
//Debug.Log ("子程序被调用/time:"+TimeInterval+"--"+TimeI);
if ((TimeInterval >0)&&(x!=""))
{
MyEnterString=x;
}
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#人脸识别入门篇
实现Android5
[Unity3D]Unity3D游戏开发之截屏保存精彩瞬间
泊松分布的期望和方差推导
Unity position和localposition
ASP生成折线图
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服