private void DrawPart(Building.Part part) { if (part.Renderer.sprite) { var snap = 1 / part.Renderer.sprite.pixelsPerUnit; var selectedBounds = HandleHelper.MoveHandle(part.Renderer.bounds.center, part.Bounds.size, new Vector2(snap, snap), Color.green, new Color(0.0f, 0.0f, 0.0f, 0.25f)); selectedBounds -= (Vector2)part.Renderer.bounds.extents; UpdatePartTransform(part, selectedBounds); } }
private void DrawBounds() { var bounds = _building.Bounds; var roofPosition = new Vector2(bounds.center.x, bounds.yMax - _building.RoofHeight); var size = HandleUtility.GetHandleSize(bounds.center) * 0.1f; HandleHelper.DrawLine(new Vector2(bounds.xMin, roofPosition.y), new Vector2(bounds.xMax, roofPosition.y), Color.cyan); var selectedBounds = HandleHelper.BoundsHandle(bounds, new Vector2(0.5f, 0.5f), Color.blue, Color.clear, Color.white, Color.white); var selectedRoofPosition = HandleHelper.MoveHandle(roofPosition, new Vector2(size * 2.5f, size), Vector2.one, Color.cyan, Color.cyan); UpdateMainTransforms(selectedBounds, _building.SortPoint, bounds.yMax - selectedRoofPosition.y, true); }
private void OnSceneGUI() { if (_pathController.Path.Nodes.Length > 0) { var lineColor = Color.cyan; var fillColor = new Color(0.0f, 1.0f, 1.0f, 0.2f); var mover = _pathController.GetComponent <Mover>(); var pathfinding = ComponentHelper.GetComponentInScene <Pathfinding>(_pathController.gameObject.scene.buildIndex, false); var transformPosition = _pathController.Path.UseAbsolutePositioning ? Vector2.zero : (Vector2)_pathController.transform.position; if (_pathController.Path.Nodes.Length > 2 && _pathController.Path.Type == Path.PathType.Loop) { var first = _pathController.Path.Nodes[0]; var last = _pathController.Path.Nodes[_pathController.Path.Nodes.Length - 1]; var firstPosition = GetPosition(first.Position, _pathController.transform.position, Mover.PositionOffset); var lastPosition = GetPosition(last.Position, transformPosition, Mover.PositionOffset); if (_pathController.Path.UsePathfinding && pathfinding) { var pathFrom = GetPathPosition(first.Position, _pathController.transform.position); var pathTo = GetPathPosition(last.Position, transformPosition); var path = pathfinding.GetPath(mover.MovementLayer, pathFrom, pathTo, false); if (path.Count > 1) { for (var n = 1; n < path.Count; n++) { var node = path[n]; var position = node + Mover.PositionOffset; HandleHelper.DrawLine(position, firstPosition, lineColor); firstPosition = position; } } } else { HandleHelper.DrawLine(lastPosition, firstPosition, lineColor); } } for (var i = 1; i < _pathController.Path.Nodes.Length; i++) { var previous = _pathController.Path.Nodes[i - 1]; var current = _pathController.Path.Nodes[i]; var previousPosition = GetPosition(previous.Position, i == 1 ? (Vector2)_pathController.transform.position : transformPosition, Mover.PositionOffset); var currentPosition = GetPosition(current.Position, transformPosition, Mover.PositionOffset); if (_pathController.Path.UsePathfinding && pathfinding) { var pathFrom = GetPathPosition(previous.Position, i == 1 ? (Vector2)_pathController.transform.position : transformPosition); var pathTo = GetPathPosition(current.Position, transformPosition); var path = pathfinding.GetPath(mover.MovementLayer, pathFrom, pathTo, false); if (path.Count > 1) { for (var n = 1; n < path.Count; n++) { var node = path[n]; var position = node + Mover.PositionOffset; HandleHelper.DrawLine(position, previousPosition, lineColor); previousPosition = position; } } } else { HandleHelper.DrawLine(currentPosition, previousPosition, Color.cyan); } } for (var i = 0; i < _pathController.Path.Nodes.Length; i++) { var node = _pathController.Path.Nodes[i]; var position = GetPosition(node.Position, i == 0 ? (Vector2)_pathController.transform.position : transformPosition, Mover.PositionOffset); var selectedPosition = HandleHelper.MoveHandle(position, Vector2.one, lineColor, fillColor, 0.25f); if (i != 0 && position != selectedPosition) { selectedPosition -= transformPosition; using (new UndoScope(_pathController, true)) _pathController.Path.Nodes[i].Position = Vector2Int.FloorToInt(selectedPosition); } if (node.Delay > 0 && node.Direction != MovementDirection.None) { HandleHelper.DrawArrow(selectedPosition, Direction.GetVector(node.Direction), 0.25f, Color.white); } HandleHelper.DrawText(new Vector2(selectedPosition.x, selectedPosition.y + 0.05f), i.ToString(), TextAnchor.MiddleCenter, Color.white); } } }