// Use this for initialization void Start() { time = Time.realtimeSinceStartup; objectsInArea = Physics.OverlapBox(size / 2, size / 2); //Physics.BoxCastAll (size / 2, size / 2, Vector3.zero); foreach (Collider hit in objectsInArea) { objs.Add(hit.transform.gameObject); } foreach (GameObject obj in objs) { MeshFilter temp = obj.GetComponent <MeshFilter> (); List <Vector3> tempVert = new List <Vector3>(); temp.mesh.GetVertices(tempVert); Vector3 pos; Vector3 objSize = obj.transform.lossyScale; Vector3 objPos = obj.transform.position; foreach (Vector3 vert in tempVert) { pos = new Vector3((vert.x * objSize.x) + objPos.x, (vert.y * objSize.y) + objPos.y, (vert.z * objSize.z) + objPos.z); vertexPoints.Add(pos); } } actualSize = size / radius; for (int a = 0; a < actualSize.x; a++) { for (int b = 0; b < actualSize.y; b++) { for (int c = 0; c < actualSize.z; c++) { gridSpace temp = new gridSpace(new Vector3(a, b, c) * radius, 0); if (c > 0) { areas [(int)((a * (actualSize.z * actualSize.y)) + (b * actualSize.z) + c - 1)].front = temp; temp.back = areas [(int)((a * (actualSize.z * actualSize.y)) + (b * actualSize.z) + c - 1)]; } if (b > 0) { areas [(int)((a * (actualSize.z * actualSize.y)) + ((b - 1) * actualSize.z) + c)].up = temp; temp.down = areas [(int)((a * (actualSize.z * actualSize.y)) + ((b - 1) * actualSize.z) + c)]; } if (a > 0) { areas [(int)(((a - 1) * (actualSize.z * actualSize.y)) + (b * actualSize.z) + c)].up = temp; temp.down = areas [(int)(((a - 1) * (actualSize.z * actualSize.y)) + (b * actualSize.z) + c)]; } areas.Add(temp); } } } //int i = 0; foreach (Vector3 vert in vertexPoints) { int x = Mathf.RoundToInt(vert.x / radius); int y = Mathf.RoundToInt(vert.y / radius); int z = Mathf.RoundToInt(vert.z / radius); areas [(int)((x * (actualSize.z * actualSize.y)) + (y * actualSize.z) + z)].area = 1; } done = true; }
public void SetTile(int x, int y, gridSpace type) { _grid[x, y] = type; }
public gridSpace(Vector3 _pos, int _area, gridSpace left, gridSpace back, gridSpace down) { pos = _pos; area = _area; }