实现效果 拖动readplane 当包围盒最小点超出bluePlane的最小点时(仅做了左边裁剪),对超出部分裁剪,当全部超出隐藏readPlane 当readPlane包围盒的最大坐标点大于bluePlane的最小点时,显示readPlane;
阅读此文时,读者最好具备世界坐标 本地坐标 bounds 等之类的知识!
collider.bounds、render.bounds的min max是世界坐标,size是大小 mesh.bounds是本地坐标。mesh.vertices对线框顶点坐标更改本资源出处狗刨网。
1.
public Transform readPlane;
2. public Transform bluePlane;
3. Bounds readBoundPlane;
4. Bounds blueBoundPlane;
5. Vector3 blueBoundMin;
6. Vector3 blueBoundMax;
7. Mesh mesh;
8. void Start() {
9. mesh=readPlane.GetComponent 10. Vector3[] ve=mesh.vertices; 11. print(ve[1]+“\\\\”+ve[3]);//readPlane最左边两个点 12. blueBoundPlane=bluePlane.gameObject.collider.bounds; 13. blueBoundMin=blueBoundPlane.min; 14. blueBoundMax=blueBoundPlane.max; 15. print(blueBoundMin+“||||”+blueBoundMax+“|||”+blueBoundPlane.size+“|||||”+blueBoundPlane.center); 16. } 17. void Update() { 18. if(Input.GetMouseButton(0)) { 19. readBoundPlane=readPlane.GetComponent 20. if(readBoundPlane.min.x 21. Vector3[] vec3=mesh.vertices; 22. Vector3 vec3local=(readPlane.worldToLocalMatrix*new Vector3(readBoundPlane.min.x-blueBoundMin.x,0,0));//因为 collider.bounds.min是世界坐标,mesh.vertices是本地坐标所以需要世界到本地的转化 23. vec3[1]=new Vector3(mesh.bounds.min.x-vec3local.x,vec3[1].y,vec3[1].z); 24. vec3[3]=new Vector3(mesh.bounds.min.x-vec3local.x,vec3[3].y,vec3[3].z); 25. Vector2[] uvs=new Vector2[vec3.Length]; 26. for(int i=0;i 28. uvs=new Vector2(((readBoundPlane.min.x- blueBoundMin.x+readBoundPlane.size.x)/readBoundPlane.size.x,mesh.uv.y); //更新UV 29. } else { 30. uvs=new Vector2(mesh.uv.x,mesh.uv.y); 31. } 32. } 33. mesh.uv=uvs; 34. mesh.vertices=vec3; 35. } if(readBoundPlane.max.x<=blueBoundMin.x) { 36. readPlane.GetComponent 37. } if(readBoundPlane.max.x>blueBoundMin.x) { 38. readPlane.GetComponent 39. } 40. float x=Input.GetAxis(“Mouse X”); 41. float y=Input.GetAxis(“Mouse Y”); 42. readPlane.position+=new Vector3(x,y,0); 43. } 44. } 因篇幅问题不能全部显示,请点此查看更多更全内容