final feedbacks fixed

This commit is contained in:
2026-04-20 14:36:51 +05:30
parent 4ba7623b13
commit f31f90034c
9 changed files with 570 additions and 1989 deletions
+21 -1
View File
@@ -67,6 +67,8 @@ public class GameManager : NetworkBehaviour
public bool m_isMoving =false;
[SyncVar(hook = nameof(OnGameStartedChanged))]
public bool gameStarted = false;
[SyncVar]
public bool isGameEnded = false;
void OnGameStartedChanged(bool oldStarted, bool newStarted){
if(newStarted){
GameCanvas.instance.HideWaitingForOpponentPanel();
@@ -509,18 +511,33 @@ public class GameManager : NetworkBehaviour
}
Team GetOpposingTeam(Team team){
return team == Team.Red ? Team.Blue : Team.Red;
}
void SetKickoffTeam(Team kickoffTeam){
turnTimerCounter = 0;
SelectedTeam = kickoffTeam;
OnTeamChanged?.Invoke(SelectedTeam);
}
public void OnGoal(Team team){
if(!isServer){
Debug.LogWarning("OnGoal called on client, skipping");
return;}
if(!CanProcessGoal){
return;
}
RpcPlayGoalScoredSfx();
freezeInput=true;
Team concedingTeam = GetOpposingTeam(team);
if(hitCounter == 1){
//kickoff goal
Logger.Log("Kickoff goal");
SetKickoffTeam(concedingTeam);
StartCoroutine(CoroutineOnGoal(team,true));//true = Kickoff goal, reset only the ball
hitCounter = 0;
@@ -536,14 +553,16 @@ public class GameManager : NetworkBehaviour
PlayGoalEffects(Team.Red);
}
SwitchTeams();
SetKickoffTeam(concedingTeam);
if(blueScore >= 3){
isGameEnded = true;
ReportDedicatedMatchGameOver(Team.Blue);
RpcGameOver(Team.Blue);
gameOver(Team.Blue);
}else if(redScore >= 3){
isGameEnded = true;
ReportDedicatedMatchGameOver(Team.Red);
RpcGameOver(Team.Red);
gameOver(Team.Red);
@@ -680,6 +699,7 @@ public class GameManager : NetworkBehaviour
}
bool freezeInput = false;
public bool CanProcessGoal => isServer && !freezeInput && !isGameEnded;
IEnumerator CoroutineOnGoal(Team team, bool kickoff = false){
if(coroutinePostLaunch!=null){
+3
View File
@@ -9,6 +9,9 @@ public class Goal : NetworkBehaviour
if(!isServer){return;}
if(collision.gameObject.CompareTag("Player")){
if(GameManager.instance == null || !GameManager.instance.CanProcessGoal){
return;
}
Debug.Log($"GOAL! {team}", gameObject);
Ball ball = collision.gameObject.GetComponent<Ball>();
Debug.Log(ball.name);
+61
View File
@@ -1,11 +1,72 @@
using System.Collections;
using UnityEngine;
using Mirror;
public class NetManager : NetworkManager
{
[SerializeField] float reconnectIntervalSeconds = 15f;
Coroutine reconnectCoroutine;
public override void OnStopServer()
{
GameManager.ReportDedicatedMatchRoomClosed();
base.OnStopServer();
}
public override void OnStopClient()
{
base.OnStopClient();
TryStartReconnectLoop();
}
public override void OnClientConnect()
{
base.OnClientConnect();
StopReconnectLoop();
}
void TryStartReconnectLoop()
{
if (!ShouldReconnect() || reconnectCoroutine != null)
return;
reconnectCoroutine = StartCoroutine(CoroutineReconnectLoop());
}
void StopReconnectLoop()
{
if (reconnectCoroutine == null)
return;
StopCoroutine(reconnectCoroutine);
reconnectCoroutine = null;
}
bool ShouldReconnect()
{
if (NetworkServer.active)
return false;
if (NetworkClient.isConnected)
return false;
if (GameManager.instance != null && GameManager.instance.isGameEnded)
return false;
return true;
}
IEnumerator CoroutineReconnectLoop()
{
while (ShouldReconnect())
{
if (!NetworkClient.active)
{
Debug.Log("Client disconnected. Reconnecting...");
StartClient();
}
yield return new WaitForSeconds(reconnectIntervalSeconds);
}
reconnectCoroutine = null;
}
}
+13
View File
@@ -166,9 +166,22 @@ public class Puck : NetworkBehaviour
Debug.Log("Resetting puck", gameObject);
Vector3 dir = position - transform.position;
Vector3 centerDir = Vector3.zero - transform.position;
dir = dir.normalized;
centerDir = centerDir.normalized;
// Clamp direction to within 30 degrees of centerDir if needed
float maxAngle = 30f;
float angle = Vector3.Angle(dir, centerDir);
if (angle > maxAngle)
{
dir = Vector3.Slerp(centerDir, dir, maxAngle / angle).normalized;
}
position += dir * 1.25f;
Reset(position, duration);
}
IEnumerator CoroutineReset(Vector3 pos, float duration){