public override string ToString() { if (Value == -1) { return(""); } var cellSetTypes = CellSets.Select(x => x.ToString()).ToList(); return($"{Value}: {string.Join(",", cellSetTypes)}"); }
IEnumerator Generate() { while (CompletedSet.Count < GridSize.x * GridSize.z) { FindNext(); yield return(null); } //Instantiate player, check all the cells for one-way paths and destroy example cell foreach (Transform t in GameObject.Find("Grid").GetComponentsInChildren <Transform>()) { if (t.childCount == 3 && !CellSets.ContainsKey(t.name)) { CellSets.Add(t.name, t); } } float maxDist = Mathf.Sqrt(Mathf.Pow(GridSize.x, 2) + Mathf.Pow(GridSize.z, 2)); foreach (Transform t in CellSets.Values) { string[] coords = t.name.Replace("(", "").Replace(")", "").Split(','); if (Random.value < Mathf.Sqrt(Mathf.Pow(float.Parse(coords[0]), 2) + Mathf.Pow(float.Parse(coords[2]), 2)) / maxDist) { finalPosition = t.transform.position; break; } } if (player != null) { GameObject p = (GameObject)Instantiate(player, Vector3.up, Quaternion.identity); p.name = "Player"; } GameObject f = new GameObject("Floors"); GameObject roof = GameObject.CreatePrimitive(PrimitiveType.Cube); roof.transform.parent = f.transform; roof.name = "Roof"; roof.transform.position = new Vector3(Buffer * GridSize.x / 2 - 1, CellPrefab.localScale.y * (GridSize.y + 1) * 2, Buffer * GridSize.z / 2 - 1); roof.transform.localScale = new Vector3(Buffer * GridSize.x, .1f, Buffer * GridSize.z); Destroy(CellPrefab.gameObject); GameObject fc = (GameObject)Instantiate(Resources.Load <GameObject>("Objects/Finish"), finalPosition + Vector3.up * .5f, Quaternion.identity); fc.name = "Finish"; generating = false; }