Unity 使用 EzySlice 实现模型切割
2020-06-02 06:23
771 查看
Unity 使用 EzySlice 实现模型切割
老规矩,直接上代码:
EzySlice 插件 在下面的链接工程中。
using System.Collections; using System.Collections.Generic; using UnityEngine; using EzySlice; public class Splitter_ZH : MonoBehaviour { //切割预制体材质 public Material _NewMaterial; //被切割预制体数组 public List <GameObject> _ListGamPreFab; void Update() { float _Mx = Input.GetAxis("Mouse X"); transform.Rotate(0, 0, _Mx); //当点击鼠标左键时 if (Input.GetMouseButtonDown(0)) { //创建忽略切割对象 Collider[] _Colliders = Physics.OverlapBox(transform.position, new Vector3(4, 0.00005f , 4), transform.rotation, ~LayerMask.GetMask("Solid")); foreach (var item in _Colliders) { Destroy(item); //切割 //GameObject[] _objs GameObject[] _objs = item.gameObject.SliceInstantiate(transform.position, transform.up); //切割出现的物体 SlicedHull _SlicedHull = item.gameObject.Slice(transform.position, transform.up); if (_SlicedHull != null) { //切割下半部分部分 物体 GameObject _Lower = _SlicedHull.CreateLowerHull(item.gameObject, _NewMaterial); //切割上半部分部分 物体 GameObject _Upper = _SlicedHull.CreateUpperHull(item.gameObject, _NewMaterial); GameObject[] _objs = new GameObject[] { _Lower, _Upper }; for (int i = 0; i < _objs.Length; i++) { _objs[i].AddComponent<Rigidbody>(); _objs[i].AddComponent<MeshCollider>().convex = true; } } } } //物体生成 if (Input.GetMouseButtonDown(1)) { GameObject _GamPrefab = _ListGamPreFab[Random.Range(0, _ListGamPreFab.Count - 1)]; if (_GamPrefab.GetComponent<Rigidbody>()) { GameObject _NewGamPrefab= Instantiate(_GamPrefab); _NewGamPrefab.GetComponent<Rigidbody>().AddForce(Vector3.up * 500); } else { _GamPrefab.AddComponent<Rigidbody>(); GameObject _NewGamPrefab = Instantiate(_GamPrefab); _NewGamPrefab.GetComponent<Rigidbody>().AddForce(Vector3.up * 500); } } } }
暂时先这样吧,如果实在看不明白就留言,看到我会回复的。
路长远兮,哈哈哈,与君共勉。
GitHub: EzySlice 工程
相关文章推荐
- “Unreal Engine 4 - 使用ProceduralMeshComponent实现模型实时切割”无效的问题解决
- unity使用vuforia实现模型AR效果
- 使用FormView Unity和LINQ实现的3层架构----MasterDataManage模型
- Unreal Engine 4 —— 使用ProceduralMeshComponent实现模型实时切割
- Unreal Engine 4 —— 使用ProceduralMeshComponent实现模型实时切割
- Unity之触屏控制_实现模型旋转和缩放—Touch类的使用
- 基于GPU实现的经典光照模型算法:漫反射模型(使用cg语言实现)
- 使用DOM模型实现图片在div之间切换
- 使用Unity Application block实现Ioc[原创]
- osg中使用MatrixTransform来实现模型的平移/旋转/缩放
- 【Unity Shaders】使用Unity Render Textures实现画面特效——建立画面特效脚本系统
- Unity模型资源使用流程
- 演示在应用在使用hibernate实现模型层的开发(手动配置):
- C# WinForm 使用多种方法实现 图片的切割和拼接
- Unity3D For iPhone游戏引擎之使用脚本实现模型平移与模型旋转(六)
- python使用__new__来实现singleton单例模型
- 【Unity Shaders】使用Unity Render Textures实现画面特效——画面特效中的亮度、饱和度和对比度
- 【Unity Shaders】使用Unity Render Textures实现画面特效——画面.
- 使用Unity新版动画系统Animator实现三连击
- [UnityShader]使用Unity Render Textures实现画面特效——建立画面特效脚本系统