Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- [RequireComponent(typeof(MeshRenderer))]
- public class ChunkGenerator : MonoBehaviour
- {
- public int chunkX;
- public int chunkY;
- public int chunkZ;
- MeshFilter myMeshFilter;
- public Vector3[] verticies;
- private int arrayCounter = 0;
- // Use this for initialization
- void Awake()
- {
- myMeshFilter = this.gameObject.AddComponent<MeshFilter> ();
- myMeshFilter.mesh = new Mesh ();
- myMeshFilter.mesh = myMeshFilter.sharedMesh;
- verticies = new Vector3[3073];
- }
- void Start ()
- {
- Debug.Log("Start Called");
- }
- void CreateMesh ()
- {
- Debug.Log("Create Mesh Called");
- myMeshFilter.mesh.vertices = verticies;
- // //Create Verticies
- // Vector3 p0 = new Vector3 (0, 0, 0);
- // Vector3 p1 = new Vector3 (chunkX, 0, 0);
- // Vector3 p2 = new Vector3 (chunkX, 0, chunkZ);
- // Vector3 p3 = new Vector3 (0, 0, chunkZ);
- // Vector3 p4 = new Vector3 (0, chunkY, 0);
- // Vector3 p5 = new Vector3 (chunkX, chunkY, 0);
- // Vector3 p6 = new Vector3 (chunkX, chunkY, chunkZ);
- // Vector3 p7 = new Vector3 (0, chunkY, chunkZ);
- //
- // myMeshFilter.mesh.vertices = new Vector3[] { p0, p1, p2, p3, p4, p5, p6, p7 };
- //
- // //Bottom
- // //left
- // myMeshFilter.mesh.triangles = new int[] { 0, 1, 3, 3, 1, 2, 0, 5, 4, 5,
- // //back
- // 0, 1, 0, 3, 4, 3, 4, 7, 3, 6,
- // //right
- // //front
- // 7, 2, 3, 6, 2, 5, 6, 1, 5, 2,
- // //top
- // 4, 5, 7, 5, 7, 6 };
- // myMeshFilter.mesh.vertices
- // myMeshFilter.mesh.RecalculateNormals ();
- // myMeshFilter.mesh.RecalculateBounds ();
- // myMeshFilter.mesh.Optimize ();
- }
- public void AddVerticies (int x, int y, int z)
- {
- Debug.Log("Add Verticies Called");
- chunkX = x;
- chunkY = y;
- chunkZ = z;
- start:
- for (int xCounter = 0; xCounter < chunkX; xCounter++) {
- for (int yCounter = 0; yCounter < chunkY; yCounter++) {
- for (int zCounter = 0; zCounter < chunkZ; zCounter++) {
- if(xCounter == 0 && yCounter == 0 && zCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if (xCounter == 0 && yCounter == chunkY && zCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == chunkX && yCounter == 0 && zCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == chunkX && yCounter == chunkY && zCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == 0 && yCounter == 0 && zCounter == chunkZ)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == 0 && yCounter == chunkY && zCounter == chunkZ)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == chunkX && yCounter == 0 && zCounter == chunkZ)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == chunkX && yCounter == chunkY && zCounter == chunkZ)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- goto start;
- }
- if(xCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- }
- if(xCounter == chunkX)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- }
- if(yCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- }
- if(yCounter == chunkY)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- }
- if(zCounter == 0)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- }
- if(zCounter == chunkZ)
- {
- verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
- arrayCounter++;
- }
- }
- }
- }
- CreateMesh();
- }
- // Update is called once per frame
- void Update ()
- {
- }
- }
Add Comment
Please, Sign In to add comment