public void Render(JunkyardViewModel viewModel, Bot bot) { _viewModel = viewModel; _junkyard = viewModel.junkyard; if (!JunkyardUtils.HideGround) { RenderGround(_junkyard); } _fogOfWarView.Render(viewModel); _junkyardJunkMonoView.Render(viewModel, renderConfig); _fogOfWarViewBottom.Render(viewModel); _camera.XMax = _junkyard.Width; _camera.ZMax = _junkyard.Height; _camera.XMin = 0; _camera.ZMin = 0; _camAgent.transform.position = new Vector3(_junkyard.X, _camAgent.transform.position.y, _junkyard.Y); Game.Instance.GetViewModel <CameraViewModel>(0).Focus(_camAgent); _border.Render(renderConfig, _junkyard); _botAnimation.Setup(renderConfig, _junkyard, bot, this); _junkyardJunkMonoView.OnJunkCleared += HandleJunkCleared; _junkyardJunkMonoView.OnJunkPointerDown += HandleJunkPointerDown; }
private void SetTriangles(Junkyard junkyard, int x, int y, int[] triangles, List <Vector3> vectorTriangles) { //we are making 2 triangles per loop. so offset goes up by 6 each time int triangleOffset = (x * junkyard.Height + y) * 6; int verticeX = junkyard.Width + 1; int verticeY = junkyard.Height + 1; //triangle 1 triangles[triangleOffset] = x * verticeY + y; triangles[1 + triangleOffset] = x * verticeY + y + 1; triangles[2 + triangleOffset] = x * verticeY + y + verticeY; vectorTriangles.Add(new Vector3(triangles[triangleOffset], triangles[1 + triangleOffset], triangles[2 + triangleOffset])); //triangle 2 triangles[3 + triangleOffset] = x * verticeY + y + verticeY; triangles[4 + triangleOffset] = x * verticeY + y + 1; triangles[5 + triangleOffset] = x * verticeY + y + verticeY + 1; vectorTriangles.Add(new Vector3(triangles[3 + triangleOffset], triangles[4 + triangleOffset], triangles[5 + triangleOffset])); }
private void RenderGround(Junkyard junkyard) { MeshFilter meshFilter; if (_renderingPlane == null) { _renderingPlane = Instantiate(new GameObject("Ground"), transform); _renderingPlane.transform.position = Vector3.zero; _renderingPlane.AddComponent <MeshRenderer>(); _renderingPlane.AddComponent <MeshFilter>(); meshFilter = _renderingPlane.GetComponent <MeshFilter>(); meshFilter.mesh = new Mesh(); //DestroyImmediate(planePrimitive); } GameObject plane = _renderingPlane; plane.GetComponent <Renderer>().material = renderConfig.GroundMaterial; meshFilter = plane.GetComponent <MeshFilter>(); Mesh mesh = meshFilter.sharedMesh; int verticiesLength = (junkyard.Width + 1) * (junkyard.Height + 1); Vector3[] vertices = new Vector3[verticiesLength]; Color[] colors = new Color[vertices.Length]; Vector2[] uvs = new Vector2[vertices.Length]; Vector3[] normals = new Vector3[vertices.Length]; float[] grass = new float[vertices.Length]; // Vector2[] triangles = new Vector2[(int)(dimensions.Area * 2)]; //for every point, there is 2 triangles, equaling 6 total vertices int[] triangles = new int[(int)((junkyard.Width * junkyard.Height) * 6)]; float totalWidth = junkyard.Width * _scale; float totalHeight = junkyard.Height * _scale; //Create Vertices for (int x = 0; x < junkyard.Width + 1; x++) { for (int y = 0; y < junkyard.Height + 1; y++) { int position = (x * (junkyard.Width + 1)) + y; vertices[position] = new Vector3(x * _scale, junkyard.GetNormalizedHeight(x, y), y * _scale); colors[position] = new Color(0.5f, 0.5f, 0.5f); //uvs[position] = new Vector2((float)x / (float)junkyard.Width, (float)y / (float)junkyard.Height); uvs[position] = new Vector2((float)x, (float)y); normals[position] = Vector3.up; grass[position] = 0.5f; } } List <Vector3> vectorTriangles = new List <Vector3>(); //Create Triangles for (int x = 0; x < junkyard.Width; x++) { for (int y = 0; y < junkyard.Height; y++) { SetTriangles(junkyard, x, y, triangles, vectorTriangles); } } mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.uv = uvs; mesh.colors = colors; mesh.normals = normals; plane.SetActive(true); mesh.RecalculateNormals(); mesh.RecalculateBounds(); mesh.RecalculateTangents(); }