From d10261e77ce0701d234476f58cd4a08caa44a93b Mon Sep 17 00:00:00 2001 From: Vu Luong Date: Sun, 20 Aug 2023 20:20:44 +1000 Subject: [PATCH] update EzyDefaultController (#37) --- unity/EzyDefaultController.cs | 78 +++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/unity/EzyDefaultController.cs b/unity/EzyDefaultController.cs index 2dd78ce..86ec5f7 100644 --- a/unity/EzyDefaultController.cs +++ b/unity/EzyDefaultController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using com.tvd12.ezyfoxserver.client.config; +using com.tvd12.ezyfoxserver.client.evt; using com.tvd12.ezyfoxserver.client.logger; using com.tvd12.ezyfoxserver.client.support; using UnityEngine; @@ -16,7 +17,8 @@ public class EzyDefaultController : MonoBehaviour protected EzySocketProxy socketProxy; protected EzyAppProxy appProxy; - private readonly List> handlers = new(); + private readonly List socketHandlers = new(); + private readonly List> appHandlers = new(); protected static readonly EzyLogger LOGGER = EzyUnityLoggerFactory .getLogger(); @@ -53,9 +55,65 @@ protected void OnEnable() ); } + protected void OnLoginSuccess(EzySocketProxyDataHandler handler) + { + socketHandlers.Add( + socketProxy.onLoginSuccess(handler) + ); + } + + protected void OnLoginError(EzySocketProxyDataHandler handler) + { + socketHandlers.Add( + socketProxy.onLoginError(handler) + ); + } + + protected void OnUdpHandshake(EzySocketProxyDataHandler handler) + { + socketHandlers.Add( + socketProxy.onUdpHandshake(handler) + ); + } + + protected void OnAppAccessed(EzyAppProxyDataHandler handler) + { + socketHandlers.Add( + socketProxy.onAppAccessed(handler) + ); + } + + protected void OnDisconnected(EzySocketProxyEventHandler handler) + { + socketHandlers.Add( + socketProxy.onDisconnected(handler) + ); + } + + protected void OnReconnecting(EzySocketProxyEventHandler handler) + { + socketHandlers.Add( + socketProxy.onReconnecting(handler) + ); + } + + protected void OnPingLost(EzySocketProxyEventHandler handler) + { + socketHandlers.Add( + socketProxy.onPingLost(handler) + ); + } + + protected void OnTryConnect(EzySocketProxyEventHandler handler) + { + socketHandlers.Add( + socketProxy.onTryConnect(handler) + ); + } + protected void AddHandler(String cmd, EzyAppProxyDataHandler handler) { - handlers.Add( + appHandlers.Add( new Tuple(cmd, appProxy.on(cmd, handler)) ); } @@ -63,7 +121,21 @@ protected void AddHandler(String cmd, EzyAppProxyDataHandler handler) protected virtual void OnDestroy() { LOGGER.debug("OnDestroy"); - foreach (Tuple tuple in handlers) + UnbindSocketHandlers(); + UnbindAppHandlers(); + } + + protected virtual void UnbindSocketHandlers() + { + foreach (var socketProxyHandler in socketHandlers) + { + socketProxy.unbind(socketProxyHandler); + } + } + + protected virtual void UnbindAppHandlers() + { + foreach (Tuple tuple in appHandlers) { appProxy.unbind(tuple.Item1, tuple.Item2); }