public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { GridCoordinates coordinates = new GridCoordinates( property.FindPropertyRelative("x").intValue, property.FindPropertyRelative("z").intValue ); position = EditorGUI.PrefixLabel(position, label); GUI.Label(position, coordinates.ToString()); }
public void CreateMesh(GridCoordinates gridCoordinates, List <int> dictionaryTriangles) { GameObject newObject = new GameObject { name = "SubMesh " + gridCoordinates }; newObject.transform.SetParent(transform); newObject.transform.localPosition = Vector3.zero; newObject.transform.localScale = Vector3.one; newObject.transform.localRotation = transform.localRotation; newObject.AddComponent <MeshFilter>(); newObject.AddComponent <MeshRenderer>(); MeshRenderer newRenderer = newObject.GetComponent <MeshRenderer>(); newRenderer.sharedMaterial = GetComponent <MeshRenderer>().sharedMaterial; // sorting order and layer name of the generated mesh renderer if (!useSortingLayerFromThisMesh) { newRenderer.sortingLayerName = renderLayerName; newRenderer.sortingOrder = renderLayerIndex; } else if (baseRenderer) { newRenderer.sortingLayerName = baseRenderer.sortingLayerName; newRenderer.sortingOrder = baseRenderer.sortingOrder; } // should the submesh also be static if the base object is static? if (useStaticSettingsFromThisMesh) { newObject.isStatic = gameObject.isStatic; } List <Vector3> verts = new List <Vector3>(); List <int> tris = new List <int>(); List <Vector2> uvs = new List <Vector2>(); List <Vector3> normals = new List <Vector3>(); for (int i = 0; i < dictionaryTriangles.Count; i += 3) { verts.Add(baseVerticles[dictionaryTriangles[i]]); verts.Add(baseVerticles[dictionaryTriangles[i + 1]]); verts.Add(baseVerticles[dictionaryTriangles[i + 2]]); tris.Add(i); tris.Add(i + 1); tris.Add(i + 2); // uvs.Add(baseUvs[dictionaryTriangles[i]]); //uvs.Add(baseUvs[dictionaryTriangles[i + 1]]); // uvs.Add(baseUvs[dictionaryTriangles[i + 2]]); //normals.Add(baseNormals[dictionaryTriangles[i]]); //normals.Add(baseNormals[dictionaryTriangles[i + 1]]); //normals.Add(baseNormals[dictionaryTriangles[i + 2]]); } // add the newly created object to the list of children (submeshes) childen.Add(newObject); // Create a new mesh ... Mesh m = new Mesh { name = gridCoordinates.ToString(), // fill it with data from our lists ... vertices = verts.ToArray(), triangles = tris.ToArray(), uv = uvs.ToArray(), normals = normals.ToArray() }; UnityEditor.MeshUtility.Optimize(m); // assign the new mesh to this submeshes mesh filter. MeshFilter newMeshFilter = newObject.GetComponent <MeshFilter>(); newMeshFilter.mesh = m; }
public Block GetBlock(GridCoordinates coordinates) { if (coordinates == null) { return(null); } if (coordinates.OutOfBounds(this)) { Debug.LogError("Tried to get block that is out of grid bounds:\n Width: " + Width + "\t Length: " + Length + "\n\t coords: " + coordinates.ToString()); return(null); } return(array[coordinates.x, coordinates.y]); }
public override string ToString() { return(type.ToString() + " - " + coordinates.ToString()); }