diff --git a/Assets/Photon/Fusion/Resources/PhotonAppSettings.asset b/Assets/Photon/Fusion/Resources/PhotonAppSettings.asset index e92d8cd..8489df9 100644 --- a/Assets/Photon/Fusion/Resources/PhotonAppSettings.asset +++ b/Assets/Photon/Fusion/Resources/PhotonAppSettings.asset @@ -16,7 +16,7 @@ MonoBehaviour: AppIdFusion: d1a1c822-ada0-47af-95d6-d64a4283f68d AppIdChat: AppIdVoice: - AppVersion: 1.0 + AppVersion: UseNameServer: 1 FixedRegion: Server: diff --git a/Assets/PhysicsMaterials/Friction.physicMaterial b/Assets/PhysicsMaterials/Friction.physicMaterial index 5bd0466..e16c3ca 100644 --- a/Assets/PhysicsMaterials/Friction.physicMaterial +++ b/Assets/PhysicsMaterials/Friction.physicMaterial @@ -7,7 +7,7 @@ PhysicMaterial: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Friction - dynamicFriction: 0.06998743 + dynamicFriction: 0.069989614 staticFriction: 1 bounciness: 0.3 frictionCombine: 3 diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index 249e8c5..33dc161 100644 --- a/Assets/Scenes/Gameplay.unity +++ b/Assets/Scenes/Gameplay.unity @@ -2859,13 +2859,13 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1868736288} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0.6439234, z: 0, w: 0.76509005} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -48.340305, y: -17.914295, z: -5.1727653} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 80.17, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1897337258 GameObject: m_ObjectHideFlags: 0 @@ -3249,13 +3249,13 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1928440682} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0.6477876, z: 0, w: 0.7618211} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -48.340305, y: -17.914295, z: 1.85} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 80.75, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2062866431 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Menu.unity b/Assets/Scenes/Menu.unity index 135ca63..231cfe1 100644 --- a/Assets/Scenes/Menu.unity +++ b/Assets/Scenes/Menu.unity @@ -337,7 +337,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0.00019626642, y: 0} + m_AnchoredPosition: {x: 0.00023456286, y: 0} m_SizeDelta: {x: -943, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &54820778 @@ -4018,6 +4018,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1319984346} + - component: {fileID: 1319984349} - component: {fileID: 1319984348} m_Layer: 0 m_Name: NetworkManager @@ -4061,6 +4062,18 @@ MonoBehaviour: waitingText: {fileID: 805019539} playerPrefab: RawGuidValue: b7ef0b21caef7df4fbaf32ff73da212f +--- !u!114 &1319984349 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1319984343} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 14040d85e2892f242981c2fe3079b3de, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1325907563 GameObject: m_ObjectHideFlags: 0 @@ -6052,7 +6065,6 @@ GameObject: m_Component: - component: {fileID: 2038445526} - component: {fileID: 2038445525} - - component: {fileID: 2038445527} m_Layer: 0 m_Name: NetworkRunner m_TagString: Untagged @@ -6087,18 +6099,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &2038445527 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2038445524} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 14040d85e2892f242981c2fe3079b3de, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &2082204556 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/FusionLauncher.cs b/Assets/Scripts/FusionLauncher.cs index f2afc3b..0c74d17 100644 --- a/Assets/Scripts/FusionLauncher.cs +++ b/Assets/Scripts/FusionLauncher.cs @@ -8,9 +8,6 @@ using UnityEngine.SceneManagement; using TMPro; using UnityEngine.UI; using System.Linq; -using Fusion.Photon.Realtime; -using static Unity.Collections.Unicode; - public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks { @@ -66,7 +63,6 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks IEnumerator AutoRefreshLobbyList() { - yield return new WaitForSeconds(2f); while (true) { RefreshLobbyList(); @@ -116,20 +112,31 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks // —————— RESET / CREATE FRESH RUNNER —————— private async Task EnsureFreshRunner() { - // … your existing shutdown/destroy logic … + // Reset flags + playerCount = 0; + gameplayLoaded = false; + connectedToServer = false; + // If an old runner exists & is running, shut it down & destroy its GO + if (runner != null && runner.IsRunning) + { + await runner.Shutdown(); + Destroy(runner.gameObject); + } + + // Stop auto-refresh while we rebuild + if (refreshCoroutine != null) + { + StopCoroutine(refreshCoroutine); + refreshCoroutine = null; + } + + // Make brand-new runner GameObject var go = new GameObject("NetworkRunnerGO"); - DontDestroyOnLoad(go); + DontDestroyOnLoad(go); // keep it alive across scenes - // 1) Add the runner runner = go.AddComponent(); runner.ProvideInput = true; - - // 2) Add *and* register your provider - var inputProv = go.AddComponent(); - runner.AddCallbacks(inputProv); - - // 3) If you still want FusionLauncher callbacks: runner.AddCallbacks(this); } @@ -139,29 +146,33 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks var name = lobbyNameInput.text.Trim(); if (string.IsNullOrEmpty(name)) { - Debug.LogWarning("[Host] Empty lobby name, not creating."); + Debug.LogWarning("Empty lobby name!"); return; } + // Tear down browse runner & spawn a fresh one await EnsureFreshRunner(); + + var sceneRef = SceneRef.FromIndex(SceneManager.GetActiveScene().buildIndex); var res = await runner.StartGame(new StartGameArgs() { GameMode = GameMode.Host, SessionName = name, PlayerCount = maxPlayers, - Scene = SceneRef.FromIndex(SceneManager.GetActiveScene().buildIndex), + Scene = sceneRef, SceneManager = runner.gameObject.AddComponent() }); if (res.Ok) { + Debug.Log($"✔ Hosted Lobby '{name}'"); lobbyUI.SetActive(false); waitingText.text = "Waiting for player 2…"; waitingText.gameObject.SetActive(true); } else { - Debug.LogError($"[Host] ✖ Host failed: {res.ShutdownReason}"); + Debug.LogError($"✖ Host failed: {res.ShutdownReason}"); } } @@ -192,39 +203,13 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks } } - private bool isJoiningLobby = false; - - - [ContextMenu("RefreshLobbyList")] + // —————— REFRESH LOBBY LIST —————— public void RefreshLobbyList() { - // 1) ensure runner exists & is running - if (runner == null || !runner.IsRunning) - return; - - // 2) don’t spam JoinLobby if one is in flight - if (isJoiningLobby) - return; - - // 3) only once we’re cloud-ready - if (!runner.IsCloudReady) - { - Debug.Log("[Client] skipping Refresh: not yet cloud-ready"); - return; - } - - // 4) now we can safely join the lobby - isJoiningLobby = true; - runner.JoinSessionLobby(SessionLobby.ClientServer) - .ContinueWith(_ => isJoiningLobby = false); - } // —————— REFRESH LOBBY LIST —————— - //public void RefreshLobbyList() - //{ - // if (!connectedToServer) return; - // ////sessionListUIHandler.ClearList(); - // runner.JoinSessionLobby(SessionLobby.ClientServer); - // //runner.JoinSessionLobby(SessionLobby.Shared); - //} + if (!connectedToServer) return; + //sessionListUIHandler.ClearList(); + runner.JoinSessionLobby(SessionLobby.ClientServer); + } // —————— FUSION CALLBACKS —————— public void OnConnectedToServer(NetworkRunner r)