本文主要是介绍Unity Mesh简化为Cube mesh,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Mesh简化为Cube mesh
- 🍳食用
- 🥙子物体独立生成CubeMesh
- 🥪合并成一个CubeMesh
- 🌭Demo
🍳食用
下载并导入插件👈即可在代码中调用。
🥙子物体独立生成CubeMesh
gameObject.ToCubeMesh_Invidual();
🥪合并成一个CubeMesh
gameObject.ToCubeMesh();
🌭Demo
using EasyRoads3Dv3;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ZYF
{public class ToCubeMeshDemo : MonoBehaviour{[SerializeField]private Material cubeMat;[SerializeField,Header("独立模式")]private bool invidualModel = true;private void Start(){GameObject res = new GameObject("cube mesh");if (invidualModel ==false){var result = gameObject.ToCubeMesh();var go= DisplayMesh(mesh: result, gameObject);go.transform.SetParent(res.transform);}else{var results = gameObject.ToCubeMesh_Invidual();foreach (var c in results){var rgo= DisplayMesh(c.cubeMesh, c.meshGo);rgo.transform.SetParent(res.transform);}}}private GameObject DisplayMesh(Mesh mesh, GameObject go){var cube = new GameObject(go.name);var mf = cube.AddComponent<MeshFilter>();var mr = cube.AddComponent<MeshRenderer>();mf.mesh = mesh;mr.material = cubeMat;cube.transform.position = go.transform.position;cube.transform.rotation = go.transform.rotation;cube.transform.localScale = go.transform.lossyScale;return cube;}}}
这篇关于Unity Mesh简化为Cube mesh的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!