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中创建 ...
随机推荐
- TensorFlow学习('utf-8' codec can't decode byte 0xff in position 0: invalid start byte)
使用语句: image_raw_data = tf.gfile.GFile("./picture.jpg", "r").read() 读取图像时报错如下: Un ...
- pass语句
Python pass是空语句,是为了保持程序结构的完整性. pass 不做任何事情,一般用做占位语句. #!/usr/bin/python # -*- coding: UTF-8 -*- # 输出 ...
- sqoop mysql--->hive 报错 (ERROR tool.ImportTool: Import failed: java.io.IOException: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf)
ERROR tool.ImportTool: Import failed: java.io.IOException: java.lang.ClassNotFoundException: org.apa ...
- 全面理解 ASP.NET Core 依赖注入 (转载)
DI在.NET Core里面被提到了一个非常重要的位置, 这篇文章主要再给大家普及一下关于依赖注入的概念,身边有工作六七年的同事还个东西搞不清楚.另外再介绍一下.NET Core的DI实现以及对实例 ...
- C#中HttpWebRequest的用法详解(转载)
1.HttpWebRequest和HttpWebResponse类是用于发送和接收HTTP数据的最好选择.2.命名空间:System.Net3.HttpWebRequest对象不是利用new关键字创建 ...
- 2019 wishes
1. 永恒目标:爱自己,依靠自己,全家人身心健康. 2. 投稿4篇+,发表2+,不管什么刊物,书稿交给出版社.//改动一下,尽量发高质量杂志和期刊. 3. 带着儿子一起学习怎么和别人主动打招呼,做个有 ...
- JAVA类加载和初始化
JAVA类的加载和初始化 一.类的加载和初始化过程 JVM将类的加载分为3个步骤: 1.加载(Load):class文件创建Class对象. 2.链接(Link) 3.初始化(Initialize) ...
- ORA-28002 密码过期解决方案
ORA-28002 密码过期解决方案 错误场景:当使用sqlplus进行登录时报错:ORA-28002 密码过期.错误原因:由于oracle 11g 在默认在default概要文件中设置了密码过期天数 ...
- ios 开发UI篇— UIToolbar
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIToolbar : UIView <UIBarPositioning& ...
- SSM(SpringMVC+Spring+Mybatis)框架学习理解
近期做到的项目中,用到的框架是SSM(SpringMVC+Spring+Mybatis).之前比较常见的是SSH.用到了自然得了解各部分的分工 spring mvc 是spring 处理web层请求的 ...