public virtual IEnumerator MakeRoutine() { Terrain[] terrains = FindObjectsOfType <Terrain>(); for (int i = 0; i < terrains.Length; i++) { if (terrains[i].canBeErased && Contains(terrains[i])) { terrains[i].gameObject.SetActive(false); } } if (surroundWithTerrains) { Vector2 currentPoint; do { currentPoint = (Vector2)rootAreaPathNode.trs.position + (Random.insideUnitCircle.normalized * (rootAreaPathNode.radius + distToNodeForFirstTerrain)); yield return(new WaitForEndOfFrame()); } while (Contains(currentPoint)); yield return(EditorCoroutineUtility.StartCoroutine(MakeTerrainRoutine(currentPoint), this)); AreaPathNode[] uncheckedAreaPathNodes = new AreaPathNode[1] { rootAreaPathNode }; AreaPathNode[] deadEndAreaPathNodes = new AreaPathNode[0]; while (uncheckedAreaPathNodes.Length > 0) { if (uncheckedAreaPathNodes[0].gameObject.activeInHierarchy) { uncheckedAreaPathNodes = uncheckedAreaPathNodes.AddRange(uncheckedAreaPathNodes[0].children); if (uncheckedAreaPathNodes[0].children.Length == 0) { deadEndAreaPathNodes = deadEndAreaPathNodes.Add(uncheckedAreaPathNodes[0]); } } uncheckedAreaPathNodes = uncheckedAreaPathNodes.RemoveAt(0); } float normalizedTraversedDistance = 0; foreach (AreaPathNode deadEndAreaPathNode in deadEndAreaPathNodes) { do { currentPoint = GetPointAlongCenterPath(deadEndAreaPathNode, normalizedTraversedDistance + normalizedTraverseRate); DebugExtensions.DrawPoint(currentPoint, 10, Color.red, .1f); normalizedTraversedDistance = GetNormalizedDistanceOfClosestPointAlongCenterPath(deadEndAreaPathNode, currentPoint); yield return(new WaitForEndOfFrame()); } while (normalizedTraversedDistance < 1); } } }
public virtual void OnDrawGizmos() { Gizmos.matrix = Matrix4x4.identity; LineSegment2D[] _borders = new LineSegment2D[0]; AreaPathNode[] _areaPathNodes = new AreaPathNode[0]; AreaPathNode[] uncheckedAreaPathNodes = new AreaPathNode[1] { rootAreaPathNode }; LineSegment2D[] borderPair; while (uncheckedAreaPathNodes.Length > 0) { if (uncheckedAreaPathNodes[0] != null) { foreach (AreaPathNode childAreaPathNode in uncheckedAreaPathNodes[0].children) { if (childAreaPathNode != null && childAreaPathNode.gameObject.activeInHierarchy) { if (_areaPathNodes.Contains(childAreaPathNode)) { Debug.LogError("AreaPath " + name + " has a cycle"); return; } borderPair = GetBorders(uncheckedAreaPathNodes[0], childAreaPathNode); _borders = _borders.AddRange(borderPair); Gizmos.color = borderColor; Gizmos.DrawLine(borderPair[0].start, borderPair[0].end); Gizmos.DrawLine(borderPair[1].start, borderPair[1].end); Gizmos.color = nodeConnectorColor; Gizmos.DrawLine(uncheckedAreaPathNodes[0].trs.position, childAreaPathNode.trs.position); } } if (uncheckedAreaPathNodes[0].gameObject.activeInHierarchy) { uncheckedAreaPathNodes = uncheckedAreaPathNodes.AddRange(uncheckedAreaPathNodes[0].children); _areaPathNodes = _areaPathNodes.Add(uncheckedAreaPathNodes[0]); } } uncheckedAreaPathNodes = uncheckedAreaPathNodes.RemoveAt(0); } borders = _borders; areaPathNodes = _areaPathNodes; }