private void Initialize() { var filter = GetComponent <MeshFilter>(); if (!filter) { Destroy(this); } var mesh = filter.sharedMesh; hook = FindObjectsOfType <DynamicMeshCombinerHook>().FirstOrDefault(h => h.type == type); if (!hook) { var hookGo = new GameObject("DynamicMeshCombiner: " + type); hook = hookGo.AddComponent <DynamicMeshCombinerHook>(); hook.type = type; hook.ref_vertices = mesh.vertices; hook.ref_uvs = mesh.uv; hook.ref_normals = mesh.normals; hook.ref_indices = mesh.GetIndices(0); hook.gameObject.layer = gameObject.layer; } var mRenderer = GetComponent <MeshRenderer>(); mRenderer.enabled = false; if (!material) { if (mRenderer) { material = mRenderer.sharedMaterial; } } hook.material = material; }
private void Initialize() { var filter = GetComponent<MeshFilter>(); if (!filter) { Destroy(this); } var mesh = filter.sharedMesh; hook = FindObjectsOfType<DynamicMeshCombinerHook>().FirstOrDefault(h => h.type == type); if (!hook) { var hookGo = new GameObject("DynamicMeshCombiner: " + type); hook = hookGo.AddComponent<DynamicMeshCombinerHook>(); hook.type = type; hook.ref_vertices = mesh.vertices; hook.ref_uvs = mesh.uv; hook.ref_normals = mesh.normals; hook.ref_indices = mesh.GetIndices(0); hook.gameObject.layer = gameObject.layer; } var mRenderer = GetComponent<MeshRenderer>(); mRenderer.enabled = false; if (!material) { if (mRenderer) { material = mRenderer.sharedMaterial; } } hook.material = material; }