Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        void onJoin(SFEvent e)
        {
            SFRequestMsgJoinRoom req = new SFRequestMsgJoinRoom();

            SFNetworkManager.instance.sendMessage(req);
            m_view.btnJoin.interactable = false;
            m_info = "正在搜索房间,请稍后...";
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        public void onLogout(SFEvent e)
        {
            SFRequestMsgUnitLogin req = new SFRequestMsgUnitLogin();

            req.loginOrOut = 2;
            SFNetworkManager.instance.sendMessage(req);
            m_view.btnLogout.interactable = false;
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 7
0
 void onDisconnect(SFEvent e)
 {
     if (!m_mgr.isReady())
     {
         m_infoMsg = "本来就没有连接";
         return;
     }
     m_mgr.uninit();
     m_infoMsg = "连接已断开";
 }
Ejemplo n.º 8
0
        void onJoinResult(SFEvent e)
        {
            var data = e.data as SFResponseMsgJoinRoom;

            if (data.retCode == 0)
            {
                m_willSwitch = true;
                m_info       = "已找到房间,正在切换场景...";
            }
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        /// <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);
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
        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("登出失败");
            }
        }
Ejemplo n.º 13
0
        void onConnectResult(SFEvent e)
        {
            var retCode = e.data as SFSimpleEventData;

            if (retCode.intVal == 0)
            {
                m_infoMsg = "连接成功,正在登陆...";
                doLogin();
            }
            else
            {
                m_infoMsg   = "无法连接到服务器";
                m_willReset = true;
            }
        }
Ejemplo n.º 14
0
        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;
            }
        }
Ejemplo n.º 15
0
        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;
            }
        }
Ejemplo n.º 16
0
 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 = "服务器未连接";
     }
 }
Ejemplo n.º 17
0
        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);
            }
        }
Ejemplo n.º 18
0
        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
            {
                // 移除角色
            }
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
 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);
 }
Ejemplo n.º 21
0
 void onMenu(SFEvent e)
 {
     m_view.scrSkills.AddItem(SFSceneManager.getView("vwSkillItem"));
 }
Ejemplo n.º 22
0
 public void onLogout(SFEvent e)
 {
     SFSceneManager.addView("vwTest", m_view.imgPos.transform);
 }
Ejemplo n.º 23
0
 void onRecvMsg(SFEvent e)
 {
     m_infoMsg = "登陆成功";
 }
Ejemplo n.º 24
0
 void onInterrupt(SFEvent e)
 {
     m_infoMsg = "网络连接中断";
 }
Ejemplo n.º 25
0
 void onOk(SFEvent e)
 {
     SceneManager.LoadScene("SceneTitle");
 }
Ejemplo n.º 26
0
 void onJoin(SFEvent e)
 {
 }
Ejemplo n.º 27
0
 void onHost(SFEvent e)
 {
 }
Ejemplo n.º 28
0
 void onClose(SFEvent e)
 {
     m_view.removeView();
 }
Ejemplo n.º 29
0
 void onPing(SFEvent e)
 {
     m_view.lblPing.text = string.Format("Ping: {0:F2}ms", SFNetworkManager.instance.ping);
 }