Unity LineRenderer制作画版
Source:
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class AtwalPaint : MonoBehaviour {
public Material currentMaterial; private Color paintColor = Color.red;
private float paintSize = 0.1f;
private bool isPress = false;
private LineRenderer lineRenderer;
private List<Vector3> positions = new List<Vector3>();
private int lineCount = ; private void Update()
{
if (Input.GetMouseButtonDown())
{
isPress = true;
GameObject go = new GameObject("LineRenderer_" + lineCount);
go.transform.parent = gameObject.transform;
lineRenderer = go.AddComponent<LineRenderer>();
lineRenderer.startColor = paintColor;
lineRenderer.endColor = paintColor;
lineRenderer.startWidth = paintSize;
lineRenderer.endWidth = paintSize;
lineRenderer.material = currentMaterial;
lineRenderer.numCapVertices = ;
lineRenderer.numCornerVertices = ;
lineCount++;
AddPosition();
} if (isPress)
{
AddPosition();
} if (Input.GetMouseButtonUp())
{
lineRenderer = null;
positions.Clear();
isPress = false;
}
} void AddPosition()
{
Vector3 position = GetMousePoint();
if (positions.Count > )
{
if (Vector3.Distance(position, positions[positions.Count - ]) < 0.1f)
{
return;
}
}
position.z = -0.02f * lineCount;
positions.Add(position);
lineRenderer.positionCount = positions.Count;
lineRenderer.SetPositions(positions.ToArray());
} Vector3 GetMousePoint()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray, out hit);
if (isCollider)
{
return hit.point;
}
return Vector3.zero;
} #region color
public void OnRedColorChange(bool isOn)
{
if (isOn)
{
paintColor = Color.red;
}
}
public void OnGreenColorChange(bool isOn)
{
if (isOn)
{
paintColor = Color.green;
}
}
public void OnBlueColorChange(bool isOn)
{
if (isOn)
{
paintColor = Color.blue;
}
}
#endregion #region size
public void On1SizeChange(bool isOn)
{
if (isOn)
{
paintSize = 0.1f;
}
}
public void On2SizeChange(bool isOn)
{
if (isOn)
{
paintSize = 0.2f;
}
}
public void On4SizeChange(bool isOn)
{
if (isOn)
{
paintSize = 0.4f;
}
}
#endregion
}
Unity LineRenderer制作画版的更多相关文章
- Unity 5 引擎收费版和免费版的区别(转)
最新Unity 5的Professional Edition(收费版)具备全新而强大的功能,除了全局动态光照或是最新的基于物理的着色器之外,也把原本分开销售的Team License放入,并含有12个 ...
- unity 发布web player版,网页打开报Failed to initialize player's 3D settings
开始时我装的是unity 5.0.0b1,不知道在哪找的这个版本. web player 装的什么版本也忘了. 最后卸载了web player,重新安装web player并另外安装一个unity4. ...
- unity资源(移动版)提取 一点尝试
原地址:http://blog.csdn.net/delguoqing/article/details/22619711 最近在参与一款手游,需要制定美术制作规范.因为拿不准主意,所以决定参考其他游戏 ...
- unity LineRenderer
using UnityEngine; using System.Collections; public class Spider:MonoBehaviour { private LineRendere ...
- Unity安装(Windows版)
Unity下载助手 Unity下载助手是一个小型可执行程序(大小约为1 MB),它允许您选择要下载和安装的Unity Editor的那些组件. 如果你不知道要安装,保留默认选择,单击继续 ,然后按照安 ...
- Unity Toast插件(UGUI版)
简介 介于自己之前经历的一些开发过程,非常希望unity能有类似Toast的功能用于一些简单的信息显示.但是找来找去找了半天,都木有发现,实在是憋不住了,自己写了个,感觉还可以用,发出来共享一下... ...
- 1、手写Unity容器--极致简陋版Unity容器
模拟Unity容器实例化AndroidPhone 思路: 1.注册类型:把类型完整名称作为key添加到数据字典中,类型添加到数据字典的value中 2.获取实例:根据完整类型名称也就是key取出val ...
- Unity 4.3 2D 教程:新手上路
这篇文章译自 Christopher LaPollo 先生的 Unity 4.3 2D 教程的第一部分 Unity 4.3 2D Tutorial: Getting Started 感谢这套优秀教程的 ...
- 如何用Unity创建一个的简单的HoloLens 3D程序
注:本文提到的代码示例下载地址>How to create a Hello World 3D holographic app with Unity 之前我们有讲过一次如何在HoloLens中创建 ...
随机推荐
- 基于HP DL388 Gen 9服务器基本配置(ESXI 6.5)
最近一段时间由于做毕业设计的原因,一直处于忙碌状态,刚做完毕业设计,导师处于项目的原因,买了一台惠普服务器(人民币1.7万),服务器自带的内存仅有16 G,硬盘也就只有600G,而且磁盘还做了raid ...
- 淡说Linux 的发展史
♦ 1 Linux的简单介绍 Linux与Windows一样都是一套OS(操作系统),Windows界面美观 ,普通用户很容易上手,点点鼠标就能搞定许多操作,而Linux生下来就是为程序员的,故精通 ...
- [转]OpenGL与CUDA互操作方式总结
一.介绍 CUDA是Nvidia推出的一个通用GPU计算平台,对于提升并行任务的效率非常有帮助.本人主管的项目中采用了OpenGL做图像渲染,但是在数据处理方面比较慢,导致帧率一直上不来.于是就尝试把 ...
- 如何转换Xcode里打印的unicode编码日志
转换Xcode里打印的unicode编码日志 1)打开Terminal 2)输入python 3)print(u'\u6027\u611f\u597d\u83b1\u575e\u5973\u661f\ ...
- table的td、th的一些样式问题(宽度,边框,滚动条)
1. 给table加边框 table{ border-collapse: collapse; /*表格的边框合并为一个单一的边框*/ } table, table tr th, table tr td ...
- PhpStorm中实现代码自动换行
方法一: 随便打开一个页面,在显示行号(最左边)这里鼠标右击,勾选"Use Soft Wraps". 方法二: 选择"File-->>Settings--&g ...
- 一种比使用协程更方便的方法:Invoke(),同样达到等待执行的效果
1.Invoke(string methodName,float time) 在一定时间调用methodName函数 using UnityEngine; using System.Collectio ...
- PTA基础编程题目集6-7 统计某类完全平方数 (函数题)
本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144.676等. 函数接口定义: int IsTheNumber ( const int N ); 其中 ...
- SAP OData $batch processing
例として.1回の呼び出しで100個の新しい商品を作成したい場合.最も簡単な方法は.$ batch要求を使用して100個のPOST呼び出しすべてを単一のサービス呼び出しにまとめることです. URIの末尾 ...
- Linux - iconv 使用 - 处理 curl 乱码问题
1. 概述 好久没有写博客了, 最近看了些东西, 但是不知道怎么输出 简单写点东西吧 2. 场景 最近发现一个网站, 时不时会更新电子书, 书还很好 网站有一个 排行榜, 会把近期更新的电子书, 都列 ...