首页 文章 精选 留言 我的

精选列表

搜索[unity],共752篇文章
优秀的个人博客,低调大师

Unity3D实现模型体积拖拽变化

实现模型拖拽体积改变功能算法: publicTransformcrossLeft; publicTransformcro***ight; publicTransformarrowUp; publicTransformarrowDown; //模型结构子对象 publicTransformlegLeftUp; publicTransformlegRightUp; publicTransformlegLeftDown; publicTransformlegRightDown; publicTransformarrow; //////传动带模型MeshFilter ///publicMeshFilterconveyorMeshFilter; //////传送带边沿护栏模型MeshFilter ///publicMeshFilterguardBarMeshFilter; publicBoxColliderboxCollider; //Mesh保存 privateDictionaryconveyorMeshLeftVertices; privateDictionaryconveyorMeshRightVertices; privateDictionaryconveyorMeshUpVertices; privateDictionaryconveyorMeshDownVertices; privateDictionaryguardBarMeshLeftVertices; privateDictionaryguardBarMeshRightVertices; privateDictionaryguardBarMeshUpVertices; privateDictionaryguardBarMeshDownVertices; //交互所用变量 privatefloatfirstDistanceToOtherCross; privateVector3nowInputMousePosition; floatendDistance; privateTransformotherCross; privateVector3otherCrossScreenPostion; privateVector3lastInputMousePoistion; 核心方法: //初始化 voidInit() { conveyorMeshLeftVertices=FiltrateVertices(conveyorMeshFilter.mesh,VecticeDir.Left); conveyorMeshRightVertices=FiltrateVertices(conveyorMeshFilter.mesh,VecticeDir.Right); conveyorMeshUpVertices=FiltrateVertices(conveyorMeshFilter.mesh,VecticeDir.Up); conveyorMeshDownVertices=FiltrateVertices(conveyorMeshFilter.mesh,VecticeDir.Down); guardBarMeshLeftVertices=FiltrateVertices(guardBarMeshFilter.mesh,VecticeDir.Left); guardBarMeshRightVertices=FiltrateVertices(guardBarMeshFilter.mesh,VecticeDir.Right); guardBarMeshUpVertices=FiltrateVertices(guardBarMeshFilter.mesh,VecticeDir.Up); guardBarMeshDownVertices=FiltrateVertices(guardBarMeshFilter.mesh,VecticeDir.Down); //length=1; //heigth=1; boxCollider=gameObject.GetComponent(); if(name.Contains("left")) { otherCross=converyEntityMediator.converyEntityView.cro***ight; isLeft=true; } else { otherCross=converyEntityMediator.converyEntityView.crossLeft; isLeft=false; } } /// ///筛选顶点,分成左右两堆 /// ///顶点方向 DictionaryFiltrateVertices(Meshmesh,VecticeDirdir) { Dictionaryresult=newDictionary(); for(inti=0;i<mesh.vertices.Length;i++) { switch(dir) { caseVecticeDir.Left: if(mesh.vertices[i].z>0) { result.Add(i,mesh.vertices[i]); } break; caseVecticeDir.Up: if(mesh.vertices[i].x>0) { result.Add(i,mesh.vertices[i]); } break; caseVecticeDir.Right: if(mesh.vertices[i].z<0) { result.Add(i,mesh.vertices[i]); } break; caseVecticeDir.Down: if(mesh.vertices[i].x<0) { result.Add(i,mesh.vertices[i]); } break; } } returnresult; } //宽度 publicvoidChangeWidth(floatwidth,Vector3dir,boolisUp) { ListconveyorMeshVertices=newList(conveyorMeshFilter.mesh.vertices); ListguardBarMeshVertices=newList(guardBarMeshFilter.mesh.vertices); floathalfWidth=width/2; transform.position+=halfWidth*(transform.rotation*dir).normalized; //this.length+=length; //改变板和边栏的长度 foreach(KeyValuePairiteminconveyorMeshUpVertices) { conveyorMeshVertices[item.Key]+=Vector3.right*halfWidth; } foreach(KeyValuePairiteminconveyorMeshDownVertices) { conveyorMeshVertices[item.Key]-=Vector3.right*halfWidth; } foreach(KeyValuePairiteminguardBarMeshUpVertices) { guardBarMeshVertices[item.Key]+=Vector3.right*halfWidth; } foreach(KeyValuePairiteminguardBarMeshDownVertices) { guardBarMeshVertices[item.Key]-=Vector3.right*halfWidth; } if(isUp) { //设置子物体的位置 legLeftUp.localPosition+=halfWidth*dir; legRightUp.localPosition+=halfWidth*dir; legLeftDown.localPosition-=halfWidth*dir; legRightDown.localPosition-=halfWidth*dir; arrowUp.localPosition+=halfWidth*dir; arrowDown.localPosition-=halfWidth*dir; } else { //设置子物体的位置 legLeftUp.localPosition-=halfWidth*dir; legRightUp.localPosition-=halfWidth*dir; legLeftDown.localPosition+=halfWidth*dir; legRightDown.localPosition+=halfWidth*dir; arrowUp.localPosition-=halfWidth*dir; arrowDown.localPosition+=halfWidth*dir; } floatarrowScale=Mathf.Clamp(((ConveyorEntity)entity).conveyorProperty.Width*2f,0.2f,1); arrow.localScale=newVector3(arrowScale,1,arrowScale); conveyorMeshFilter.mesh.SetVertices(conveyorMeshVertices); guardBarMeshFilter.mesh.SetVertices(guardBarMeshVertices); //设置collider boxCollider.size+=Vector3.right*width; } ///改变传送带长度 /// ///传送带长度 ///是否选择的左边移动 publicvoidChangeLength(floatlength,Vector3dir,boolisChoiceLeft=false) { ListconveyorMeshVertices=newList(conveyorMeshFilter.mesh.vertices); ListguardBarMeshVertices=newList(guardBarMeshFilter.mesh.vertices); floathalfLength=length/2; transform.position+=halfLength*(transform.rotation*dir).normalized; //改变板和边栏的长度 foreach(KeyValuePairiteminconveyorMeshLeftVertices) { conveyorMeshVertices[item.Key]+=Vector3.forward*halfLength; } foreach(KeyValuePairiteminguardBarMeshLeftVertices) { guardBarMeshVertices[item.Key]+=Vector3.forward*halfLength; } foreach(KeyValuePairiteminconveyorMeshRightVertices) { conveyorMeshVertices[item.Key]-=Vector3.forward*halfLength; } foreach(KeyValuePairiteminguardBarMeshRightVertices) { guardBarMeshVertices[item.Key]-=Vector3.forward*halfLength; } if(isChoiceLeft) { //设置子物体的位置 legLeftUp.localPosition+=halfLength*dir; legRightUp.localPosition-=halfLength*dir; legLeftDown.localPosition+=halfLength*dir; legRightDown.localPosition-=halfLength*dir; crossLeft.localPosition+=halfLength*dir; cro***ight.localPosition-=halfLength*dir; } else { //设置子物体的位置 legLeftUp.localPosition-=halfLength*dir; legRightUp.localPosition+=halfLength*dir; legLeftDown.localPosition-=halfLength*dir; legRightDown.localPosition+=halfLength*dir; crossLeft.localPosition-=halfLength*dir; cro***ight.localPosition+=halfLength*dir; } //floatarrowScale=Mathf.Clamp(((ConveyorEntity)entity).conveyorProperty.Length*2f,0.2f,1); //arrow.localScale=newVector3(arrowScale,1,arrowScale); conveyorMeshFilter.mesh.SetVertices(conveyorMeshVertices); guardBarMeshFilter.mesh.SetVertices(guardBarMeshVertices); //设置collider boxCollider.size+=Vector3.forward*length; ChangeBounds(100);//拉伸mesh会导致原bound不在摄像机视角下,造成传送带不渲染(FrustumCulling) } privatevoidChangeBounds(floatboundLength) { Vector3bound=newVector3(boundLength,boundLength,boundLength); conveyorMeshFilter.mesh.bounds=newBounds(transform.position,bound); guardBarMeshFilter.mesh.bounds=newBounds(transform.position,bound); } 交互输入: privatevoidOnMouseDown() { endAddDistance=0; otherArrowScreenPostion=Camera.main.WorldToScreenPoint(otherArrow.position); lastInputMousePoistion=Input.mousePosition; lastDistanceToOtherCross=Vector2.Distance(otherArrowScreenPostion,lastInputMousePoistion); } privatevoidOnMouseDrag() { nowInputMousePosition=Input.mousePosition; floatdistance=Vector2.Distance(nowInputMousePosition,lastInputMousePoistion)*0.1f; floatotherDistaceToNowInputMousePosition=Vector2.Distance(otherArrowScreenPostion,nowInputMousePosition); //减少宽度 if(lastDistanceToOtherCross>otherDistaceToNowInputMousePosition) { endAddDistance-=distance; ChangeWidth(-distance,(transform.localPosition-otherArrow.localPosition).normalized,isUp); } //增加宽带 elseif(lastDistanceToOtherCross<otherDistaceToNowInputMousePosition) { endAddDistance+=distance; ChangeWidth(distance,(transform.localPosition-otherArrow.localPosition).normalized,isUp); } if(otherDistaceToNowInputMousePositionotherDistaceToNowInputMousePosition) { if(Vector3.Distance(transform.localPosition,otherCross.localPosition)Vector3.Distance(transform.localPosition,otherCross.localPosition)) { return; } endDistance-=distance; converyEntityMediator.ChangeLength(-distance,(transform.localPosition-otherCross.localPosition).normalized,isLeft); } //增加长度 elseif(firstDistanceToOtherCross<otherDistaceToNowInputMousePosition) { endDistance+=distance; converyEntityMediator.ChangeLength(distance,(transform.localPosition-otherCross.localPosition).normalized,isLeft); } lastInputMousePoistion=Input.mousePosition; lastDistanceToOtherCross=Vector2.Distance(otherArrowScreenPostion,lastInputMousePoistion); } privatevoidOnMouseUp() { if(endAddDistance!=0) { ChangeWidth(-endAddDistance,(transform.localPosition-otherArrow.localPosition).normalized,isUp); ChangeLength(-endDistance,(transform.localPosition-otherCross.localPosition).normalized,isLeft); } }

优秀的个人博客,低调大师

Unity3d dll 热更新 基础框架

晚上有了dll 热更新的想法,今天做了一天的实验,也遇到些坑,这里总结下 工作环境: U3D5.3.2 + vs2010 +mono 下面要模拟的是一个登陆环境,点击按钮,就加载一个iGameObjec的Item, Item 上得到更新的文本内容。具体如下图 1> 程序集管理 2> Dll管理与加载 3> 逻辑代码和UI的实现 4> 打包dll+打包Assetbundle 限制1:在Android手机里动态加载dll不能使用Assembly.LoadFile(string path),只能使用Assembly.Load(byte[] rawAssembly)这个接口,所以要自己想办法先读出来。 限制2:动态加载的脚本不能在编辑器里挂在prefab上。 限制3:如果脚本在动态dll里,调用AddComponent()挂此脚本上prefab上时不能使用AddComponent(“SomeScript”)的方式调用,要用AddComponent(Type.GetType(“SomeScript”))。 限制4:在动态dll里使用[RequireComponent(typeof(SomeScript))]无效,所以不能使用。 本文转自jiahuafu博客园博客,原文链接:http://www.cnblogs.com/jiahuafu/p/8278893.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册