Unity3D GUI绘制折线图
2013-09-27 12:09
1071 查看
using UnityEngine; using System.Collections; using System; public class DrawLine : MonoBehaviour { public Vector2[] m_point;//特征点位置 public Color m_lineColor; private static Texture2D m_texure;//最终渲染得到的带有折线的纹理 public void InitCanvas(Vector2[] point, int width, int height) { m_point = point; m_texure = new Texture2D(width,height); } public IEnumerator Draw() { //清空纹理对象 for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { m_texure.SetPixel(i, j, Color.white); } } Vector2 currentPoint = m_point[0]; for (int i = 1; i < m_point.Length; i++) { for (float j = 0; j < 1; j = j + 0.01f) { Vector2 temp = Vector2.Lerp(m_point[i-1],m_point[i],j); m_texure.SetPixel(Convert.ToInt32(temp.x),Convert.ToInt32(temp.y),m_lineColor); } currentPoint = m_point[i]; } m_texure.Apply(); yield return m_texure; } void OnPostRender() { StartCoroutine(Draw()); } void Start() { InitCanvas(m_point, 100, 100); } void OnGUI() { GUI.DrawTexture(new Rect(0, 0, 100, 100), m_texure); } }
相关文章推荐
- Unity3d Shader开发(三)Pass(Culling & Depth Testing)
- Unity Web Cache
- Unity3d学习
- Unity3d Shader开发(三)Pass(Color, Material, Lighting )
- unity 字体添加边框颜色
- Unity3d Shader开发(二)SubShader
- Unity3d绘制饼状图
- 零基础Unity3D游戏开发系列 第三章:Unity脚本编程(十八)代码执行顺序
- 用DropBox分享Unity3D的Web应用
- unity3d 捕获系统日志,来处理一些问题
- unity3d游戏开发——新手引导
- unity3d各种OpenFileDialog操作
- Unity3d开发android项目时引入jar包读取图片资源的问题
- 使用 MonoDevelop 调试 Unity3D 的正确步骤
- unity3d 捕获系统日志,来处理一些问题
- Unity3D:Unity Serialization
- Unity3d不支持vistual studio2012?用vs2012打开unity c#脚本进行编码的方法。
- unity 确定敌人行走路线
- unity 小地图的制作
- unity3D相机缓慢看向目标物体