Unity3D开发之利用LineRenderer画曲线
来源:互联网 发布:尚学堂大数据项目 编辑:程序博客网 时间:2024/06/06 10:51
using UnityEngine;using System.Collections;using System.Collections.Generic;public class LinearDrawLine: MonoBehaviour {private int pointCnt = 0;public Color c1 = Color.red;public Color c2 = Color.blue;private LineRenderer lineRenderer;private Vector3 screenPoint;private Vector3 scanPos;private Vector3 first_pos = Vector3.zero; void Start () { scanPos = gameObject.transform.position; lineRenderer = (LineRenderer)gameObject.GetComponent("LineRenderer"); lineRenderer.material = new Material (Shader.Find("Particles/Additive")); lineRenderer.SetColors(c1, c2); lineRenderer.SetWidth(0.02F, 0.02F); lineRenderer.SetVertexCount(0); } void Update(){}void OnMouseDown(){Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);screenPoint = Camera.main.WorldToScreenPoint(scanPos);Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint);pointCnt = 0;DrawRenderLine(lineRenderer, curPosition);first_pos = curPosition;}void OnMouseDrag(){iTween.ScaleFrom(gameObject,iTween.Hash("x",2,"y",2,"z",2,"time",.1,"easetype","linear"));Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint);DrawRenderLine(lineRenderer, curPosition);}void DrawRenderLine(LineRenderer line, Vector3 vect3){if((Mathf.Abs(first_pos.x - vect3.x) < 0.1) && (Mathf.Abs(first_pos.y - vect3.y) < 0.1))return;first_pos = vect3; line.SetVertexCount(++pointCnt); line.SetPosition(pointCnt-1, vect3);print("new point: "+vect3+"+"+pointCnt);}}
这种方式相比于GL方式来说,它不需要添加到相机中,可以是点击某个物品来画图。
可以直接把这个脚本拉到物品上面就可以用了。
- Unity3D开发之利用LineRenderer画曲线
- Unity3D开发之利用GL画曲线
- lineRenderer画曲线
- unity3d 画线(LineRenderer方式)
- Unity3d LineRenderer画线
- Unity3d LineRenderer画线
- Unity3D中LineRenderer的使用
- unity之Linerenderer组件
- <Unity3D>Unity3D中LineRenderer的使用
- <Unity3D>Unity3D中LineRenderer的使用
- Unity3D之 AnimationCurve 动画曲线
- Unity3D学习记录——LineRenderer
- Unity3D技术之绘制曲线详解
- JFreeChart开发:利用JFreeChart开发实时曲线
- Unity 使用LineRenderer 画箭头
- 【Unity3d开发记录】Unity动态画曲线、弧线(GL画线)在UI上的显示
- iOS开发之利用链式编程和贝瑟尔曲线来画图
- 利用scikitlearn画ROC曲线
- mysql迁移-----拷贝mysql目录/load data/mysqldump/into outfile
- 在Raspberry PI上,NJU6061的LED控制模块的驱动
- URAL 1992
- DG保护模式与备用联机日志文件
- 设计模式六大原则(2):里氏替换原则
- Unity3D开发之利用LineRenderer画曲线
- 细数颈椎病的7大危害,可致瘫痪中风高血压
- 安卓自测试题——第十八期
- 等概率随机函数的实现
- 设计模式六大原则(3):依赖倒置原则
- C语言中唯一的一个三目运算符(条件运算符)
- ios面试题
- 指针与引用
- 起航!