TO SQUASH: Wall thickness.
This commit is contained in:
@@ -2960,6 +2960,9 @@ MonoBehaviour:
|
|||||||
player: {fileID: 1002905792}
|
player: {fileID: 1002905792}
|
||||||
gameBoardSpriteRenderer: {fileID: 297740151}
|
gameBoardSpriteRenderer: {fileID: 297740151}
|
||||||
wallPrefab: {fileID: 2746972694419659216, guid: 3fbc857440f3c649b9d49d40955db450, type: 3}
|
wallPrefab: {fileID: 2746972694419659216, guid: 3fbc857440f3c649b9d49d40955db450, type: 3}
|
||||||
|
fallbackBarThicknessWorldUnits: 0.08
|
||||||
|
geometryEpsilon: 0.0001
|
||||||
|
wallPaddingPixelsPerSide: 2
|
||||||
--- !u!1001 &2090615130
|
--- !u!1001 &2090615130
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ public class WorldFiller : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float geometryEpsilon = 0.0001f;
|
private float geometryEpsilon = 0.0001f;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private float wallPaddingPixelsPerSide = 1.0f;
|
||||||
|
|
||||||
private Bounds gameBoardBounds;
|
private Bounds gameBoardBounds;
|
||||||
|
|
||||||
private Vector2?[] wallPositions;
|
private Vector2?[] wallPositions;
|
||||||
@@ -162,10 +165,20 @@ public class WorldFiller : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyWallTransform(wall.transform, wallRenderer, clampedWallRect);
|
Rect boardRect = Rect.MinMaxRect(
|
||||||
|
gameBoardBounds.min.x,
|
||||||
|
gameBoardBounds.min.y,
|
||||||
|
gameBoardBounds.max.x,
|
||||||
|
gameBoardBounds.max.y
|
||||||
|
);
|
||||||
|
|
||||||
|
float wallPaddingWorldUnits = PixelsToWorldUnits(wallPaddingPixelsPerSide, wallRenderer);
|
||||||
|
Rect paddedWallRect = ExpandRectInsideBounds(clampedWallRect, wallPaddingWorldUnits, boardRect);
|
||||||
|
|
||||||
|
ApplyWallTransform(wall.transform, wallRenderer, paddedWallRect);
|
||||||
var wallBounds = wallRenderer.bounds;
|
var wallBounds = wallRenderer.bounds;
|
||||||
|
|
||||||
UpdateFreeAreas(clampedWallRect);
|
UpdateFreeAreas(paddedWallRect);
|
||||||
|
|
||||||
// Check if there are yummies, multipliers or the shark intersecting the spawned wall.
|
// Check if there are yummies, multipliers or the shark intersecting the spawned wall.
|
||||||
// Yummies and multipliers are awarded to the player if they are intersected by the wall.
|
// Yummies and multipliers are awarded to the player if they are intersected by the wall.
|
||||||
@@ -226,7 +239,7 @@ public class WorldFiller : MonoBehaviour
|
|||||||
|
|
||||||
// Let the player know that the wall has been spawned.
|
// Let the player know that the wall has been spawned.
|
||||||
int areaPercentage = boardArea > geometryEpsilon
|
int areaPercentage = boardArea > geometryEpsilon
|
||||||
? Mathf.RoundToInt((clampedWallRect.width * clampedWallRect.height / boardArea) * 100.0f)
|
? Mathf.RoundToInt((paddedWallRect.width * paddedWallRect.height / boardArea) * 100.0f)
|
||||||
: 0;
|
: 0;
|
||||||
player.OnWallSpawned(areaPercentage);
|
player.OnWallSpawned(areaPercentage);
|
||||||
|
|
||||||
@@ -491,4 +504,42 @@ public class WorldFiller : MonoBehaviour
|
|||||||
&& point.y >= rect.yMin - geometryEpsilon
|
&& point.y >= rect.yMin - geometryEpsilon
|
||||||
&& point.y <= rect.yMax + geometryEpsilon;
|
&& point.y <= rect.yMax + geometryEpsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float PixelsToWorldUnits(float pixels, SpriteRenderer referenceRenderer)
|
||||||
|
{
|
||||||
|
float pixelsPerUnit = 100.0f;
|
||||||
|
|
||||||
|
if (referenceRenderer != null && referenceRenderer.sprite != null && referenceRenderer.sprite.pixelsPerUnit > 0.0f)
|
||||||
|
{
|
||||||
|
pixelsPerUnit = referenceRenderer.sprite.pixelsPerUnit;
|
||||||
|
}
|
||||||
|
else if (gameBoardSpriteRenderer != null && gameBoardSpriteRenderer.sprite != null && gameBoardSpriteRenderer.sprite.pixelsPerUnit > 0.0f)
|
||||||
|
{
|
||||||
|
pixelsPerUnit = gameBoardSpriteRenderer.sprite.pixelsPerUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixels / pixelsPerUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rect ExpandRectInsideBounds(Rect rect, float padding, Rect boundsRect)
|
||||||
|
{
|
||||||
|
if (padding <= geometryEpsilon)
|
||||||
|
{
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect expanded = Rect.MinMaxRect(
|
||||||
|
rect.xMin - padding,
|
||||||
|
rect.yMin - padding,
|
||||||
|
rect.xMax + padding,
|
||||||
|
rect.yMax + padding
|
||||||
|
);
|
||||||
|
|
||||||
|
if (TryGetRectIntersection(expanded, boundsRect, out Rect clampedExpanded))
|
||||||
|
{
|
||||||
|
return clampedExpanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user