chore: clean up Debug.Log

This commit is contained in:
Théo LUDWIG 2025-05-17 20:32:43 +02:00
parent 8caca60647
commit c38eecfbda
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
2 changed files with 6 additions and 46 deletions

View File

@ -166,7 +166,6 @@ public class LevelEditor : MonoBehaviour
{ {
if (!IsPlacementValid()) if (!IsPlacementValid())
{ {
Debug.Log("Placement invalide : collision.");
return; return;
} }
PlaceBlock(); PlaceBlock();
@ -201,7 +200,6 @@ public class LevelEditor : MonoBehaviour
currentBlock = sel; currentBlock = sel;
isPlacingBlock = true; isPlacingBlock = true;
currentScale = currentBlock.transform.localScale; currentScale = currentBlock.transform.localScale;
Debug.Log($"Sélection : {sel.name}");
} }
} }
void PlaceBlock() void PlaceBlock()
@ -211,7 +209,6 @@ public class LevelEditor : MonoBehaviour
if (isSpikeType) if (isSpikeType)
{ {
// 1) Bloquer si on perçoit un spike de même type dans la direction de snap
if (IsBlockedBySameTypeInSnapDirection()) if (IsBlockedBySameTypeInSnapDirection())
{ {
Debug.LogError("Impossible de poser un spike sur un autre spike !"); Debug.LogError("Impossible de poser un spike sur un autre spike !");
@ -219,7 +216,6 @@ public class LevelEditor : MonoBehaviour
} }
else else
{ {
// 2) On snap dans la direction (down/left/up/right), et on détruit si aucun support
if (!SnapSpikeByRotation()) if (!SnapSpikeByRotation())
{ {
Debug.LogError("Impossible de poser un spike dans le vide !"); Debug.LogError("Impossible de poser un spike dans le vide !");
@ -227,14 +223,12 @@ public class LevelEditor : MonoBehaviour
} }
else else
{ {
// 3) On fait lajustement fin (si besoin)
TrySnapToNearbyBlock(); TrySnapToNearbyBlock();
} }
} }
} }
else else
{ {
// tous les autres blocs
TrySnapToNearbyBlock(); TrySnapToNearbyBlock();
} }
@ -242,16 +236,11 @@ public class LevelEditor : MonoBehaviour
currentBlock = null; currentBlock = null;
} }
/// <summary>
/// Vérifie quil ny ait pas déjà un spike/smallspike/killzone
/// juste devant le spike selon sa rotation.
/// </summary>
bool IsBlockedBySameTypeInSnapDirection() bool IsBlockedBySameTypeInSnapDirection()
{ {
var col = currentBlock.GetComponent<Collider2D>(); var col = currentBlock.GetComponent<Collider2D>();
var b = col.bounds; var b = col.bounds;
// 1) Détermine direction de snap (0→down,1→left,2→up,3→right)
int rot = (Mathf.RoundToInt(currentBlock.transform.eulerAngles.z / 90) % 4 + 4) % 4; int rot = (Mathf.RoundToInt(currentBlock.transform.eulerAngles.z / 90) % 4 + 4) % 4;
Vector2 dir = rot switch Vector2 dir = rot switch
{ {
@ -261,17 +250,15 @@ public class LevelEditor : MonoBehaviour
_ => Vector2.down _ => Vector2.down
}; };
// 2) Origine : on place la « boîte » juste en bordure du sprite
float offset = 0.01f; float offset = 0.01f;
Vector2 origin = rot switch Vector2 origin = rot switch
{ {
1 => new Vector2(b.min.x - offset, b.center.y), // gauche 1 => new Vector2(b.min.x - offset, b.center.y), // left
3 => new Vector2(b.max.x + offset, b.center.y), // droite 3 => new Vector2(b.max.x + offset, b.center.y), // right
2 => new Vector2(b.center.x, b.max.y + offset), // haut 2 => new Vector2(b.center.x, b.max.y + offset), // top
_ => new Vector2(b.center.x, b.min.y - offset) // bas _ => new Vector2(b.center.x, b.min.y - offset) // bottom
}; };
// 3) On boxcast exactement la taille du sprite pour 100 unités
RaycastHit2D[] hits = Physics2D.BoxCastAll( RaycastHit2D[] hits = Physics2D.BoxCastAll(
origin, origin,
b.size, b.size,
@ -293,11 +280,9 @@ public class LevelEditor : MonoBehaviour
if (meIsSpikeFamily && otherIsSpikeFamily) if (meIsSpikeFamily && otherIsSpikeFamily)
{ {
// on bloque absolument tout chevauchement entre ces trois types
return true; return true;
} }
// si on tape autre chose (sol, block, bonus…), on arrête le scan
break; break;
} }
@ -306,13 +291,11 @@ public class LevelEditor : MonoBehaviour
bool SnapSpikeByRotation() bool SnapSpikeByRotation()
{ {
// Récupère bounds et demi-tailles
var col = currentBlock.GetComponent<Collider2D>(); var col = currentBlock.GetComponent<Collider2D>();
var b = col.bounds; var b = col.bounds;
float hw = b.extents.x; float hw = b.extents.x;
float hh = b.extents.y; float hh = b.extents.y;
// 1) Détermine la rotation en quarts de tour : 0→down, 1→left, 2→up, 3→right
int rot = ((Mathf.RoundToInt(currentBlock.transform.eulerAngles.z / 90f) % 4) + 4) % 4; int rot = ((Mathf.RoundToInt(currentBlock.transform.eulerAngles.z / 90f) % 4) + 4) % 4;
Vector2 dir; Vector2 dir;
switch (rot) switch (rot)
@ -323,12 +306,10 @@ public class LevelEditor : MonoBehaviour
default: dir = Vector2.down; break; default: dir = Vector2.down; break;
} }
// 2) Calcule 3 origines le long de la face « avant » du spike
const float eps = 0.01f; const float eps = 0.01f;
List<Vector2> origins = new List<Vector2>(); List<Vector2> origins = new List<Vector2>();
if (dir == Vector2.down || dir == Vector2.up) if (dir == Vector2.down || dir == Vector2.up)
{ {
// face inférieure ou supérieure → balaye laxe X
float y0 = (dir == Vector2.down) ? b.min.y - eps : b.max.y + eps; float y0 = (dir == Vector2.down) ? b.min.y - eps : b.max.y + eps;
origins.Add(new Vector2(b.min.x + 0.1f * b.size.x, y0)); origins.Add(new Vector2(b.min.x + 0.1f * b.size.x, y0));
origins.Add(new Vector2(b.center.x, y0)); origins.Add(new Vector2(b.center.x, y0));
@ -336,14 +317,12 @@ public class LevelEditor : MonoBehaviour
} }
else else
{ {
// face gauche ou droite → balaye laxe Y
float x0 = (dir == Vector2.left) ? b.min.x - eps : b.max.x + eps; float x0 = (dir == Vector2.left) ? b.min.x - eps : b.max.x + eps;
origins.Add(new Vector2(x0, b.min.y + 0.1f * b.size.y)); origins.Add(new Vector2(x0, b.min.y + 0.1f * b.size.y));
origins.Add(new Vector2(x0, b.center.y)); origins.Add(new Vector2(x0, b.center.y));
origins.Add(new Vector2(x0, b.max.y - 0.1f * b.size.y)); origins.Add(new Vector2(x0, b.max.y - 0.1f * b.size.y));
} }
// 3) Pour chaque origine, on lance un RaycastAll et on garde le hit le plus proche
float bestDist = float.PositiveInfinity; float bestDist = float.PositiveInfinity;
RaycastHit2D bestHit = default; RaycastHit2D bestHit = default;
foreach (var o in origins) foreach (var o in origins)
@ -361,11 +340,9 @@ public class LevelEditor : MonoBehaviour
} }
} }
// 4) Aucun support trouvé → échec
if (bestHit.collider == null) if (bestHit.collider == null)
return false; return false;
// 5) Sinon, colle bord à bord
Vector3 p = currentBlock.transform.position; Vector3 p = currentBlock.transform.position;
if (dir == Vector2.down) p.y = bestHit.point.y + hh; if (dir == Vector2.down) p.y = bestHit.point.y + hh;
else if (dir == Vector2.up) p.y = bestHit.point.y - hh; else if (dir == Vector2.up) p.y = bestHit.point.y - hh;
@ -373,7 +350,6 @@ public class LevelEditor : MonoBehaviour
else if (dir == Vector2.right) p.x = bestHit.point.x - hw; else if (dir == Vector2.right) p.x = bestHit.point.x - hw;
currentBlock.transform.position = new Vector3(p.x, p.y, -1f); currentBlock.transform.position = new Vector3(p.x, p.y, -1f);
Debug.Log($"Spike snapé {dir} sur « {bestHit.collider.name} » à {currentBlock.transform.position}");
return true; return true;
} }
@ -406,7 +382,6 @@ public class LevelEditor : MonoBehaviour
? ResizeAxis.Horizontal ? ResizeAxis.Horizontal
: ResizeAxis.Vertical; : ResizeAxis.Vertical;
isResizing = true; isResizing = true;
Debug.Log($"Début redim {tgt.name} (axe {currentResizeAxis})");
} }
void PerformResizing() void PerformResizing()
@ -422,14 +397,12 @@ public class LevelEditor : MonoBehaviour
if (IsOverlapping(resizingTarget)) if (IsOverlapping(resizingTarget))
{ {
resizingTarget.transform.localScale = originalScale; resizingTarget.transform.localScale = originalScale;
Debug.Log("Redim annulé : collision");
} }
if (Input.GetMouseButtonUp(0)) if (Input.GetMouseButtonUp(0))
{ {
isResizing = false; isResizing = false;
resizingTarget = null; resizingTarget = null;
currentResizeAxis = ResizeAxis.None; currentResizeAxis = ResizeAxis.None;
Debug.Log("Fin redim");
} }
} }
@ -455,7 +428,6 @@ public class LevelEditor : MonoBehaviour
toD = toD.transform.parent.gameObject; toD = toD.transform.parent.gameObject;
if (toD == currentBlock) { currentBlock = null; isPlacingBlock = false; } if (toD == currentBlock) { currentBlock = null; isPlacingBlock = false; }
Destroy(toD); Destroy(toD);
Debug.Log($"Supprimé {toD.name}");
} }
} }
@ -484,7 +456,6 @@ public class LevelEditor : MonoBehaviour
if (IsInvalidSnapTarget(h)) continue; if (IsInvalidSnapTarget(h)) continue;
float newX = h.bounds.min.x - b.extents.x; float newX = h.bounds.min.x - b.extents.x;
currentBlock.transform.position = new Vector3(newX, currentBlock.transform.position.y, -1f); currentBlock.transform.position = new Vector3(newX, currentBlock.transform.position.y, -1f);
Debug.Log($"Snap horizontal à droite contre {h.name}");
return; return;
} }
@ -496,7 +467,6 @@ public class LevelEditor : MonoBehaviour
if (IsInvalidSnapTarget(h)) continue; if (IsInvalidSnapTarget(h)) continue;
float newX = h.bounds.max.x + b.extents.x; float newX = h.bounds.max.x + b.extents.x;
currentBlock.transform.position = new Vector3(newX, currentBlock.transform.position.y, -1f); currentBlock.transform.position = new Vector3(newX, currentBlock.transform.position.y, -1f);
Debug.Log($"Snap horizontal à gauche contre {h.name}");
return; return;
} }
@ -509,7 +479,6 @@ public class LevelEditor : MonoBehaviour
if (IsInvalidSnapTarget(h)) continue; if (IsInvalidSnapTarget(h)) continue;
float newY = h.bounds.max.y + b.extents.y; float newY = h.bounds.max.y + b.extents.y;
currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, newY, -1f); currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, newY, -1f);
Debug.Log($"Snap vertical (bas) contre {h.name}");
return; return;
} }
@ -521,7 +490,6 @@ public class LevelEditor : MonoBehaviour
if (IsInvalidSnapTarget(h)) continue; if (IsInvalidSnapTarget(h)) continue;
float newY = h.bounds.min.y - b.extents.y; float newY = h.bounds.min.y - b.extents.y;
currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, newY, -1f); currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, newY, -1f);
Debug.Log($"Snap vertical (haut) contre {h.name}");
return; return;
} }
} }
@ -554,7 +522,6 @@ public class LevelEditor : MonoBehaviour
void HandleBlockRotation() void HandleBlockRotation()
{ {
currentBlock.transform.Rotate(0, 0, -90f); currentBlock.transform.Rotate(0, 0, -90f);
Debug.Log("Rotation 90°!");
} }
void InstantiateAndPrepare(GameObject prefab, Vector3? scaleOverride = null) void InstantiateAndPrepare(GameObject prefab, Vector3? scaleOverride = null)
@ -582,8 +549,6 @@ public class LevelEditor : MonoBehaviour
Destroy(child.gameObject); Destroy(child.gameObject);
} }
Debug.Log("Éditeur vidé.");
currentBlock = null; currentBlock = null;
isPlacingBlock = false; isPlacingBlock = false;
currentPage = 0; currentPage = 0;

View File

@ -80,7 +80,6 @@ public class TestManager : MonoBehaviour
currentPlayer.RigidBody.freezeRotation = true; currentPlayer.RigidBody.freezeRotation = true;
currentPlayer.RigidBody.linearVelocity = Vector2.zero; currentPlayer.RigidBody.linearVelocity = Vector2.zero;
currentPlayer.SpeedMultiplier = 1f; currentPlayer.SpeedMultiplier = 1f;
// currentPlayer.SpriteRenderer.sprite = Resources.Load<Sprite>("Shapes/BaseSquare");
currentPlayer.ChangeGameMode(gameMode); currentPlayer.ChangeGameMode(gameMode);
isTesting = true; isTesting = true;
@ -95,9 +94,7 @@ public class TestManager : MonoBehaviour
currentPlayer.SpriteRenderer.enabled = true; currentPlayer.SpriteRenderer.enabled = true;
if (currentPlayer.Particle != null) if (currentPlayer.Particle != null)
currentPlayer.Particle.Play(); // Démarrer la particule currentPlayer.Particle.Play();
Debug.Log("[TestManager] Test du niveau démarré !");
} }
public void StopTest() public void StopTest()
@ -112,7 +109,7 @@ public class TestManager : MonoBehaviour
currentPlayer.SpeedMultiplier = 0f; currentPlayer.SpeedMultiplier = 0f;
if (currentPlayer.Particle != null) if (currentPlayer.Particle != null)
currentPlayer.Particle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear); // Arrêter proprement currentPlayer.Particle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
if (currentPlayer.SpriteRenderer != null) if (currentPlayer.SpriteRenderer != null)
currentPlayer.SpriteRenderer.enabled = false; currentPlayer.SpriteRenderer.enabled = false;
@ -128,7 +125,5 @@ public class TestManager : MonoBehaviour
} }
isTesting = false; isTesting = false;
Debug.Log("[TestManager] Test du niveau arrêté, joueur reset et caméra recentrée !");
} }
} }