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中创建 ...
随机推荐
- ubuntu查询命令行安装的软件的安装路径
which git // 查询git的安装路径
- javaSE web开发 登录思路代码
准备工作: 1.在WebContent WEB-INF lib下添加c3p0-0.9.5.2.jar mchange-common-java-0.2.11.jar ojdbc6.ja ...
- EF Core中外键关系的DeleteBehavior介绍(转自MSDN)
Delete behaviors Delete behaviors are defined in the DeleteBehavior enumerator type and can be passe ...
- linux内核netfilter连接跟踪的hash算法
linux内核netfilter连接跟踪的hash算法 linux内核中的netfilter是一款强大的基于状态的防火墙,具有连接跟踪(conntrack)的实现.conntrack是netfilte ...
- 1006.Sign in and Sign out(25)—PAT 甲级
At the beginning of every day, the first person who signs in the computer room will unlock the door, ...
- VS Code 的常用快捷键及插件(前端)
一.vs code 的常用快捷键 1.注释: a) 单行注释:[ctrl+k,ctrl+c] 或 ctrl+/ b) 取消单行注释:[ctrl+k,ctrl+u] (按下ctrl不放,再按k + u) ...
- 课时9.HTML发展史(了解)
这个图片里的时间不用都记住,只需要记住一些特殊的,1993年,1995年(在W3C接手以后,才有了真正意义上的标准),1999年这几个时间 WHATWG的目的是推广HTML的标准,HTML5是浏览器厂 ...
- SVN(独立安装)-1.9.7 centos 6.5(64位)
说明: 运行方式: 基于Apache的http.https网页访问形式: 基于svnserve的独立服务器模式. 数据存储方式: 在Berkeley DB数据库中存储数据: 使用普通的文件FSFS存储 ...
- 【七】ab压测
[任务7]ab压测 安装ab压测软件 命令:yum -y install httpd-tools 进行压力测试: 执行命令:ab -c 20 -n 5000 http://192.168.159.30 ...
- 使用jdk生成自签发证书(过程总结)
前言: 最近在做华为NB-IoT接口开发,需要用到双向认证,就去学了一下. 然后我将过程总结了一下. 相关华为论坛链接:http://developer.huawei.com/ict/forum/th ...