From 343f12b4901e4b2b2034f87dccda468359d20f70 Mon Sep 17 00:00:00 2001 From: aarijimam <35100854+aarijimam@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:25:20 +0500 Subject: [PATCH] refactor: onquit uses player service now --- .../modules/Interfaces/IPlayerBase.cs | 2 ++ .../BrowserMode/BrowserMockPlayerService.cs | 4 ++-- .../modules/Player/LocalPlayerService.cs | 5 +++++ Assets/PlayroomKit/modules/Player/Player.cs | 17 +---------------- .../PlayroomKit/modules/Player/PlayerService.cs | 2 +- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Assets/PlayroomKit/modules/Interfaces/IPlayerBase.cs b/Assets/PlayroomKit/modules/Interfaces/IPlayerBase.cs index 9488b27..2ace0e9 100644 --- a/Assets/PlayroomKit/modules/Interfaces/IPlayerBase.cs +++ b/Assets/PlayroomKit/modules/Interfaces/IPlayerBase.cs @@ -22,6 +22,8 @@ public interface IPlayerBase public void WaitForState(string stateKey, Action onStateSetCallback = null); protected static Action onKickCallBack = null; + + public void InvokePlayerOnQuitCallback(string id); } } } diff --git a/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockPlayerService.cs b/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockPlayerService.cs index c9ed84a..e8b1d81 100644 --- a/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockPlayerService.cs +++ b/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockPlayerService.cs @@ -130,14 +130,14 @@ void Unsubscribe() return Unsubscribe; } - public void OnQuitWrapperCallback(string id) + private void OnQuitWrapperCallback(string id) { if (OnQuitCallbacks != null) foreach (var callback in OnQuitCallbacks) callback?.Invoke(id); } - internal void InvokePlayerOnQuitCallback(string id) + public void InvokePlayerOnQuitCallback(string id) { OnQuitWrapperCallback(id); } diff --git a/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs b/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs index 3c43c9e..ab10d0b 100644 --- a/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs +++ b/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs @@ -117,6 +117,11 @@ public void WaitForState(string stateKey, Action onStateSetCallback = nu CallbackManager.RegisterCallback(onStateSetCallback, key); DebugLogger.Log($"Callback registered, the key is: {key}"); } + + public void InvokePlayerOnQuitCallback(string id) + { + Debug.LogWarning("InvokePlayerOnQuitCallback is only supported on build"); + } } } } diff --git a/Assets/PlayroomKit/modules/Player/Player.cs b/Assets/PlayroomKit/modules/Player/Player.cs index 4f28c6d..fb431d3 100644 --- a/Assets/PlayroomKit/modules/Player/Player.cs +++ b/Assets/PlayroomKit/modules/Player/Player.cs @@ -139,22 +139,7 @@ public void WaitForState(string StateKey, Action onStateSetCallback = nu public void InvokePlayerOnQuitCallback() { - if (_playerService is PlayerService playerService) - { - playerService.InvokePlayerOnQuitCallback(id); - } - #if UNITY_EDITOR || DEBUG - else if (_playerService is BrowserMockPlayerService playerService2) - { - playerService2.InvokePlayerOnQuitCallback(id); - } - #endif - else - { - Debug.LogWarning("InvokePlayerOnQuitCallback is only supported on build"); - } - - + _playerService.InvokePlayerOnQuitCallback(id); } //DI END diff --git a/Assets/PlayroomKit/modules/Player/PlayerService.cs b/Assets/PlayroomKit/modules/Player/PlayerService.cs index 1dddc4b..99744e6 100644 --- a/Assets/PlayroomKit/modules/Player/PlayerService.cs +++ b/Assets/PlayroomKit/modules/Player/PlayerService.cs @@ -140,7 +140,7 @@ void Unsubscribe() return Unsubscribe; } - internal void InvokePlayerOnQuitCallback(string id) + public void InvokePlayerOnQuitCallback(string id) { OnQuitWrapperCallback(id); }