unity GUI绘制直线条
2013-11-08 10:53
323 查看
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);
}
}
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);
}
}
相关文章推荐
- Unity 通过LineRenderer绘制两点之间的直线
- Unity技巧总结02 GUI绘制 Loading遮罩
- 制作Unity插件之-常用GUI绘制组建
- Unity-------------------------关于GUI绘制的编程
- Unity GUI内绘制贝塞尔曲线
- Unity-使用GUI绘制进度条或者血条
- Unity-GUI绘制旋转的Texture
- 【Unity】模仿GUILayout.SelectionGird绘制一组互斥的按钮
- 在unity向量空间内绘制几何(4): 利用平面几何知识画像素直线。
- Unity调试:在GUI界面绘制Log信息
- Unity绘制跟随鼠标移动的曲线
- Graphics类绘制直线与拖动
- Unity之编辑器类将摄像机视图(targetTexture)绘制在窗口中
- Unity移动端实时阴影绘制
- GDI+ 动态绘制直线
- Unity FairyGUI测试过程
- Android: 利用SurfaceView绘制股票滑动直线解决延迟问题
- OpenCV探索之路(十四):绘制点、直线、几何图形
- Android: 利用SurfaceView绘制股票滑动直线解决延迟问题
- Unity3D GUI绘制折线图