public static Rect GetBoundsRect() { List <Rect> levelBoundRectsInstances = new List <Rect>(); foreach (Renderer renderer in FindObjectsOfType <Renderer>()) { if (renderer.GetComponent <OmitFromLevelMap>() == null) { levelBoundRectsInstances.Add(renderer.bounds.ToRect()); } } return(RectExtensions.Combine(levelBoundRectsInstances.ToArray())); }
public virtual void Start() { Canvas.ForceUpdateCanvases(); RectTransform[] children = GetComponentsInChildren <RectTransform>(); children = children.Remove(combinedRectTrs); Rect[] graphicRects = new Rect[children.Length]; for (int i = 0; i < children.Length; i++) { graphicRects[i] = children[i].GetRectInCanvasNormalized(canvasRectTrs); } Rect combinedRect = RectExtensions.Combine(graphicRects); Vector2 combinedRectCenter; combinedRectCenter = combinedRect.center; combinedRect.size = combinedRect.size.Multiply(canvasRectTrs.sizeDelta); combinedRect.center = combinedRectCenter.Multiply(canvasRectTrs.sizeDelta); combinedRectTrs.sizeDelta = combinedRect.size; rectTrs = combinedRectTrs; }
static void MakeSafeAreas() { GameObject[] gos = FindObjectsOfType <GameObject>(); List <Vector2> allPositions = new List <Vector2>(); List <Vector2> safeZonePositions = new List <Vector2>(); List <Vector3Int> _unexploredPositions = new List <Vector3Int>(); Vector3Int[] unexploredPositions = new Vector3Int[0]; List <SafeArea> safeAreas = new List <SafeArea>(); foreach (Vector3Int cellPosition in GameManager.GetSingleton <GameManager>().zonesTilemap.cellBounds.allPositionsWithin) { _unexploredPositions.Add(cellPosition); Vector2 position = GameManager.GetSingleton <GameManager>().zonesTilemap.GetCellCenterWorld(cellPosition); if (!ContainsPoint(safeZonePositions, position, .7f) && !ContainsPoint(allPositions, position, .7f)) { allPositions.Add(position); SafeZone safeZone; if (GetComponent <SafeZone>(gos, position, out safeZone, .7f)) { SafeArea safeArea = new GameObject().AddComponent <SafeArea>(); safeArea.GetComponent <Transform>().SetParent(GameManager.GetSingleton <World>().piecesParent); safeZone.safeArea = safeArea; List <Vector2> safeAreaPositions = new List <Vector2>(); safeAreaPositions.Add(position); List <Vector2> positionsRemaining = new List <Vector2>(); List <Vector2> positionsTested = new List <Vector2>(); positionsTested.Add(position); List <DangerArea> dangerAreas = new List <DangerArea>(); List <ConveyorBelt> conveyorBelts = new List <ConveyorBelt>(); ConveyorBelt conveyorBelt; if (GetComponent <ConveyorBelt>(gos, position, out conveyorBelt, .7f)) { conveyorBelts.Add(conveyorBelt); } foreach (Vector2 possibleMove in GameManager.GetSingleton <GameManager>().possibleMoves) { positionsRemaining.Add(position + possibleMove); } do { position = positionsRemaining[0]; if (GetComponent <SafeZone>(gos, position, out safeZone, .7f)) { safeZone.safeArea = safeArea; foreach (Vector2 possibleMove in GameManager.GetSingleton <GameManager>().possibleMoves) { Vector2 positionToTest = position + possibleMove; if (!ContainsPoint(positionsRemaining, positionToTest, .7f) && !ContainsPoint(positionsTested, positionToTest, .7f)) { positionsRemaining.Add(positionToTest); } } safeAreaPositions.Add(position); } else { DangerZone dangerZone; if (GetComponent <DangerZone>(gos, position, out dangerZone, .7f)) { DangerArea dangerArea = dangerZone.dangerArea; dangerAreas.Add(dangerArea); if (!safeArea.surroundingSafeAreas.Contains(dangerArea.correspondingSafeArea)) { safeArea.surroundingSafeAreas.Add(dangerArea.correspondingSafeArea); } if (!dangerArea.correspondingSafeArea.surroundingSafeAreas.Contains(safeArea)) { dangerArea.correspondingSafeArea.surroundingSafeAreas.Add(safeArea); } } } if (GetComponent <ConveyorBelt>(gos, position, out conveyorBelt, .7f)) { conveyorBelts.Add(conveyorBelt); } positionsTested.Add(position); allPositions.Add(position); positionsRemaining.RemoveAt(0); } while (positionsRemaining.Count > 0); safeZonePositions.AddRange(safeAreaPositions); safeArea.cameraRect = RectExtensions.FromPoints(safeAreaPositions.ToArray()).Expand(Vector2.one * GameManager.WORLD_SCALE * 4); Rect[] dangerAreaCameraRects = new Rect[dangerAreas.Count]; for (int i = 0; i < dangerAreas.Count; i++) { dangerAreaCameraRects[i] = dangerAreas[i].cameraRect; } safeArea.cameraRect = RectExtensions.Combine(dangerAreaCameraRects.Add(safeArea.cameraRect)); safeArea.conveyorBelts = conveyorBelts.ToArray(); safeAreas.Add(safeArea); } } } unexploredPositions = _unexploredPositions.ToArray(); for (int i = 0; i < safeAreas.Count; i++) { safeAreas[i].unexploredCellPositions = unexploredPositions; } }