mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-10 22:20:40 +02:00
feat: map editor (#56)
This commit is contained in:
20
Assets/Scripts/CameraController.cs
Normal file
20
Assets/Scripts/CameraController.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 10f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
float horizontalInput = Input.GetAxisRaw("Horizontal"); // ← → ou A D
|
||||
float verticalInput = Input.GetAxisRaw("Vertical"); // ↑ ↓ ou W S
|
||||
|
||||
Vector3 movement = new Vector3(
|
||||
horizontalInput * moveSpeed * Time.deltaTime,
|
||||
verticalInput * moveSpeed * Time.deltaTime,
|
||||
0f
|
||||
);
|
||||
|
||||
Camera.main.transform.position += movement;
|
||||
}
|
||||
}
|
2
Assets/Scripts/CameraController.cs.meta
Normal file
2
Assets/Scripts/CameraController.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74af3e3f2c02bde43b24c2f56589d071
|
@ -42,7 +42,10 @@ public class NormalGameMode : IGameMode
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
player.LevelsLoader.IncreaseTotalJumps();
|
||||
if (player.LevelsLoader != null)
|
||||
{
|
||||
player.LevelsLoader.IncreaseTotalJumps();
|
||||
}
|
||||
isRotating = true;
|
||||
targetRotationAngle = player.transform.eulerAngles.z - 90f;
|
||||
}
|
||||
|
@ -59,7 +59,10 @@ public class ShipGameMode : IGameMode
|
||||
{
|
||||
player.RigidBody.linearVelocity = new Vector2(player.RigidBody.linearVelocity.x, 0);
|
||||
player.RigidBody.AddForce(Vector2.up * JumpForce, ForceMode2D.Impulse);
|
||||
player.LevelsLoader.IncreaseTotalJumps();
|
||||
if (player.LevelsLoader != null)
|
||||
{
|
||||
player.LevelsLoader.IncreaseTotalJumps();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCollisionEnter(Player player, Collision2D collision)
|
||||
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
||||
public class LevelEditor : MonoBehaviour
|
||||
{
|
||||
[Header("Placement")]
|
||||
public Transform mapParent;
|
||||
private GameObject currentBlock;
|
||||
private bool isPlacingBlock = false;
|
||||
private Vector3 currentScale = new Vector3(1f, 1f, 1);
|
||||
@ -46,6 +45,12 @@ public class LevelEditor : MonoBehaviour
|
||||
|
||||
Transform container = blockGroupContainer;
|
||||
|
||||
if (container == null || buttonPrefabTemplate == null)
|
||||
{
|
||||
Debug.LogError("UI Container ou prefab de bouton manquant.");
|
||||
return;
|
||||
}
|
||||
|
||||
int start = currentPage * buttonsPerPage;
|
||||
int end = Mathf.Min(start + buttonsPerPage, blockPrefabs.Count);
|
||||
|
||||
@ -76,13 +81,9 @@ public class LevelEditor : MonoBehaviour
|
||||
|
||||
string prefabName = blockPrefabs[i].name.ToLower();
|
||||
if (prefabName.Contains("smallspike") || prefabName.Contains("smallobstacle"))
|
||||
{
|
||||
icon.GetComponent<RectTransform>().sizeDelta = new Vector2(50, 25);
|
||||
}
|
||||
else
|
||||
{
|
||||
icon.GetComponent<RectTransform>().sizeDelta = new Vector2(50, 50);
|
||||
}
|
||||
|
||||
GameObject prefab = blockPrefabs[i];
|
||||
button.GetComponent<Button>().onClick.AddListener(() => SelectPrefab(prefab));
|
||||
@ -93,9 +94,7 @@ public class LevelEditor : MonoBehaviour
|
||||
void ClearCurrentButtons()
|
||||
{
|
||||
foreach (var button in currentButtons)
|
||||
{
|
||||
Destroy(button);
|
||||
}
|
||||
|
||||
currentButtons.Clear();
|
||||
}
|
||||
@ -103,6 +102,7 @@ public class LevelEditor : MonoBehaviour
|
||||
public void NextPage()
|
||||
{
|
||||
int maxPage = 3;
|
||||
Debug.Log(currentPage);
|
||||
if (currentPage < maxPage - 1)
|
||||
{
|
||||
currentPage++;
|
||||
@ -112,6 +112,7 @@ public class LevelEditor : MonoBehaviour
|
||||
|
||||
public void PreviousPage()
|
||||
{
|
||||
Debug.Log(currentPage);
|
||||
if (currentPage > 0)
|
||||
{
|
||||
currentPage--;
|
||||
@ -121,49 +122,38 @@ public class LevelEditor : MonoBehaviour
|
||||
|
||||
void SelectPrefab(GameObject prefab)
|
||||
{
|
||||
if (isPlacingBlock)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (isPlacingBlock) return;
|
||||
|
||||
string name = prefab.name.ToLower();
|
||||
|
||||
if (name.Contains("portal"))
|
||||
{
|
||||
currentScale = new Vector3(0.5f, 0.5f, 1);
|
||||
}
|
||||
else if (name.Contains("small"))
|
||||
{
|
||||
currentScale = new Vector3(0.15f, 0.07f, 1);
|
||||
}
|
||||
else if (name.Contains("spike"))
|
||||
{
|
||||
currentScale = new Vector3(0.15f, 0.15f, 1);
|
||||
}
|
||||
else if (name.Contains("block"))
|
||||
{
|
||||
|
||||
currentScale = new Vector3(0.2f, 0.2f, 1);
|
||||
}
|
||||
else if (name.Contains("bonus"))
|
||||
{
|
||||
currentScale = new Vector3(0.3f, 0.3f, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentScale = new Vector3(1f, 1f, 1);
|
||||
}
|
||||
|
||||
InstantiateAndPrepare(prefab, currentScale);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Déplacement de l'objet en cours de placement
|
||||
if (isPlacingBlock && currentBlock != null)
|
||||
{
|
||||
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
currentBlock.transform.position = new Vector3(Mathf.Round(mousePos.x), Mathf.Round(mousePos.y), -1);
|
||||
|
||||
if (currentBlock != null && Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
HandleBlockRotation(); // ✅ Nouvelle rotation
|
||||
}
|
||||
|
||||
if (!currentBlock.name.ToLower().Contains("portal"))
|
||||
{
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
@ -185,19 +175,40 @@ public class LevelEditor : MonoBehaviour
|
||||
|
||||
if (overlaps.Length > 1)
|
||||
{
|
||||
Debug.Log("Placement annulé : un objet est déjà présent à cet endroit.");
|
||||
return;
|
||||
}
|
||||
|
||||
PlaceBlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(0) && !isPlacingBlock)
|
||||
else if (Input.GetMouseButtonDown(0)) // Clic gauche pour reprendre un objet déjà placé
|
||||
{
|
||||
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Collider2D hit = Physics2D.OverlapPoint(mousePos);
|
||||
|
||||
if (hit != null)
|
||||
if (hit != null && hit.transform != null)
|
||||
{
|
||||
if (hit.CompareTag("Ground"))
|
||||
{
|
||||
Debug.Log("Impossible de déplacer le sol (tag Ground).");
|
||||
return;
|
||||
}
|
||||
currentBlock = hit.gameObject;
|
||||
isPlacingBlock = true;
|
||||
currentScale = currentBlock.transform.localScale;
|
||||
Debug.Log($"Déplacement de l'objet : {currentBlock.name}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Redimensionnement d'un objet déjà placé
|
||||
if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift) && !isPlacingBlock)
|
||||
{
|
||||
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Collider2D hit = Physics2D.OverlapPoint(mousePos);
|
||||
|
||||
if (hit != null && hit.transform != null && !hit.CompareTag("Ground"))
|
||||
{
|
||||
resizingTarget = hit.gameObject;
|
||||
originalMousePos = mousePos;
|
||||
@ -212,6 +223,7 @@ public class LevelEditor : MonoBehaviour
|
||||
: ResizeAxis.Vertical;
|
||||
|
||||
isResizing = true;
|
||||
Debug.Log($"Début de redimensionnement : {resizingTarget.name}, axe = {currentResizeAxis}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,15 +232,34 @@ public class LevelEditor : MonoBehaviour
|
||||
Vector3 currentMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Vector3 delta = currentMousePos - originalMousePos;
|
||||
|
||||
Vector3 newScale = originalScale;
|
||||
|
||||
if (currentResizeAxis == ResizeAxis.Horizontal)
|
||||
{
|
||||
float newScaleX = Mathf.Max(0.1f, originalScale.x + delta.x);
|
||||
resizingTarget.transform.localScale = new Vector3(newScaleX, originalScale.y, 1);
|
||||
}
|
||||
newScale.x = Mathf.Max(0.1f, originalScale.x + delta.x);
|
||||
else if (currentResizeAxis == ResizeAxis.Vertical)
|
||||
newScale.y = Mathf.Max(0.1f, originalScale.y + delta.y);
|
||||
|
||||
// Temporarily apply the new scale for collision testing
|
||||
Vector3 originalPos = resizingTarget.transform.position;
|
||||
resizingTarget.transform.localScale = newScale;
|
||||
|
||||
Bounds bounds = resizingTarget.GetComponent<Collider2D>().bounds;
|
||||
Collider2D[] overlaps = Physics2D.OverlapBoxAll(bounds.center, bounds.size, 0f);
|
||||
|
||||
bool hasCollision = false;
|
||||
foreach (var col in overlaps)
|
||||
{
|
||||
float newScaleY = Mathf.Max(0.1f, originalScale.y + delta.y);
|
||||
resizingTarget.transform.localScale = new Vector3(originalScale.x, newScaleY, 1);
|
||||
if (col.gameObject != resizingTarget)
|
||||
{
|
||||
hasCollision = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCollision)
|
||||
{
|
||||
resizingTarget.transform.localScale = originalScale; // revert
|
||||
Debug.Log("Étirement annulé : collision détectée.");
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
@ -238,30 +269,180 @@ public class LevelEditor : MonoBehaviour
|
||||
currentResizeAxis = ResizeAxis.None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Clic droit pour supprimer un objet déjà placé (sauf le sol)
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
Collider2D hit = Physics2D.OverlapPoint(mousePos);
|
||||
|
||||
if (hit != null && hit.transform != null)
|
||||
{
|
||||
if (hit.CompareTag("Ground"))
|
||||
{
|
||||
Debug.Log("Impossible de supprimer le sol (tag Ground).");
|
||||
return;
|
||||
}
|
||||
|
||||
Destroy(hit.gameObject);
|
||||
Debug.Log($"Objet supprimé : {hit.name}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlaceBlock()
|
||||
{
|
||||
bool skipVerticalSnap = false;
|
||||
|
||||
if (currentBlock.name.ToLower().Contains("smallobstacle") || currentBlock.name.ToLower().Contains("portal"))
|
||||
{
|
||||
skipVerticalSnap = true; // On saute l'alignement vertical pour ces cas-là
|
||||
}
|
||||
|
||||
if (!skipVerticalSnap)
|
||||
{
|
||||
Vector2 origin = currentBlock.transform.position;
|
||||
RaycastHit2D[] hitsBelow = Physics2D.RaycastAll(origin, Vector2.down, 100f);
|
||||
|
||||
float highestY = -Mathf.Infinity;
|
||||
GameObject bestTargetBelow = null;
|
||||
|
||||
foreach (var hit in hitsBelow)
|
||||
{
|
||||
if (hit.collider != null && hit.collider.gameObject != currentBlock)
|
||||
{
|
||||
float topOfObject = hit.collider.bounds.max.y;
|
||||
if (topOfObject > highestY)
|
||||
{
|
||||
highestY = topOfObject;
|
||||
bestTargetBelow = hit.collider.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestTargetBelow != null)
|
||||
{
|
||||
float height = currentBlock.GetComponent<Collider2D>().bounds.size.y;
|
||||
currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, highestY + height / 2f, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
float height = currentBlock.GetComponent<Collider2D>().bounds.size.y;
|
||||
currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, height / 2f, -1);
|
||||
}
|
||||
}
|
||||
// ➔ Toujours essayer de snap sur la droite et en bas même pour Portal et SmallObstacle
|
||||
TrySnapToNearbyBlock();
|
||||
|
||||
isPlacingBlock = false;
|
||||
currentBlock = null;
|
||||
}
|
||||
|
||||
|
||||
private void TrySnapToNearbyBlock()
|
||||
{
|
||||
if (currentBlock == null)
|
||||
return;
|
||||
|
||||
Collider2D blockCollider = currentBlock.GetComponent<Collider2D>();
|
||||
Bounds bounds = blockCollider.bounds;
|
||||
|
||||
float snapDistance = 1f; // Distance de snap (en Unity units)
|
||||
|
||||
// Zone de scan à droite
|
||||
Vector2 rightAreaStart = new Vector2(bounds.max.x, bounds.min.y);
|
||||
Vector2 rightAreaEnd = new Vector2(bounds.max.x + snapDistance, bounds.max.y);
|
||||
|
||||
// Zone de scan à gauche
|
||||
Vector2 leftAreaStart = new Vector2(bounds.min.x - snapDistance, bounds.min.y);
|
||||
Vector2 leftAreaEnd = new Vector2(bounds.min.x, bounds.max.y);
|
||||
|
||||
// Zone de scan en dessous
|
||||
Vector2 bottomAreaStart = new Vector2(bounds.min.x, bounds.min.y - snapDistance);
|
||||
Vector2 bottomAreaEnd = new Vector2(bounds.max.x, bounds.min.y);
|
||||
|
||||
// Zone de scan au dessus
|
||||
Vector2 topAreaStart = new Vector2(bounds.min.x, bounds.max.y);
|
||||
Vector2 topAreaEnd = new Vector2(bounds.max.x, bounds.max.y + snapDistance);
|
||||
|
||||
Collider2D[] hitsRight = Physics2D.OverlapAreaAll(rightAreaStart, rightAreaEnd);
|
||||
Collider2D[] hitsLeft = Physics2D.OverlapAreaAll(leftAreaStart, leftAreaEnd);
|
||||
Collider2D[] hitsBelow = Physics2D.OverlapAreaAll(bottomAreaStart, bottomAreaEnd);
|
||||
Collider2D[] hitsAbove = Physics2D.OverlapAreaAll(topAreaStart, topAreaEnd);
|
||||
|
||||
// ➔ Priorité : droite > gauche > bas > haut
|
||||
|
||||
foreach (var hit in hitsRight)
|
||||
{
|
||||
if (hit != null && hit.gameObject != currentBlock)
|
||||
{
|
||||
float theirLeft = hit.bounds.min.x;
|
||||
float ourWidth = bounds.size.x;
|
||||
currentBlock.transform.position = new Vector3(theirLeft - ourWidth / 2f, currentBlock.transform.position.y, -1);
|
||||
Debug.Log("✅ Snap automatique à droite !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var hit in hitsLeft)
|
||||
{
|
||||
if (hit != null && hit.gameObject != currentBlock)
|
||||
{
|
||||
float theirRight = hit.bounds.max.x;
|
||||
float ourWidth = bounds.size.x;
|
||||
currentBlock.transform.position = new Vector3(theirRight + ourWidth / 2f, currentBlock.transform.position.y, -1);
|
||||
Debug.Log("✅ Snap automatique à gauche !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var hit in hitsBelow)
|
||||
{
|
||||
if (hit != null && hit.gameObject != currentBlock)
|
||||
{
|
||||
float theirTop = hit.bounds.max.y;
|
||||
float ourHeight = bounds.size.y;
|
||||
currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, theirTop + ourHeight / 2f, -1);
|
||||
Debug.Log("✅ Snap automatique en bas !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var hit in hitsAbove)
|
||||
{
|
||||
if (hit != null && hit.gameObject != currentBlock)
|
||||
{
|
||||
float theirBottom = hit.bounds.min.y;
|
||||
float ourHeight = bounds.size.y;
|
||||
currentBlock.transform.position = new Vector3(currentBlock.transform.position.x, theirBottom - ourHeight / 2f, -1);
|
||||
Debug.Log("✅ Snap automatique en haut !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void InstantiateAndPrepare(GameObject prefab, Vector3? scaleOverride = null)
|
||||
{
|
||||
GameObject obj = Instantiate(prefab);
|
||||
obj.transform.position = new Vector3(0, 0, -1);
|
||||
obj.transform.localScale = scaleOverride ?? currentScale;
|
||||
|
||||
if (mapParent != null)
|
||||
{
|
||||
obj.transform.SetParent(mapParent);
|
||||
}
|
||||
try { obj.tag = prefab.name; }
|
||||
catch { Debug.LogWarning($"Le tag '{prefab.name}' n'existe pas. Ajoutez-le dans Project Settings > Tags."); }
|
||||
|
||||
currentBlock = obj;
|
||||
isPlacingBlock = true;
|
||||
}
|
||||
|
||||
private void HandleBlockRotation()
|
||||
{
|
||||
currentBlock.transform.Rotate(0f, 0f, -90f); // ➔ Rotation de 90° dans le sens horaire
|
||||
Debug.Log("🔄 Bloc pivoté de 90° !");
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
// TODO : Implémenter la sauvegarde du niveau
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,11 @@ public class MainMenu : MonoBehaviour
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void LevelEditor()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("LevelEditorScene");
|
||||
}
|
||||
|
||||
public void EditorChoice()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("EditorChoiceScene");
|
||||
|
@ -6,9 +6,11 @@ public class Player : MonoBehaviour
|
||||
public Rigidbody2D RigidBody { get; private set; }
|
||||
public Transform Transform { get; private set; }
|
||||
public ParticleSystem Particle { get; private set; }
|
||||
public LevelsLoader LevelsLoader { get; private set; }
|
||||
public LevelsLoader LevelsLoader { get; set; }
|
||||
public SpriteRenderer SpriteRenderer { get; private set; }
|
||||
public bool IsColliding { get; set; } = true;
|
||||
public bool HasStarted { get; set; } = false;
|
||||
public bool CanJump { get; set; } = true;
|
||||
|
||||
public IGameMode CurrentGameMode { get; set; }
|
||||
public float SpeedMultiplier = 1f;
|
||||
@ -19,7 +21,12 @@ public class Player : MonoBehaviour
|
||||
Transform = transform;
|
||||
Particle = GetComponentInChildren<ParticleSystem>();
|
||||
SpriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||
LevelsLoader = GameObject.FindGameObjectWithTag("LevelsLoader").GetComponent<LevelsLoader>();
|
||||
|
||||
GameObject loaderObj = GameObject.FindGameObjectWithTag("LevelsLoader");
|
||||
if (loaderObj != null)
|
||||
LevelsLoader = loaderObj.GetComponent<LevelsLoader>();
|
||||
else
|
||||
Debug.LogWarning("LevelsLoader introuvable : Progression désactivée pour ce niveau.");
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@ -33,21 +40,24 @@ public class Player : MonoBehaviour
|
||||
|
||||
public void Update()
|
||||
{
|
||||
CurrentGameMode.Update(this);
|
||||
LevelsLoader.CalculateCurrentProgressionPercent(transform.position);
|
||||
if (CurrentGameMode != null)
|
||||
CurrentGameMode.Update(this);
|
||||
|
||||
if (LevelsLoader != null)
|
||||
LevelsLoader.CalculateCurrentProgressionPercent(transform.position);
|
||||
}
|
||||
|
||||
public void OnCollisionEnter2D(Collision2D collision)
|
||||
public virtual void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
CurrentGameMode.OnCollisionEnter(this, collision);
|
||||
CurrentGameMode?.OnCollisionEnter(this, collision);
|
||||
}
|
||||
|
||||
public void OnCollisionExit2D(Collision2D collision)
|
||||
{
|
||||
CurrentGameMode.OnCollisionExit(this, collision);
|
||||
CurrentGameMode?.OnCollisionExit(this, collision);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
public virtual void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.CompareTag("ShipPortal"))
|
||||
{
|
||||
|
@ -8,6 +8,9 @@ public class PlayerCamera : MonoBehaviour
|
||||
public float smoothSpeed = 5.0f;
|
||||
private float initialY;
|
||||
|
||||
[Header("References")]
|
||||
public bool isPlaying;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
initialY = transform.position.y;
|
||||
@ -15,22 +18,25 @@ public class PlayerCamera : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Player player = playerObject.GetComponent<Player>();
|
||||
|
||||
float minYFollow = normalMinYFollow;
|
||||
if (player.CurrentGameMode is ShipGameMode)
|
||||
if (isPlaying)
|
||||
{
|
||||
minYFollow = shipMinYFollow;
|
||||
Player player = playerObject.GetComponent<Player>();
|
||||
|
||||
float minYFollow = normalMinYFollow;
|
||||
if (player.CurrentGameMode is ShipGameMode)
|
||||
{
|
||||
minYFollow = shipMinYFollow;
|
||||
}
|
||||
|
||||
float targetY = initialY;
|
||||
if (playerObject.transform.position.y > minYFollow)
|
||||
{
|
||||
targetY = playerObject.transform.position.y;
|
||||
}
|
||||
|
||||
float newY = Mathf.Lerp(transform.position.y, targetY, smoothSpeed * Time.deltaTime);
|
||||
|
||||
transform.position = new Vector3(playerObject.transform.position.x, newY, transform.position.z);
|
||||
}
|
||||
|
||||
float targetY = initialY;
|
||||
if (playerObject.transform.position.y > minYFollow)
|
||||
{
|
||||
targetY = playerObject.transform.position.y;
|
||||
}
|
||||
|
||||
float newY = Mathf.Lerp(transform.position.y, targetY, smoothSpeed * Time.deltaTime);
|
||||
|
||||
transform.position = new Vector3(playerObject.transform.position.x, newY, transform.position.z);
|
||||
}
|
||||
}
|
||||
|
127
Assets/Scripts/TestManager.cs
Normal file
127
Assets/Scripts/TestManager.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TestManager : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
public IGameMode gameMode;
|
||||
public Player currentPlayer;
|
||||
public Transform spawnPoint;
|
||||
public GameObject editorUI;
|
||||
public PlayerCamera playerCamera;
|
||||
|
||||
private bool isTesting = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (spawnPoint == null)
|
||||
{
|
||||
GameObject spawn = new GameObject("AutoSpawnPoint");
|
||||
spawn.transform.position = new Vector3(-16, -3, 0f);
|
||||
spawnPoint = spawn.transform;
|
||||
}
|
||||
|
||||
if (currentPlayer == null)
|
||||
{
|
||||
Debug.LogError("[TestManager] Aucun Player assigné !");
|
||||
}
|
||||
else
|
||||
{
|
||||
gameMode = new NormalGameMode();
|
||||
currentPlayer.ChangeGameMode(gameMode);
|
||||
currentPlayer.SpeedMultiplier = 0f;
|
||||
|
||||
if (currentPlayer.SpriteRenderer != null)
|
||||
currentPlayer.SpriteRenderer.enabled = false;
|
||||
|
||||
if (currentPlayer.Particle != null)
|
||||
currentPlayer.Particle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear); // 🛑 Stop propre
|
||||
}
|
||||
|
||||
if (playerCamera != null)
|
||||
{
|
||||
playerCamera.isPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isTesting && currentPlayer == null)
|
||||
{
|
||||
StopTest();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartOrStop()
|
||||
{
|
||||
if (isTesting)
|
||||
StopTest();
|
||||
else
|
||||
StartTest();
|
||||
}
|
||||
|
||||
public void StartTest()
|
||||
{
|
||||
if (currentPlayer == null)
|
||||
{
|
||||
Debug.LogError("[TestManager] Player manquant pour lancer le test !");
|
||||
return;
|
||||
}
|
||||
|
||||
if (editorUI != null)
|
||||
editorUI.SetActive(false);
|
||||
|
||||
currentPlayer.transform.position = spawnPoint.position;
|
||||
currentPlayer.RigidBody.linearVelocity = Vector2.zero;
|
||||
currentPlayer.SpeedMultiplier = 1f;
|
||||
currentPlayer.SpriteRenderer.sprite = Resources.Load<Sprite>("Shapes/BaseSquare");
|
||||
|
||||
currentPlayer.ChangeGameMode(gameMode);
|
||||
isTesting = true;
|
||||
|
||||
if (playerCamera != null)
|
||||
{
|
||||
playerCamera.playerObject = currentPlayer.gameObject;
|
||||
playerCamera.isPlaying = true;
|
||||
}
|
||||
|
||||
if (currentPlayer.SpriteRenderer != null)
|
||||
currentPlayer.SpriteRenderer.enabled = true;
|
||||
|
||||
if (currentPlayer.Particle != null)
|
||||
currentPlayer.Particle.Play(); // ✅ Démarrer la particule
|
||||
|
||||
Debug.Log("[TestManager] Test du niveau démarré !");
|
||||
}
|
||||
|
||||
public void StopTest()
|
||||
{
|
||||
if (currentPlayer != null)
|
||||
{
|
||||
currentPlayer.transform.position = spawnPoint.position;
|
||||
currentPlayer.RigidBody.linearVelocity = Vector2.zero;
|
||||
currentPlayer.RigidBody.angularVelocity = 0f;
|
||||
currentPlayer.transform.rotation = Quaternion.identity;
|
||||
currentPlayer.SpriteRenderer.sprite = Resources.Load<Sprite>("Shapes/BaseSquare");
|
||||
currentPlayer.SpeedMultiplier = 0f;
|
||||
|
||||
if (currentPlayer.Particle != null)
|
||||
currentPlayer.Particle.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear); // ✅ Arrêter proprement
|
||||
|
||||
if (currentPlayer.SpriteRenderer != null)
|
||||
currentPlayer.SpriteRenderer.enabled = false;
|
||||
}
|
||||
|
||||
if (editorUI != null)
|
||||
editorUI.SetActive(true);
|
||||
|
||||
if (playerCamera != null)
|
||||
{
|
||||
playerCamera.isPlaying = false;
|
||||
playerCamera.transform.position = new Vector3(0f, 0f, -10f);
|
||||
}
|
||||
|
||||
isTesting = false;
|
||||
|
||||
Debug.Log("[TestManager] Test du niveau arrêté, joueur reset et caméra recentrée !");
|
||||
}
|
||||
}
|
2
Assets/Scripts/TestManager.cs.meta
Normal file
2
Assets/Scripts/TestManager.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c6d38f8c53ec314c9827a842e6f17d8
|
Reference in New Issue
Block a user