Esempio n. 1
0
 public void OnNetReceivePlayerLoginBoxMsg(PlayerWeiXinData val)
 {
     Debug.Log("Unity:" + "OnNetReceivePlayerLoginBoxMsg -> userName == " + val.userName + ", userId == " + val.userId);
     if (OnEventPlayerLoginBox != null)
     {
         OnEventPlayerLoginBox(val);
     }
 }
    /// <summary>
    /// 收到WebSocket网络消息.
    /// </summary>
    public void OnMessageReceived(string message)
    {
        Debug.Log("OnMessageReceived -> message == " + message);
        if (IsCheckXinTiaoMsg)
        {
            if (message == m_XinTiaoReturnMsg)
            {
#if UNITY_EDITOR
                Debug.Log("Unity:" + "XinTiao Check Success!");
#endif
                IsCheckXinTiaoMsg = false;
            }
            return;
        }

        JsonData jd      = JsonMapper.ToObject(message);
        string   msgType = jd["type"].ToString();
        switch (msgType)
        {
        case "userInfo":     //玩家登陆盒子信息.
        {
            //{"data":{"sex":1,"headUrl":"http://game.hdiandian.com/h5/public/image/head/93124.jpg","userName":"******","userId":"93124"},"type":"userInfo"}
            PlayerWeiXinData playerDt = new PlayerWeiXinData();
            playerDt.sex      = jd["data"]["sex"].ToString();
            playerDt.headUrl  = jd["data"]["headUrl"].ToString();
            playerDt.userName = jd["data"]["userName"].ToString();
            playerDt.userId   = Convert.ToInt32(jd["data"]["userId"].ToString());
            OnNetReceivePlayerLoginBoxMsg(playerDt);
            break;
        }

        case "ReleasePlayer":     //玩家退出盒子或其他消息.
        {
            //{"type":"ReleasePlayer","userId":"93124"}
            int userId = Convert.ToInt32(jd["userId"].ToString());
            OnNetReceivePlayerExitBoxMsg(userId);
            break;
        }

        case "directionAngle":     //手柄方向消息.
        {
            //{"data":53,"type":"directionAngle","userId":"93124"}
            string dirVal = jd["data"].ToString();
            int    userId = Convert.ToInt32(jd["userId"].ToString());
            OnNetReceiveDirectionAngleMsg(dirVal, userId);
            break;
        }

        case "actionOperation":     //手柄按键消息.
        {
            //{"data":"fireA","type":"actionOperation","userId":"93124"}
            string btVal  = jd["data"].ToString();
            int    userId = Convert.ToInt32(jd["userId"].ToString());
            OnNetReceiveActionOperationMsg(btVal, userId);
            break;
        }
        }
    }