c# – 如何统一显示网格线?
发布时间:2020-12-15 22:23:48 所属栏目:百科 来源:网络整理
导读:我正在进行我的第一场2D比赛. 我在生成游戏领域时遇到问题. 我需要做3件事. 用方形瓷砖填充场地(完成) 在每个瓷砖上显示随机数(完成) 显示网格线(问题在这里) 要创建我的主板,我使用附加到主相机的脚本. 这是我使用的功能: void BoardSetup(){ board = new
我正在进行我的第一场2D比赛.
我在生成游戏领域时遇到问题. 我需要做3件事. >用方形瓷砖填充场地(完成) 要创建我的主板,我使用附加到主相机的脚本. void BoardSetup() { board = new GameObject("Board"); boardHolder = board.transform; for (int x = 0; x < columns; x++) { for (int y = 0; y < rows; y++) { GameObject toInstantiateBackground = snowTile; GameObject backgroundInstance = Instantiate(toInstantiateBackground,new Vector3(x,y,0f),Quaternion.identity) as GameObject; backgroundInstance.transform.SetParent(boardHolder); AddRandomNumber(backgroundInstance,x,y); } } float step = snowTile.GetComponent<SpriteRenderer>().bounds.max[0] - snowTile.GetComponent<SpriteRenderer>().bounds.min[0]; CreateGrid(new Vector3(0,0),new Vector3(rows-1,columns-1,step); } 这是我的CreateGrid块: void CreateLineMaterial() { if (!lineMaterial) { lineMaterial = new Material("Shader "Lines/Colored Blended" {" + "SubShader { Pass { " + " Blend SrcAlpha OneMinusSrcAlpha " + " ZWrite Off Cull Off Fog { Mode Off } " + " BindChannels {" + " Bind "vertex",vertex Bind "color",color }" + "} } }"); lineMaterial.hideFlags = HideFlags.HideAndDontSave; lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; } } private void CreateGrid(Vector3 start,Vector3 stop,float step) { CreateLineMaterial(); // set the current material lineMaterial.SetPass(0); GL.Begin(GL.LINES); GL.Color(gridColor); // Vertical lines for (float x = start[0]; x <= stop[0]; x += step) { GL.Vertex3(x,0f,0f); GL.Vertex3(x,stop[1],0f); } // Horizontal lines for (float y = start[0]; y <= stop[1]; y += step) { GL.Vertex3(0f,0f); GL.Vertex3(stop[0],0f); } GL.End(); } 我使用了here的例子(并修改了它). 但是当我运行我的游戏时,我只看到了雪地联系和数字 我试图只运行CreateGrid()但在这种情况下我只看到黑屏. 解决方法
您引用的链接是在3D中绘制线条.您应该加载正交矩阵以在屏幕空间中绘制2d图元.首先推动一个新矩阵,加载正交矩阵,绘图,然后在完成后弹出矩阵:
GL.PushMatrix(); mat.SetPass(0); GL.LoadOrtho(); GL.Begin(GL.LINES); // Set colors and draw verts GL.End(); GL.PopMatrix(); 不要忘记你的顶点坐标应该在0和1之间. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 在Dynamic LINQ to Entities中使用DateTime
- oracle sys/system账户登录
- ruby-on-rails – 在heroku回滚后部署
- ruby-on-rails – Rails中的Angular ui bootstrap自定义模板
- c# – 准确测量Asp.Net MVC应用程序的请求/响应时间的方法
- Flex 4 ( Flash Builder 4 ) DropDownList实现数据拖拽 -示
- ISE烧写程序时出错: '2': Verifying device...Fai
- [译]迁移到新的 React Context Api
- 红宝石 – 生成长度在给定范围内的数组的所有可能组合
- objective-c – 如何在Cocoa中绘制锥形椭圆形阴影