public static ChunkGO InstantiateChunk(Chunk createdChunk, Transform _parent) { ChunkGO chunkGO = InstantiateChunk(createdChunk); chunkGO.transform.parent = _parent; return(chunkGO); }
public static ChunkGO InstantiateChunk(Chunk createdChunk) { //SEM VARIAVEL CHUNKPREFAB: //GameObject chunkGO = new GameObject("Chunk: " + createdChunk.chunkPos.ToString()); //chunkGO.AddComponent<MeshFilter>(); //chunkGO.AddComponent<MeshRenderer>().material = Resources.Load<Material>("TestMaterial"); //chunkGO.transform.position = Chunk.CHUNK_WIDTH * createdChunk.chunkPos; //ChunkMarching chunkMarchingScript = chunkGO.AddComponent<ChunkMarching>(); //------------ GameObject chunkGO = Instantiate(WorldGeneration.CHUNK_PREFAB, new Vector3(Chunk.CHUNK_WIDTH * createdChunk.chunkPos.x, Chunk.CHUNK_HEIGHT * createdChunk.chunkPos.y, Chunk.CHUNK_WIDTH * createdChunk.chunkPos.z), Quaternion.identity); chunkGO.name = "Chunk: " + createdChunk.chunkPos.ToString(); ChunkGO chunkMarchingScript = chunkGO.GetComponent <ChunkGO>(); chunkMarchingScript.marchedChunk = createdChunk; chunkGO.GetComponent <MeshFilter>().sharedMesh = createdChunk.meshData.BuildMesh(); chunkMarchingScript.UpdateMeshCollider(); return(chunkMarchingScript); }
// public GameObject CreateGO() { GameObject chunkGO = new GameObject("Chunk " + m_chunkPos.ToString()); ChunkGO chunkGOScript = chunkGO.AddComponent <ChunkGO>(); chunkGOScript.loadedChunk = this; chunkGO.transform.position = m_chunkPos * NodeMapIndexToLocalCoord(m_chunkWidth - 1, m_chunkHeight - 1); chunkGO.AddComponent <MeshFilter>(); chunkGO.AddComponent <MeshRenderer>().sharedMaterial = Resources.Load <Material>("DirtMaterial"); chunkGO.AddComponent <MeshCollider>(); //Surface: GameObject chunkSurfaceGO = new GameObject("Surface"); chunkGOScript.surfaceGO = chunkSurfaceGO; chunkSurfaceGO.transform.SetParent(chunkGO.transform, false); chunkSurfaceGO.AddComponent <MeshFilter>(); chunkSurfaceGO.AddComponent <MeshCollider>(); chunkSurfaceGO.AddComponent <MeshRenderer>().sharedMaterial = Resources.Load <Material>("GrassMaterial"); //UpdateMeshComponent: chunkGOScript.UpdateMeshComponent(); return(chunkGO); }
public ChunkGO InstantiateGO(Transform t) { return(ChunkGO.InstantiateChunk(this, t)); }