refactor: make UIService Disposable, and sure UIBootstrapper disposes it OnDisable.

This commit is contained in:
alexiscatnip
2022-08-06 02:43:06 +08:00
committed by alexiscatnip
parent 79b843b699
commit b49787d19f
2 changed files with 11 additions and 5 deletions
+7 -3
View File
@@ -15,6 +15,9 @@ namespace Raindrop.Bootstrap
private RaindropNetcom netcom => instance.Netcom;
[SerializeField] public References references;
private UIService _uisrv;
// bootstraps the UI.
private void Start()
// 1. finds all the canvasmanager and modal managers.
@@ -34,6 +37,7 @@ namespace Raindrop.Bootstrap
{
ServiceLocator.Instance.Unregister<UIService>();
}
_uisrv.Dispose();
}
@@ -58,15 +62,15 @@ namespace Raindrop.Bootstrap
Debug.LogError("loadingscreen not present");
references.ll.Init();
var uisrv = new UIService(
_uisrv = new UIService(
instance,
references.sm,
references.mm,
references.ll,
references.chatPresenter);
ServiceLocator.Instance.Register<UIService>(uisrv);
ServiceLocator.Instance.Register<UIService>(_uisrv);
uisrv.MapFacade = references.mapUI;
_uisrv.MapFacade = references.mapUI;
//3. start the chat window right.
references.chatPresenter.Initialise();
+4 -2
View File
@@ -9,7 +9,7 @@ using UnityEngine;
namespace Raindrop.Services
{
public class UIService : IGameService
public class UIService : IGameService, IDisposable
{
//UI is a service. it will always be available.
// presenters themselves provide the logic of ui-traversal.
@@ -66,8 +66,10 @@ namespace Raindrop.Services
initialise();
}
~UIService()
public void Dispose()
{
_loadingController?.Dispose();
netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);