Guest User

Untitled

a guest
May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. [RequireComponent(typeof(MeshRenderer))]
  6.  
  7.  
  8. public class ChunkGenerator : MonoBehaviour
  9. {
  10. public int chunkX;
  11. public int chunkY;
  12. public int chunkZ;
  13. MeshFilter myMeshFilter;
  14. public Vector3[] verticies;
  15. private int arrayCounter = 0;
  16.  
  17. // Use this for initialization
  18. void Awake()
  19. {
  20.  
  21. myMeshFilter = this.gameObject.AddComponent<MeshFilter> ();
  22. myMeshFilter.mesh = new Mesh ();
  23. myMeshFilter.mesh = myMeshFilter.sharedMesh;
  24. verticies = new Vector3[3073];
  25.  
  26.  
  27. }
  28.  
  29. void Start ()
  30. {
  31. Debug.Log("Start Called");
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. }
  39.  
  40. void CreateMesh ()
  41. {
  42. Debug.Log("Create Mesh Called");
  43.  
  44.  
  45. myMeshFilter.mesh.vertices = verticies;
  46.  
  47. // //Create Verticies
  48. // Vector3 p0 = new Vector3 (0, 0, 0);
  49. // Vector3 p1 = new Vector3 (chunkX, 0, 0);
  50. // Vector3 p2 = new Vector3 (chunkX, 0, chunkZ);
  51. // Vector3 p3 = new Vector3 (0, 0, chunkZ);
  52. // Vector3 p4 = new Vector3 (0, chunkY, 0);
  53. // Vector3 p5 = new Vector3 (chunkX, chunkY, 0);
  54. // Vector3 p6 = new Vector3 (chunkX, chunkY, chunkZ);
  55. // Vector3 p7 = new Vector3 (0, chunkY, chunkZ);
  56. //
  57. // myMeshFilter.mesh.vertices = new Vector3[] { p0, p1, p2, p3, p4, p5, p6, p7 };
  58. //
  59. // //Bottom
  60. // //left
  61. // myMeshFilter.mesh.triangles = new int[] { 0, 1, 3, 3, 1, 2, 0, 5, 4, 5,
  62. // //back
  63. // 0, 1, 0, 3, 4, 3, 4, 7, 3, 6,
  64. // //right
  65. // //front
  66. // 7, 2, 3, 6, 2, 5, 6, 1, 5, 2,
  67. // //top
  68. // 4, 5, 7, 5, 7, 6 };
  69. // myMeshFilter.mesh.vertices
  70. // myMeshFilter.mesh.RecalculateNormals ();
  71. // myMeshFilter.mesh.RecalculateBounds ();
  72. // myMeshFilter.mesh.Optimize ();
  73. }
  74.  
  75. public void AddVerticies (int x, int y, int z)
  76. {
  77. Debug.Log("Add Verticies Called");
  78.  
  79. chunkX = x;
  80. chunkY = y;
  81. chunkZ = z;
  82.  
  83. start:
  84. for (int xCounter = 0; xCounter < chunkX; xCounter++) {
  85. for (int yCounter = 0; yCounter < chunkY; yCounter++) {
  86. for (int zCounter = 0; zCounter < chunkZ; zCounter++) {
  87.  
  88. if(xCounter == 0 && yCounter == 0 && zCounter == 0)
  89. {
  90. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  91. arrayCounter++;
  92. goto start;
  93. }
  94.  
  95. if (xCounter == 0 && yCounter == chunkY && zCounter == 0)
  96. {
  97. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  98. arrayCounter++;
  99. goto start;
  100. }
  101.  
  102. if(xCounter == chunkX && yCounter == 0 && zCounter == 0)
  103. {
  104. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  105. arrayCounter++;
  106. goto start;
  107. }
  108.  
  109. if(xCounter == chunkX && yCounter == chunkY && zCounter == 0)
  110. {
  111. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  112. arrayCounter++;
  113. goto start;
  114. }
  115.  
  116. if(xCounter == 0 && yCounter == 0 && zCounter == chunkZ)
  117. {
  118. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  119. arrayCounter++;
  120. goto start;
  121. }
  122.  
  123. if(xCounter == 0 && yCounter == chunkY && zCounter == chunkZ)
  124. {
  125. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  126. arrayCounter++;
  127. goto start;
  128. }
  129.  
  130. if(xCounter == chunkX && yCounter == 0 && zCounter == chunkZ)
  131. {
  132. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  133. arrayCounter++;
  134. goto start;
  135. }
  136.  
  137. if(xCounter == chunkX && yCounter == chunkY && zCounter == chunkZ)
  138. {
  139. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  140. arrayCounter++;
  141. goto start;
  142. }
  143.  
  144. if(xCounter == 0)
  145. {
  146. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  147. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  148. arrayCounter++;
  149. }
  150.  
  151. if(xCounter == chunkX)
  152. {
  153. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  154. arrayCounter++;
  155. }
  156. if(yCounter == 0)
  157. {
  158. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  159. arrayCounter++;
  160. }
  161.  
  162. if(yCounter == chunkY)
  163. {
  164. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  165. arrayCounter++;
  166. }
  167. if(zCounter == 0)
  168. {
  169. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  170. arrayCounter++;
  171. }
  172.  
  173. if(zCounter == chunkZ)
  174. {
  175. verticies[arrayCounter] = new Vector3(xCounter, yCounter, zCounter);
  176. arrayCounter++;
  177. }
  178.  
  179. }
  180. }
  181.  
  182. }
  183. CreateMesh();
  184.  
  185. }
  186.  
  187. // Update is called once per frame
  188. void Update ()
  189. {
  190.  
  191. }
  192. }
Add Comment
Please, Sign In to add comment