using System; using UnityEngine; using Sfs2X.Core; public abstract class BaseConnector { public GardenSmartFox GardenSmartFox; public static int TcpPort = 9933; public static string Host = "121.199.20.79"; //public static string Host = "127.0.0.1"; public static string Zone = "Garden"; //public static string Zone = "GardenTest"; public Action onConnectSucceed; public Action onConnectFailed; public Action onConnectionLost; public Action onConnectResult; public BaseConnector Init(GardenSmartFox smartFox) { GardenSmartFox = smartFox; GardenSmartFox.SmartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection); GardenSmartFox.SmartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); return this; } public abstract void Connect(); public abstract void Disconnect(); public void OnConnection(BaseEvent baseEvent) { if ((bool)baseEvent.Params["success"]) { //Debug.Log("Connect succeed"); if (onConnectSucceed != null) onConnectSucceed.Invoke(baseEvent); if (onConnectResult != null) onConnectResult.Invoke(true, baseEvent); } else { //Debug.Log("Connect failed"); if (onConnectFailed != null) onConnectSucceed.Invoke(baseEvent); if (onConnectResult != null) onConnectResult.Invoke(false, baseEvent); } } public void OnConnectionLost(BaseEvent baseEvent) { //Debug.Log("ConnectionLost : " + (string)baseEvent.Params["reason"]); if (onConnectionLost != null) onConnectionLost.Invoke(baseEvent); } }