位置: 编程技术 - 正文
推荐整理分享【边玩边学Unity3d】实现可编辑网格(unity3drpg游戏教程),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:unity 边玩边下,unity3d自学教程视频,unity游戏教程完整版,unity 边玩边下,unity玩游戏,unity游戏教程完整版,unity玩游戏,unity 边玩边下,内容如对您有帮助,希望把文章链接给更多的朋友!
转载: Prefab, 以供多次实例化调用。
脚本如下:
[csharp] view plaincopyusing UnityEngine; using System.Collections; public class Vertex : MonoBehaviour { private const float size = 0.f; private Vector3[] newVertices = { new Vector3(size, -size, 0), new Vector3(size, size, 0), new Vector3(-size, size, 0), new Vector3(-size, -size, 0) }; private Vector2[] newUV = { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) }; private int[] newTriangles = {0, 3, 2, 0, 2, 1}; private Vector3[] newNormals = {Vector3.forward, Vector3.forward, Vector3.forward, Vector3.forward};//forward private Vector4[] newTangents = { new Vector4(-1, 0, 0, -1), new Vector4(-1, 0, 0, -1), new Vector4(-1, 0, 0, -1), new Vector4(-1, 0, 0, -1) }; // Use this for initialization void Start () { Mesh mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; mesh.normals = newNormals; mesh.tangents = newTangents; } } 然后,是Edge Prefab预设,即实现两端顶点位置改变时可以更新自身网顶点位置,且在鼠标长按后实现添加顶点的边对象。该对象组件与Vertex Prefab大致相同,其脚本“Edge”中多了起始和终止顶点属性,以及计算自己网顶点的CalcuVertexPosition方法。脚本如下:
[csharp] view plaincopyusing UnityEngine; using System.Collections; public class Edge : MonoBehaviour { private GameObject startVertex; private GameObject endVertex; private Vector3[] newVertices = new Vector3[4]; private const float size = 0.f; private Vector3[] basicVertices = { new Vector3(size, 0, 0), new Vector3(size, 0, 0), new Vector3(-size, 0, 0), new Vector3(-size, 0, 0) }; private Vector2[] newUV = { new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0) }; private int[] newTriangles = {0, 3, 2, 0, 2, 1}; private Vector3[] newNormals = {Vector3.forward, Vector3.forward, Vector3.forward, Vector3.forward}; private Vector4[] newTangents = { new Vector4(-1, 0, 0, -1), new Vector4(-1, 0, 0, -1), new Vector4(-1, 0, 0, -1), new Vector4(-1, 0, 0, -1) }; public GameObject StartVertex { get {return startVertex;} set {startVertex = value;} } public GameObject EndVertex { get {return endVertex;} set {endVertex = value;} } public void CalcuVertexPosition () { if(startVertex == null || endVertex == null){ return; } Vector3 startPosition = startVertex.transform.localPosition; Vector3 endPosition = endVertex.transform.localPosition; float length = Vector3.Distance(startPosition, endPosition) - 0.f; float halfLength = length * 0.5f; Vector3 position = (endPosition startPosition)*0.5f; Quaternion rotation = Quaternion.FromToRotation(Vector3.up, startPosition - endPosition ); gameObject.transform.localPosition = position; gameObject.transform.localRotation = rotation; BoxCollider collider = GetComponent<BoxCollider>(); collider.size = new Vector3(0.f, length, 0.f); newVertices[0] = halfLength*Vector3.down basicVertices[0]; newVertices[1] = halfLength*Vector3.up basicVertices[1]; newVertices[2] = halfLength*Vector3.up basicVertices[2]; newVertices[3] = halfLength*Vector3.down basicVertices[3]; ResetMesh(); } public void ResetMesh(){ Mesh mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; mesh.normals = newNormals; mesh.tangents = newTangents; } } 先到这里,下一篇完成MeshObject对象,以及MeshBuilder、MeshEditor脚本。Unity3D开发之Unity5版本自写Shader没有雾的效果问题 原本项目是Unity4.6版本的,升级到Unity5之后发现原本的雾不再看见了,然后查了一下相关资料,发现官方是改变了雾的渲染。这里有相关的官方方式:htt
Unity3D制作2D精灵动画 首先导入图片,我自己做了个简单的图片。图片导入unity3d,修改spritemodel,点击spriteeditor。如果,图片中的各个元素距离比较开,可以用Slice自动划分。
Unity3D教程宝典之Shader篇 基本知识 基础讲:基本知识以下内容不需要入门的时候立刻阅读和理解,建议逐渐深入学习后,不时回来看看即可。什么事GUP?GUP:GraphicProcessingUnit,中文翻译为
标签: unity3drpg游戏教程
本文链接地址:https://www.jiuchutong.com/biancheng/372802.html 转载请保留说明!上一篇:【猫猫的Unity Shader之旅】之双面材质和多Pass渲染(猫的猫的视频)
友情链接: 武汉网站建设