From 98c6a0edb057f267c2f28e36017cab6b52b8a311 Mon Sep 17 00:00:00 2001 From: Ali Sharoz Date: Mon, 5 May 2025 16:31:21 +0500 Subject: [PATCH] Update input bug --- .../Fusion/Resources/PhotonAppSettings.asset | 2 +- .../PhysicsMaterials/Friction.physicMaterial | 2 +- Assets/Scenes/Gameplay.unity | 8 +- Assets/Scenes/Menu.unity | 28 +++---- Assets/Scripts/FusionLauncher.cs | 79 +++++++++++-------- 5 files changed, 67 insertions(+), 52 deletions(-) diff --git a/Assets/Photon/Fusion/Resources/PhotonAppSettings.asset b/Assets/Photon/Fusion/Resources/PhotonAppSettings.asset index 8489df9..e92d8cd 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: + AppVersion: 1.0 UseNameServer: 1 FixedRegion: Server: diff --git a/Assets/PhysicsMaterials/Friction.physicMaterial b/Assets/PhysicsMaterials/Friction.physicMaterial index e16c3ca..5bd0466 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.069989614 + dynamicFriction: 0.06998743 staticFriction: 1 bounciness: 0.3 frictionCombine: 3 diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index 33dc161..249e8c5 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, z: 0, w: 1} + m_LocalRotation: {x: 0, y: 0.6439234, z: 0, w: 0.76509005} 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: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 80.17, 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, z: 0, w: 1} + m_LocalRotation: {x: 0, y: 0.6477876, z: 0, w: 0.7618211} 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: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 80.75, z: 0} --- !u!1 &2062866431 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Menu.unity b/Assets/Scenes/Menu.unity index 231cfe1..135ca63 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.00023456286, y: 0} + m_AnchoredPosition: {x: 0.00019626642, y: 0} m_SizeDelta: {x: -943, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &54820778 @@ -4018,7 +4018,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1319984346} - - component: {fileID: 1319984349} - component: {fileID: 1319984348} m_Layer: 0 m_Name: NetworkManager @@ -4062,18 +4061,6 @@ 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 @@ -6065,6 +6052,7 @@ GameObject: m_Component: - component: {fileID: 2038445526} - component: {fileID: 2038445525} + - component: {fileID: 2038445527} m_Layer: 0 m_Name: NetworkRunner m_TagString: Untagged @@ -6099,6 +6087,18 @@ 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 0c74d17..f2afc3b 100644 --- a/Assets/Scripts/FusionLauncher.cs +++ b/Assets/Scripts/FusionLauncher.cs @@ -8,6 +8,9 @@ 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 { @@ -63,6 +66,7 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks IEnumerator AutoRefreshLobbyList() { + yield return new WaitForSeconds(2f); while (true) { RefreshLobbyList(); @@ -112,31 +116,20 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks // —————— RESET / CREATE FRESH RUNNER —————— private async Task EnsureFreshRunner() { - // Reset flags - playerCount = 0; - gameplayLoaded = false; - connectedToServer = false; + // … your existing shutdown/destroy logic … - // 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); // keep it alive across scenes + DontDestroyOnLoad(go); + // 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); } @@ -146,33 +139,29 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks var name = lobbyNameInput.text.Trim(); if (string.IsNullOrEmpty(name)) { - Debug.LogWarning("Empty lobby name!"); + Debug.LogWarning("[Host] Empty lobby name, not creating."); 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, + Scene = SceneRef.FromIndex(SceneManager.GetActiveScene().buildIndex), 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 failed: {res.ShutdownReason}"); + Debug.LogError($"[Host] ✖ Host failed: {res.ShutdownReason}"); } } @@ -203,13 +192,39 @@ public class FusionLauncher : MonoBehaviour, INetworkRunnerCallbacks } } - // —————— REFRESH LOBBY LIST —————— + private bool isJoiningLobby = false; + + + [ContextMenu("RefreshLobbyList")] public void RefreshLobbyList() { - if (!connectedToServer) return; - //sessionListUIHandler.ClearList(); - runner.JoinSessionLobby(SessionLobby.ClientServer); - } + // 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); + //} // —————— FUSION CALLBACKS —————— public void OnConnectedToServer(NetworkRunner r)