public virtual void PlaceWorldTile(Vector3 _placePosition) { _grid.GetXY(_placePosition, out int x, out int z); Vector2Int _placedObjectOrigin = new Vector2Int(x, z); List <Vector2Int> gridPositionList = placedWorldTileTypeSO.GetGridPositionList(_placedObjectOrigin, dir); bool canBuild = true; foreach (Vector2Int gridPosition in gridPositionList) { if (!_grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild()) { canBuild = false; break; } } if (canBuild) { Vector2Int rotationOffset = placedWorldTileTypeSO.GetRotationOffset(dir); Vector3 placedObjectWorldPosition = _grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, rotationOffset.y) * _grid.GetCellSize(); PlacedObject_WorldTile placedObject = PlacedObject_WorldTile.Create(WorldTileParent, StartingAspects, placedObjectWorldPosition, _placedObjectOrigin, dir, placedWorldTileTypeSO); placedObject.transform.rotation = Quaternion.Euler(0, 0, -placedWorldTileTypeSO.GetRotationAngle(dir)); foreach (Vector2Int gridPosition in gridPositionList) { _grid.GetGridObject(gridPosition.x, gridPosition.y).SetPlacedObject(placedObject); } //OnObjectPlaced?.Invoke(this, EventArgs.Empty); //DeselectObjectType(); } else { // Cannot build here UtilsClass.CreateWorldTextPopup("Cannot Build Here!", _placePosition); } }
public static PlacedObject_WorldTile Create(Transform _worldTileParent, List <TileAspect> _startingAspects, Vector3 worldPosition, Vector2Int origin, PlacedWorldTileTypeSO.Dir dir, PlacedWorldTileTypeSO _placedWorldTileTypeSO) { Transform placedObjectTransform = Instantiate(_placedWorldTileTypeSO.prefab, worldPosition, Quaternion.Euler(0, _placedWorldTileTypeSO.GetRotationAngle(dir), 0), _worldTileParent); PlacedObject_WorldTile placedObject = placedObjectTransform.GetComponent <PlacedObject_WorldTile>(); placedObject.SetupTile(_placedWorldTileTypeSO, origin, dir); placedObject.SetTileAspects(_startingAspects); return(placedObject); }