Added building flipping
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Fruitomation.Game
|
|||||||
private bool[,] InhabitedCells { get; } = new bool[96, 49];
|
private bool[,] InhabitedCells { get; } = new bool[96, 49];
|
||||||
private List<BuildingInfo> Buildings { get; } = new();
|
private List<BuildingInfo> Buildings { get; } = new();
|
||||||
|
|
||||||
public bool AddBuildingAt(Vector2Int position, GameObject prefab, bool updateCellMap = false)
|
public bool AddBuildingAt(Vector2Int position, GameObject prefab, bool isFlipped)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
GameObject go = Instantiate(prefab, transform);
|
GameObject go = Instantiate(prefab, transform);
|
||||||
@@ -41,6 +41,8 @@ namespace Fruitomation.Game
|
|||||||
info.Rect.sizeDelta = info.Building.SizeOnGrid * 40;
|
info.Rect.sizeDelta = info.Building.SizeOnGrid * 40;
|
||||||
info.Rect.anchoredPosition = p1 + off1;
|
info.Rect.anchoredPosition = p1 + off1;
|
||||||
|
|
||||||
|
info.Rect.transform.localScale = new Vector3(isFlipped ? -1f : 1f, 1f, 1f);
|
||||||
|
|
||||||
Debug.Log(g0);
|
Debug.Log(g0);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace Fruitomation.Game
|
|||||||
{
|
{
|
||||||
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
|
if (other.transform.parent.TryGetComponent(out Rigidbody2D body))
|
||||||
{
|
{
|
||||||
body?.AddForce(-transform.right * Mathf.PI, ForceMode2D.Impulse);
|
Vector3 force = new(-transform.localScale.x, 0f, 0f);
|
||||||
|
body?.AddForce(force * Mathf.PI, ForceMode2D.Impulse);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace Fruitomation.UI
|
|||||||
[SerializeField, InspectorReadOnly] private float CurrentMouseClickStrength;
|
[SerializeField, InspectorReadOnly] private float CurrentMouseClickStrength;
|
||||||
[SerializeField, InspectorReadOnly] private Vector2Int GridPosition;
|
[SerializeField, InspectorReadOnly] private Vector2Int GridPosition;
|
||||||
[SerializeField, InspectorReadOnly] private GameObject SelectedBuildingToBuild;
|
[SerializeField, InspectorReadOnly] private GameObject SelectedBuildingToBuild;
|
||||||
|
[SerializeField, InspectorReadOnly] private bool FlipCurrentBuilding;
|
||||||
|
|
||||||
private readonly ContactFilter2D ContactFilter = new();
|
private readonly ContactFilter2D ContactFilter = new();
|
||||||
private readonly List<Collider2D> Colliders = new();
|
private readonly List<Collider2D> Colliders = new();
|
||||||
@@ -38,6 +39,8 @@ namespace Fruitomation.UI
|
|||||||
{
|
{
|
||||||
SelectedBuildingsBuildingBase = prefab.GetComponent<Building>();
|
SelectedBuildingsBuildingBase = prefab.GetComponent<Building>();
|
||||||
SelectedBuildingToBuild = prefab;
|
SelectedBuildingToBuild = prefab;
|
||||||
|
|
||||||
|
FlipCurrentBuilding = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePosition()
|
private void UpdatePosition()
|
||||||
@@ -145,6 +148,15 @@ namespace Fruitomation.UI
|
|||||||
{
|
{
|
||||||
BuildingPreview.enabled = true;
|
BuildingPreview.enabled = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (Input.GetKeyDown(KeyCode.R))
|
||||||
|
{
|
||||||
|
FlipCurrentBuilding = !FlipCurrentBuilding;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
BuildingPreview.transform.localScale = new Vector3(FlipCurrentBuilding ? -1f : 1f, 1f, 1f);
|
||||||
BuildingPreview.rectTransform.sizeDelta = SelectedBuildingsBuildingBase.SizeOnGrid * 40;
|
BuildingPreview.rectTransform.sizeDelta = SelectedBuildingsBuildingBase.SizeOnGrid * 40;
|
||||||
BuildingPreview.sprite = SelectedBuildingsBuildingBase.Sprite;
|
BuildingPreview.sprite = SelectedBuildingsBuildingBase.Sprite;
|
||||||
|
|
||||||
@@ -166,7 +178,7 @@ namespace Fruitomation.UI
|
|||||||
//
|
//
|
||||||
if (Input.GetMouseButtonDown(0) && MouseOnGrid)
|
if (Input.GetMouseButtonDown(0) && MouseOnGrid)
|
||||||
{
|
{
|
||||||
BuildingManager.AddBuildingAt(p1, SelectedBuildingToBuild);
|
BuildingManager.AddBuildingAt(p1, SelectedBuildingToBuild, FlipCurrentBuilding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user