daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [RequireComponent(typeof(MeshFilter))]
  2.     [RequireComponent(typeof(MeshRenderer))]
  3.     public class MeshGenerator : MonoBehaviour {
  4.         Mesh _mesh;
  5.         MeshFilter _meshFilter;
  6.  
  7.         public void Initialize() {
  8.             _meshFilter = GetComponent<MeshFilter>();
  9.         }
  10.  
  11.         public void CreateMesh(List<Tile> tiles) {
  12.             _mesh = new Mesh();
  13.             Debug.Log(_mesh);
  14.             MeshFilter[] meshFilters = null;
  15.             for (int x = 0; x < tiles.Count; x++) {
  16.                 Tile tile = tiles[x];
  17.                 meshFilters[x] = tile.GetComponentInChildren<MeshFilter>();
  18.                 Debug.Log(tile.name + " is added.");
  19.             }
  20.             CombineInstance[] combines = new CombineInstance[meshFilters.Length];
  21.             Debug.Log(combines.Length);
  22.             int i = 0;
  23.             while (i < meshFilters.Length) {
  24.                 combines[i].mesh = meshFilters[i].sharedMesh;
  25.                 combines[i].transform = meshFilters[i].transform.localToWorldMatrix;
  26.                 i++;
  27.             }
  28.             _mesh.CombineMeshes(combines);
  29.             _meshFilter.mesh = _mesh;
  30.         }
  31.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top