Conversation
WalkthroughLes modifications apportées dans cette demande de tirage concernent principalement la configuration des objets de jeu et leurs propriétés dans la scène Unity Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (4)
Assets/Scripts/UI/PlayerHealth.cs (2)
Line range hint
39-46: Erreur de syntaxe dans la méthode HealIl manque une accolade fermante après
currentHealth = maxHealth. Cette erreur empêchera la compilation du code.Voici la correction à appliquer :
public void Heal(int amount) { currentHealth += amount; if (currentHealth > maxHealth) { currentHealth = maxHealth; + } UpdateHealthBar(); }
Line range hint
39-46: Suggestion d'amélioration pour la méthode HealPour une meilleure cohérence avec la méthode
TakeDamage, considérez l'ajout d'une vérification de santé minimale.Voici une suggestion d'amélioration :
public void Heal(int amount) { currentHealth += amount; if (currentHealth > maxHealth) { currentHealth = maxHealth; } + if (currentHealth < 0) + { + currentHealth = 0; + } UpdateHealthBar(); }Assets/Scripts/SocketManager.cs (1)
6-7: Imports System.Collections.Generic non utiliséL'import
System.Collections.Generica été ajouté mais n'est pas utilisé dans le code.using System; using System.Threading.Tasks; using UnityEngine; using SocketIOClient; using CandyCoded.env; using System.IO; -using System.Collections.Generic;Assets/Scripts/Player/PlayerController.cs (1)
Line range hint
1-225: Recommandations générales pour la gestion des configurationsPour améliorer la robustesse de l'application sur Windows, voici quelques suggestions architecturales :
- Centraliser la gestion des variables d'environnement dans une seule classe.
- Utiliser un système de configuration hiérarchique.
- Implémenter une validation des configurations au démarrage.
Je suggère de créer une classe
ConfigurationManagerdédiée. Voulez-vous que je propose une implémentation ?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- Assets/Scenes/EmptyRoom_2.unity (2 hunks)
- Assets/Scripts/Player/PlayerController.cs (4 hunks)
- Assets/Scripts/SocketManager.cs (2 hunks)
- Assets/Scripts/Trap/TrapManager.cs (0 hunks)
- Assets/Scripts/UI/PlayerHealth.cs (2 hunks)
💤 Files with no reviewable changes (1)
- Assets/Scripts/Trap/TrapManager.cs
🔇 Additional comments (7)
Assets/Scripts/UI/PlayerHealth.cs (3)
62-67: Amélioration de la gestion de l'état de mort du joueurLa vérification supplémentaire de
!deadCanvas.activeSelfest une bonne pratique pour éviter les émissions multiples de socket.
83-83: RAS sur la mise à jour de la barre de vieLa logique d'instanciation des cœurs est correcte.
62-67: Vérification de la gestion des socketsAssurons-nous que l'émission du socket est correctement gérée dans tous les cas.
Assets/Scripts/SocketManager.cs (1)
32-32: Vérifier la compatibilité Windows du chemin du fichierLe chemin du fichier .env utilise
Application.dataPathqui pourrait causer des problèmes sur Windows.✅ Verification successful
La gestion des chemins de fichiers est correctement implémentée
L'utilisation de
Path.CombineavecApplication.dataPathest la méthode recommandée par Unity pour gérer les chemins de fichiers de manière compatible sur toutes les plateformes, y compris Windows. Cette approche est utilisée de manière cohérente dans tout le code pour accéder au fichier.env.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Rechercher d'autres utilisations de Application.dataPath pour vérifier la cohérence rg "Application.dataPath" -A 2Length of output: 479
Script:
#!/bin/bash # Vérifier l'utilisation de Path.Combine pour voir si c'est cohérent dans le code rg "Path.Combine" -A 2Length of output: 471
Assets/Scripts/Player/PlayerController.cs (1)
215-215: Amélioration de la clarté du message d'erreurLa modification apportée pour utiliser explicitement
UnityEngine.Debug.LogErroraméliore la clarté du code.Assets/Scenes/EmptyRoom_2.unity (2)
884-887: Confirmation requise pour l'activation par défaut de la caméraL'activation par défaut de la caméra pourrait avoir un impact sur l'initialisation de la scène. Assurez-vous que cela n'interfère pas avec d'autres systèmes de caméra ou transitions.
693-696: Vérification nécessaire de la configuration du nouveau piègeL'ajout d'un nouveau préfab de piège nécessite une vérification de sa configuration pour assurer une intégration correcte avec le système de pièges existant.
✅ Verification successful
Configuration du préfab d'arbalète correctement intégrée
Le préfab d'arbalète est correctement configuré avec :
- Le script Crossbow attaché avec les références nécessaires
- Un point de tir (firePoint) correctement positionné
- Une direction de tir appropriée
- Les composants de collision et d'animation requis
Le système de gestion des pièges (TrapManager) prend également en charge ce type de piège dans son dictionnaire de préfabs.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Vérifier la configuration du préfab de piège # Rechercher les références au préfab dans les scripts rg -l "d7c2a5ac1f23afe428f872343ed56d71"Length of output: 209
Script:
#!/bin/bash # Vérifier le contenu du préfab de l'arbalète et ses références cat Assets/Prefabs/Traps/Crossbow/crossbow_up_prefab.prefab # Rechercher les scripts liés aux pièges pour vérifier l'intégration rg -g "*.cs" "trap" -lLength of output: 6810
Script:
#!/bin/bash # Vérifier le script de gestion des pièges cat Assets/Scripts/Trap/TrapManager.cs # Vérifier le script spécifique à l'arbalète rg -g "*.cs" "arrowPrefab" -lLength of output: 4154
Script:
#!/bin/bash # Vérifier le script de l'arbalète cat Assets/Scripts/Trap/Crossbow/Crossbow.cs # Vérifier les autres préfabs d'arbalète référencés cat Assets/Prefabs/Traps/Crossbow/*.prefabLength of output: 29463
|
|
||
| LoadEnvVariables(); | ||
|
|
||
| try | ||
| { | ||
| var socketUrl = Environment.GetEnvironmentVariable("SOCKET_URL"); | ||
| var uri = new Uri(socketUrl); | ||
| ClientSocket = new SocketIOUnity(uri); | ||
|
|
||
| // Connect to the server | ||
| await ClientSocket.ConnectAsync(); | ||
| Debug.Log("Connected to backend via SocketManager."); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Debug.LogError("Socket connection error: " + e.Message); | ||
| } |
There was a problem hiding this comment.
Code dupliqué dans SetupSocket
Il y a une duplication du bloc try-catch pour la connexion socket. De plus, deux approches différentes sont utilisées pour récupérer l'URL du socket.
Voici la correction proposée :
private async Task SetupSocket()
{
LoadEnvVariables();
try
{
- var socketUrl = Environment.GetEnvironmentVariable("SOCKET_URL");
- var uri = new Uri(socketUrl);
- ClientSocket = new SocketIOUnity(uri);
-
- // Connect to the server
- await ClientSocket.ConnectAsync();
- Debug.Log("Connected to backend via SocketManager.");
- }
- catch (Exception e)
- {
- Debug.LogError("Socket connection error: " + e.Message);
- }
-
- try
- {
- env.TryParseEnvironmentVariable("SOCKET_URL", out string socketUrl);
+ if (!env.TryParseEnvironmentVariable("SOCKET_URL", out string socketUrl))
+ {
+ throw new Exception("Variable d'environnement SOCKET_URL non définie");
+ }
var uri = new Uri(socketUrl);
ClientSocket = new SocketIOUnity(uri);
// Connect to the server
await ClientSocket.ConnectAsync();
- Debug.Log("Connected to backend via SocketManager.");
+ Debug.Log("Connecté au backend via SocketManager.");
}
catch (Exception e)
{
- Debug.LogError("Socket connection error: " + e.Message);
+ Debug.LogError($"Erreur de connexion socket : {e.Message}");
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| LoadEnvVariables(); | |
| try | |
| { | |
| var socketUrl = Environment.GetEnvironmentVariable("SOCKET_URL"); | |
| var uri = new Uri(socketUrl); | |
| ClientSocket = new SocketIOUnity(uri); | |
| // Connect to the server | |
| await ClientSocket.ConnectAsync(); | |
| Debug.Log("Connected to backend via SocketManager."); | |
| } | |
| catch (Exception e) | |
| { | |
| Debug.LogError("Socket connection error: " + e.Message); | |
| } | |
| LoadEnvVariables(); | |
| try | |
| { | |
| if (!env.TryParseEnvironmentVariable("SOCKET_URL", out string socketUrl)) | |
| { | |
| throw new Exception("Variable d'environnement SOCKET_URL non définie"); | |
| } | |
| var uri = new Uri(socketUrl); | |
| ClientSocket = new SocketIOUnity(uri); | |
| // Connect to the server | |
| await ClientSocket.ConnectAsync(); | |
| Debug.Log("Connecté au backend via SocketManager."); | |
| } | |
| catch (Exception e) | |
| { | |
| Debug.LogError($"Erreur de connexion socket : {e.Message}"); | |
| } |
| private void LoadEnvVariables() | ||
| { | ||
| string envFilePath = Path.Combine(Application.dataPath, ".env"); | ||
|
|
||
| if (File.Exists(envFilePath)) | ||
| { | ||
| foreach (var line in File.ReadAllLines(envFilePath)) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) | ||
| { | ||
| var keyValue = line.Split('='); | ||
| if (keyValue.Length == 2) | ||
| { | ||
| var key = keyValue[0].Trim(); | ||
| var value = keyValue[1].Trim(); | ||
| Environment.SetEnvironmentVariable(key, value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Debug.LogError(".env file not found at " + envFilePath); | ||
| } | ||
| } |
There was a problem hiding this comment.
Améliorer la gestion des variables d'environnement
La méthode LoadEnvVariables présente plusieurs points à améliorer :
- Il manque une validation du contenu des variables d'environnement
- Les erreurs ne sont pas gérées lors de la lecture du fichier
- Le chemin du fichier .env pourrait être problématique sur certaines plateformes
Voici une version améliorée :
private void LoadEnvVariables()
{
- string envFilePath = Path.Combine(Application.dataPath, ".env");
+ string envFilePath = Path.Combine(Application.persistentDataPath, ".env");
if (File.Exists(envFilePath))
{
- foreach (var line in File.ReadAllLines(envFilePath))
+ try
{
- if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
+ foreach (var line in File.ReadAllLines(envFilePath))
{
- var keyValue = line.Split('=');
- if (keyValue.Length == 2)
+ if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
{
- var key = keyValue[0].Trim();
- var value = keyValue[1].Trim();
- Environment.SetEnvironmentVariable(key, value);
+ var keyValue = line.Split(new[] { '=' }, 2);
+ if (keyValue.Length == 2)
+ {
+ var key = keyValue[0].Trim();
+ var value = keyValue[1].Trim();
+ if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
+ {
+ Environment.SetEnvironmentVariable(key, value);
+ }
+ }
}
}
}
+ catch (Exception e)
+ {
+ Debug.LogError($"Erreur lors de la lecture du fichier .env : {e.Message}");
+ }
}
else
{
- Debug.LogError(".env file not found at " + envFilePath);
+ Debug.LogError($"Fichier .env non trouvé : {envFilePath}");
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private void LoadEnvVariables() | |
| { | |
| string envFilePath = Path.Combine(Application.dataPath, ".env"); | |
| if (File.Exists(envFilePath)) | |
| { | |
| foreach (var line in File.ReadAllLines(envFilePath)) | |
| { | |
| if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) | |
| { | |
| var keyValue = line.Split('='); | |
| if (keyValue.Length == 2) | |
| { | |
| var key = keyValue[0].Trim(); | |
| var value = keyValue[1].Trim(); | |
| Environment.SetEnvironmentVariable(key, value); | |
| } | |
| } | |
| } | |
| } | |
| else | |
| { | |
| Debug.LogError(".env file not found at " + envFilePath); | |
| } | |
| } | |
| private void LoadEnvVariables() | |
| { | |
| string envFilePath = Path.Combine(Application.persistentDataPath, ".env"); | |
| if (File.Exists(envFilePath)) | |
| { | |
| try | |
| { | |
| foreach (var line in File.ReadAllLines(envFilePath)) | |
| { | |
| if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) | |
| { | |
| var keyValue = line.Split(new[] { '=' }, 2); | |
| if (keyValue.Length == 2) | |
| { | |
| var key = keyValue[0].Trim(); | |
| var value = keyValue[1].Trim(); | |
| if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) | |
| { | |
| Environment.SetEnvironmentVariable(key, value); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| catch (Exception e) | |
| { | |
| Debug.LogError($"Erreur lors de la lecture du fichier .env : {e.Message}"); | |
| } | |
| } | |
| else | |
| { | |
| Debug.LogError($"Fichier .env non trouvé : {envFilePath}"); | |
| } | |
| } |
| try | ||
| { | ||
| LoadEnvVariables(); | ||
| var socketUrl = Environment.GetEnvironmentVariable("SOCKET_URL"); | ||
| var uri = new Uri(socketUrl); | ||
| clientSocket = SocketManager.Instance.ClientSocket; | ||
| if (clientSocket == null) | ||
| { | ||
| Debug.LogError("SocketIO client is null! Check SocketManager initialization."); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Debug.LogError("Socket connection error: " + e.Message); | ||
| } |
There was a problem hiding this comment.
Code dupliqué dans la méthode Start
Il y a une duplication du bloc try-catch pour la configuration du socket. De plus, vous mélangez deux approches différentes pour charger les variables d'environnement.
Suggestion de refactorisation :
try
{
LoadEnvVariables();
- var socketUrl = Environment.GetEnvironmentVariable("SOCKET_URL");
- var uri = new Uri(socketUrl);
- clientSocket = SocketManager.Instance.ClientSocket;
- if (clientSocket == null)
- {
- Debug.LogError("SocketIO client is null! Check SocketManager initialization.");
- }
- }
- catch (Exception e)
- {
- Debug.LogError("Socket connection error: " + e.Message);
- }
- try
- {
env.TryParseEnvironmentVariable("SOCKET_URL", out string socketUrl);
var uri = new Uri(socketUrl);
clientSocket = SocketManager.Instance.ClientSocket;
if (clientSocket == null)
{
- Debug.LogError("SocketIO client is null! Check SocketManager initialization.");
+ Debug.LogError("Le client SocketIO est null ! Vérifiez l'initialisation du SocketManager.");
}
}
catch (Exception e)
{
- Debug.LogError("Socket connection error: " + e.Message);
+ Debug.LogError($"Erreur de connexion socket : {e.Message}");
}Committable suggestion was skipped due to low confidence.
| private void LoadEnvVariables() | ||
| { | ||
| string envFilePath = Path.Combine(Application.dataPath, ".env"); | ||
|
|
||
| if (File.Exists(envFilePath)) | ||
| { | ||
| foreach (var line in File.ReadAllLines(envFilePath)) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) | ||
| { | ||
| var keyValue = line.Split('='); | ||
| if (keyValue.Length == 2) | ||
| { | ||
| var key = keyValue[0].Trim(); | ||
| var value = keyValue[1].Trim(); | ||
| Environment.SetEnvironmentVariable(key, value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Debug.LogError(".env file not found at " + envFilePath); | ||
| } | ||
| } |
There was a problem hiding this comment.
Attention à la gestion des chemins de fichiers sur Windows
La méthode LoadEnvVariables présente plusieurs points à améliorer :
- L'utilisation de
Path.Combineest bonne pour la compatibilité Windows, maisApplication.dataPathn'est peut-être pas le meilleur choix pour stocker le fichier.env. - Il manque une validation du contenu des variables d'environnement.
- La méthode fait double emploi avec
CandyCoded.envdéjà importé.
Suggestions d'amélioration :
private void LoadEnvVariables()
{
- string envFilePath = Path.Combine(Application.dataPath, ".env");
+ string envFilePath = Path.Combine(Application.persistentDataPath, ".env");
if (File.Exists(envFilePath))
{
foreach (var line in File.ReadAllLines(envFilePath))
{
if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#"))
{
var keyValue = line.Split('=');
if (keyValue.Length == 2)
{
var key = keyValue[0].Trim();
var value = keyValue[1].Trim();
+ if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
+ {
+ Debug.LogWarning($"Variable d'environnement invalide : {line}");
+ continue;
+ }
Environment.SetEnvironmentVariable(key, value);
}
}
}
}
else
{
- Debug.LogError(".env file not found at " + envFilePath);
+ Debug.LogError($"Fichier .env non trouvé : {envFilePath}");
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private void LoadEnvVariables() | |
| { | |
| string envFilePath = Path.Combine(Application.dataPath, ".env"); | |
| if (File.Exists(envFilePath)) | |
| { | |
| foreach (var line in File.ReadAllLines(envFilePath)) | |
| { | |
| if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) | |
| { | |
| var keyValue = line.Split('='); | |
| if (keyValue.Length == 2) | |
| { | |
| var key = keyValue[0].Trim(); | |
| var value = keyValue[1].Trim(); | |
| Environment.SetEnvironmentVariable(key, value); | |
| } | |
| } | |
| } | |
| } | |
| else | |
| { | |
| Debug.LogError(".env file not found at " + envFilePath); | |
| } | |
| } | |
| private void LoadEnvVariables() | |
| { | |
| string envFilePath = Path.Combine(Application.persistentDataPath, ".env"); | |
| if (File.Exists(envFilePath)) | |
| { | |
| foreach (var line in File.ReadAllLines(envFilePath)) | |
| { | |
| if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")) | |
| { | |
| var keyValue = line.Split('='); | |
| if (keyValue.Length == 2) | |
| { | |
| var key = keyValue[0].Trim(); | |
| var value = keyValue[1].Trim(); | |
| if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) | |
| { | |
| Debug.LogWarning($"Variable d'environnement invalide : {line}"); | |
| continue; | |
| } | |
| Environment.SetEnvironmentVariable(key, value); | |
| } | |
| } | |
| } | |
| } | |
| else | |
| { | |
| Debug.LogError($"Fichier .env non trouvé : {envFilePath}"); | |
| } | |
| } |
* feat: add death system * chore: add socket emiter for end game * fix: fix heart generator if develop don't have socket * fix: remove crossbow * chore: try to fix .env for Windows and Unity * fix: Quick Fix in production
* Chore/shadering map (#24) * technical : add shadering and post-traitement system, adapt asset and sprite for using this * feat: update Room2 * feat: Link the chat to the back sockets (#25) * feat: Link chat to backend (#26) * feat: Link the chat to the back sockets * fix: Move the dialogue script outside the canvas to avoid it to be disabled while the canvas is going to be disabled * fix: remove dual camera * fix: fix crossbow system (#27) * fix: add request to back (room name) * fix: Revert trap manager * hotfix: Fix things that weren't working * feat: RPS (#29) * feat : add multiple option and itemscollider for RockPaperCissor * feat: Link Rock Paper Scissors to backend socket * feat: Link RockPaperScissors, but display missing --------- Co-authored-by: Thomas Lamiable <lamiablethomas@gmail.com> * hotfix: Change RPS size to match the screen * fix: fix Crossbow up sprite and arrow system, change color pixel dead font * chore: change EmptyRoom2 * feat: add death system (#30) * feat: add death system * chore: add socket emiter for end game * fix: fix heart generator if develop don't have socket * fix: remove crossbow * feature: add audio system and fix crossbow with sound (#32) Co-authored-by: Guillaume MORET <90462045+AyakorK@users.noreply.github.com> * chore: Fix env for windows (#31) * feat: add death system * chore: add socket emiter for end game * fix: fix heart generator if develop don't have socket * fix: remove crossbow * chore: try to fix .env for Windows and Unity * fix: Quick Fix in production * fix: QuickFx PlayerHealth fail merge * Fix: fix Room * feat: Adapt Waiting Room (#33) * feat: Instantiate waiting room when arriving in the corridor 0 * fix: Add a flag to change message one time and avoid repetition of it * feat: Add the creation of the room when instanciating the WaitingRoom process * feat: Try to remove the Door collider before game has started * fix: fix lock and door system, add waiting room, last fix for dialogue system for pity --------- Co-authored-by: Thomlam <lamiablethomas@gmail.com> * fix: rename bear_trap to prefab * fix: quick fix prefab room for crossbow * fix: quickfix for bear_trap * feat: Add room deletion when disconnection from a game * Wip/streaming back (#35) * feat: add streaming system with recording and sending frame jpeg * feat: add config * feat: first try to add socketIOSystem * feat: Add the right socket * feature : deploy for 60fps --------- Co-authored-by: AyakorK <guillaume.moret@yahoo.com> * hotfix: Get rid of a Debug * fix: fix arrows component and stade 24 fps to streaming * fix: Global rendering fixes (#36) * fix: Update corridor displays + additions of colliders to avoid glitching * fix: Add a door transition lock * feat: Add collision to the walls in the room * fix: Fix collisions of the hole * fix: Fix glitched hitboxes * fix: Destory arrows when going to an other room --------- Co-authored-by: Guillaume MORET <90462045+AyakorK@users.noreply.github.com> Co-authored-by: AyakorK <guillaume.moret@yahoo.com>
Summary by CodeRabbit
Nouvelles Fonctionnalités
Améliorations
Corrections de Bugs