/// <summary> /// 派发事件 /// </summary> /// <param name="eventType">事件类型</param> /// <param name="data">事件数据</param> /// <returns>通知的订阅者数量</returns> public int dispatchEvent(string eventType, ISFEventData data = null) { SFEvent e = new SFEvent(eventType, m_target); e.data = data; return(dispatchEvent(e)); }
void onJoin(SFEvent e) { SFRequestMsgJoinRoom req = new SFRequestMsgJoinRoom(); SFNetworkManager.instance.sendMessage(req); m_view.btnJoin.interactable = false; m_info = "正在搜索房间,请稍后..."; }
void onOk(SFEvent e) { m_view.lblTitle.text = "Button Clicked!"; m_view.btnOk.SetText("修改了button的Text"); var md5 = SFUtils.getMD5("Abcd.1234@BA!"); SFUtils.log(SFUtils.getMD5(md5)); }
public void onLogout(SFEvent e) { SFRequestMsgUnitLogin req = new SFRequestMsgUnitLogin(); req.loginOrOut = 2; SFNetworkManager.instance.sendMessage(req); m_view.btnLogout.interactable = false; }
void onHeartbeat(SFEvent e) { var now = DateTime.Now; var diff = now.Subtract(m_heartbeatStartTime); m_ping = diff.TotalMilliseconds; SFUtils.log("ping: {0:F2}", m_ping); dispatcher.dispatchEvent(SFEvent.EVENT_NETWORK_PING); }
void onLifeChange(SFEvent e) { var data = e.data as SFUnitLifeChange; if (data.uid == m_uid) { m_view.proLife.setProgress(1.0f * data.curLife / data.maxLife); } }
void onDisconnect(SFEvent e) { if (!m_mgr.isReady()) { m_infoMsg = "本来就没有连接"; return; } m_mgr.uninit(); m_infoMsg = "连接已断开"; }
void onJoinResult(SFEvent e) { var data = e.data as SFResponseMsgJoinRoom; if (data.retCode == 0) { m_willSwitch = true; m_info = "已找到房间,正在切换场景..."; } }
void onLifeChange(SFEvent e) { var data = e.data as SFUnitLifeChange; if (data.uid == SFUserData.instance.uid) { m_view.proLife.setProgress(1.0f * data.curLife / data.maxLife); SFUtils.log("当前血量{0}/{1}", data.curLife, data.maxLife); } }
/// <summary> /// 派发事件 /// </summary> /// <param name="e">事件</param> /// <returns>通知的订阅者数量</returns> public int dispatchEvent(SFEvent e) { int count = 0; if (m_dictListeners.ContainsKey(e.eventType)) { var pairs = m_dictListeners[e.eventType]; for (int i = pairs.Count - 1; i >= 0; --i) { pairs[i].selector(e); count += 1; } } return(count); }
/// <summary> /// 派发事件 /// </summary> /// <param name="e">事件</param> /// <returns>通知的订阅者数量</returns> public int dispatchEvent(SFEvent e) { int count = 0; if (m_dictListeners.ContainsKey(e.eventType)) { var selectors = m_dictListeners[e.eventType]; foreach (var item in selectors) { item.selector(e); count += 1; } } return(count); }
void onLogoutResult(SFEvent e) { var data = e.data as SFResponseMsgUnitLogin; if (data.retCode == 0) { SFNetworkManager.instance.uninit(); m_view.removeView(); SFSceneManager.addView("vwLogin"); } else { SFUtils.logWarning("登出失败"); } }
void onConnectResult(SFEvent e) { var retCode = e.data as SFSimpleEventData; if (retCode.intVal == 0) { m_infoMsg = "连接成功,正在登陆..."; doLogin(); } else { m_infoMsg = "无法连接到服务器"; m_willReset = true; } }
void onLoginResult(SFEvent e) { var data = e.data as SFResponseMsgUnitLogin; if (data.retCode == 0) { m_infoMsg = "登陆成功,正在加载游戏..."; m_willSwitch = true; } else { m_infoMsg = string.Format("登陆失败,错误码:{0}", data.retCode); m_willReset = true; } }
void onLoginResult(SFEvent e) { var data = e.data as SFResponseMsgUnitLogin; if (data.retCode == 0) { m_infoMsg = "登陆成功..."; m_view.removeView(); SFSceneManager.addView("vwMain"); } else { m_infoMsg = string.Format("登陆失败,错误码:{0}", data.retCode); m_willReset = true; } }
void onSend(SFEvent e) { if (m_mgr.isReady()) { string content = m_view.txtMsg.text; SFUtils.log("正在发送 " + content); SFRequestMsgUnitLogin req = new SFRequestMsgUnitLogin(); req.uid = "abc"; req.loginOrOut = 1; m_mgr.sendMessage(req); } else { m_infoMsg = "服务器未连接"; } }
void onRemoteUsers(SFEvent e) { var data = e.data as SFResponseMsgNotifyRemoteUsers; if (data.retCode == 0) { SFBattleData.instance.enterBattle_mapId = data.mapId; SFBattleData.instance.enterBattle_remoteUsers = data.users; SFBattleData.instance.enterBattle_posX = data.posX; SFBattleData.instance.enterBattle_posY = data.posY; SFBattleData.instance.enterBattle_rotation = data.rotation; SFBattleData.instance.enterBattle_maxLife = data.maxLife; SFBattleData.instance.enterBattle_initRunTime = data.runTime; SFUtils.log("玩家初始坐标:({0}, {1}),rot={2}", data.posX, data.posY, data.rotation); } }
void onUnitAddRemove(SFEvent e) { var data = e.data as SFUnitAddRemove; if (data.addOrRemove == true) { // 添加角色 var newGO = m_view.scrLeftPlayers.AddItem(SFSceneManager.getView("vwUnitStatusItem")); if (newGO != null) { var item = newGO.GetComponent <SFUnitStatusItemView>().getPresenter(); item.init(data); } } else { // 移除角色 } }
void onLogin(SFEvent e) { string username = m_view.txtUsername.text; if (username == "") { m_infoMsg = "用户名不能为空"; return; } SFUserData.instance.uid = username; m_view.txtUsername.interactable = false; m_view.btnLogin.interactable = false; m_infoMsg = "正在连接服务器..."; SFNetworkManager.instance.init(); SFNetworkManager.instance.dispatcher.addEventListener(SFEvent.EVENT_NETWORK_READY, onConnectResult); SFNetworkManager.instance.dispatcher.addEventListener(SFEvent.EVENT_NETWORK_INTERRUPTED, result => { m_infoMsg = "网络连接中断"; m_willReset = true; }); SFNetworkManager.instance.dispatcher.addEventListener(SFResponseMsgUnitLogin.pName, onLoginResult); }
void onConnect(SFEvent e) { if (m_mgr.isReady()) { m_infoMsg = "已经连接过了"; return; } m_infoMsg = "正在连接服务器"; m_mgr.init(); m_mgr.dispatcher.addEventListener(this, SFEvent.EVENT_NETWORK_READY, result => { SFSimpleEventData retCode = result.data as SFSimpleEventData; if (retCode.intVal == 0) { m_infoMsg = "服务器连接成功"; } else { m_infoMsg = "服务器连接失败"; } }); m_mgr.dispatcher.addEventListener(this, SFEvent.EVENT_NETWORK_INTERRUPTED, onInterrupt); m_mgr.dispatcher.addEventListener(this, SFResponseMsgUnitLogin.pName, onRecvMsg); }
void onMenu(SFEvent e) { m_view.scrSkills.AddItem(SFSceneManager.getView("vwSkillItem")); }
public void onLogout(SFEvent e) { SFSceneManager.addView("vwTest", m_view.imgPos.transform); }
void onRecvMsg(SFEvent e) { m_infoMsg = "登陆成功"; }
void onInterrupt(SFEvent e) { m_infoMsg = "网络连接中断"; }
void onOk(SFEvent e) { SceneManager.LoadScene("SceneTitle"); }
void onJoin(SFEvent e) { }
void onHost(SFEvent e) { }
void onClose(SFEvent e) { m_view.removeView(); }
void onPing(SFEvent e) { m_view.lblPing.text = string.Format("Ping: {0:F2}ms", SFNetworkManager.instance.ping); }