unity拖动鼠标绘制矩形区域,类似于在windows桌面上拖动鼠标

想要实现的功能是:当鼠标按下时开始画矩形,矩形的边长随着鼠标拖动而动态改变,当鼠标抬起后结束矩形的绘制。谢谢大神!加分!

用GL类屏幕画线,类似于dota的选择区域
void OnPostRender() {

if (!mat) {
Debug.LogError("Please Assign a material on the inspector");

return;

}

GL.PushMatrix(); //保存当前Matirx

mat.SetPass(0); //刷新当前材质

GL.LoadPixelMatrix();//设置pixelMatrix

GL.Color(Color.yellow);

GL.Begin(GL.LINES);

GL.Vertex3(0, 0, 0);

GL.Vertex3(Screen.width, Screen.height, 0);

GL.End();

GL.PopMatrix();//读取之前的Matrix

}
具体的你可以百度这个类看看
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-08-17
代码可以参照NGUI的UIwedgte这个脚本(忘了怎么拼了)
相似回答