Exemple #1
0
    /// <summary>
    /// 更新网络玩家数据
    /// </summary>
    /// <param name="protocol"></param>
    public void UpdatePlayerInfo(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string playerName    = p.GetString(startIndex, ref startIndex);
        float  HP            = p.GetFloat(startIndex, ref startIndex);
        float  posX          = p.GetFloat(startIndex, ref startIndex);
        float  posY          = p.GetFloat(startIndex, ref startIndex);
        float  posZ          = p.GetFloat(startIndex, ref startIndex);
        float  rotX          = p.GetFloat(startIndex, ref startIndex);
        float  rotY          = p.GetFloat(startIndex, ref startIndex);
        float  rotZ          = p.GetFloat(startIndex, ref startIndex);
        string CurrentAction = p.GetString(startIndex, ref startIndex);

        //自己的消息
        if (playerName == NetworkManager.PlayerName)
        {
            BagManager.Instance.characterStatus.HP = HP;
        }

        if (ScenePlayers.ContainsKey(playerName))
        {
            ScenePlayers[playerName].SetPlayerInfo(HP, CurrentAction);
            ScenePlayers[playerName].SetPlayerTransform(posX, posY, posZ, rotX, rotY, rotZ);
        }
    }
Exemple #2
0
    /// <summary>
    /// 获取玩家列表回调
    /// </summary>
    public void OnGetPlayersInfo(BaseProtocol baseProtocol)
    {
        BytesProtocol p          = baseProtocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int Playernum = p.GetInt(startIndex, ref startIndex);

        UnityEngine.Object playerprefab = Resources.Load("NetPlayerPrefab");
        GameObject         tmp_player   = null;

        for (int i = 0; i < Playernum; i++)
        {
            string playerName = p.GetString(startIndex, ref startIndex);
            //自己不需要更新
            if (playerName != NetworkManager.PlayerName)
            {
                tmp_player      = Instantiate(playerprefab) as GameObject;
                tmp_player.name = playerName;
                tmp_player.transform.SetParent(transform);

                NetworkPlayer nPlayer = tmp_player.GetComponent <NetworkPlayer>();
                nPlayer.SetPlayerName(playerName);
                ScenePlayers.Add(playerName, nPlayer);
                nPlayer.LastUpdateTime = NetworkManager.GetTimeStamp();
            }
        }
    }
Exemple #3
0
    /// <summary>
    /// 玩家死亡处理
    /// </summary>
    /// <param name="protocol"></param>
    private void OnPlayerKilled(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        //杀手名
        string KillerName = p.GetString(startIndex, ref startIndex);
        //被杀玩家名
        string KilledPlayerName = p.GetString(startIndex, ref startIndex);

        //玩家死亡处理
        if (KilledPlayerName == NetworkManager.PlayerName)
        {
            UIManager.Instance.ShowUI(UIid.FinishUI);
            object[] param = new object[3];
            param[0] = "无畏之争——无谓之争";
            param[1] = "你被 " + KillerName + " 击杀";
            param[2] = " ";
            MessageCenter.Send_Multparam(EMessageType.FinishUI, param);
            CameraBase.Instance.isFollowing = false;
            return;
        }

        DelPlayer(KilledPlayerName);
    }
Exemple #4
0
    private void OnPlayerEquipWeapon(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string Playername = p.GetString(startIndex, ref startIndex);
        int    ItemID     = p.GetInt(startIndex, ref startIndex);

        if (ScenePlayers.ContainsKey(Playername))
        {
            ScenePlayers[Playername].SetPlayerWeapon(ItemID);
        }
    }
Exemple #5
0
    private void OnPlayerEquipHelmet(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string Playername = p.GetString(startIndex, ref startIndex);
        int    ItemID     = p.GetInt(startIndex, ref startIndex);

        Debug.Log("网络玩家 " + Playername + "  又要威又要戴头盔");
        if (ScenePlayers.ContainsKey(Playername))
        {
            ScenePlayers[Playername].SetPlayerHelmet(ItemID);
        }
    }
Exemple #6
0
    private void OnPlayerGetBuff(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string playerName = p.GetString(startIndex, ref startIndex);
        int    bufftype   = p.GetInt(startIndex, ref startIndex);
        float  buffTime   = p.GetFloat(startIndex, ref startIndex);

        if (playerName == NetworkManager.PlayerName)
        {
            CameraBase.Instance.player.GetComponent <PlayerController>().GetDeBuffInTime((BuffType)bufftype, buffTime, BagManager.Instance.characterStatus);
        }
    }
    private void OnConnectCallback(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;
        string        MethodName = p.GetString(startIndex, ref startIndex);
        int           returnCode = p.GetInt(startIndex, ref startIndex);

        if (returnCode == 0)
        {
            Debug.Log("连接成功");

            UIManager.Instance.ShowUI(UIid.MainUI);
            MessageCenter.Send(EMessageType.PlayerName, inputField.text);
            UIManager.Instance.HideTheUI(this.uiId, () => { });
        }
        else
        {
            Debug.Log("连接失败");
            UIManager.Instance.ShowUI(UIid.TipsUI);
            object[] param = new object[2];
            param[0] = "连接失败\n可能原因:昵称已被使用、服务器问题 或 网络故障";
            param[1] = "知道了";
            MessageCenter.Send_Multparam(EMessageType.TipsUI, param);
        }
    }
Exemple #8
0
    /// <summary>
    /// 获取地图道具随机数种子
    /// </summary>
    private void OnGetMapItemDataBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        Seed = p.GetInt(startIndex, ref startIndex);

        object[] param = new object[2];
        param[0] = "正在接收道具数据...";
        param[1] = 0;
        MessageCenter.Send_Multparam(EMessageType.LoadingUI, param);

        if (Seed != 0)
        {
            //220个物品生成点的随机数
            RandomList = InitTotalProbabilityValue(ProbabilityValue);
            param[0]   = "道具数据接收完毕";
            param[1]   = 0;
            MessageCenter.Send_Multparam(EMessageType.LoadingUI, param);

            GenerateItem();
        }
        else
        {
            Debug.LogError("Seed异常 " + Seed.ToString() + " 无法加载");
        }
    }
Exemple #9
0
    /// <summary>
    /// 魔法回调
    /// </summary>
    /// <param name="protocol"></param>
    private void OnPlayerMagicBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string MagicName = p.GetString(startIndex, ref startIndex);
        float  posX      = p.GetFloat(startIndex, ref startIndex);
        float  posY      = p.GetFloat(startIndex, ref startIndex);
        float  posZ      = p.GetFloat(startIndex, ref startIndex);
        float  rotX      = p.GetFloat(startIndex, ref startIndex);
        float  rotY      = p.GetFloat(startIndex, ref startIndex);
        float  rotZ      = p.GetFloat(startIndex, ref startIndex);

        NetPoolManager.Instantiate(MagicName, new Vector3(posX, posY, posZ), Quaternion.Euler(rotX, rotY, rotZ));
    }
Exemple #10
0
    private void OnStartGameBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        UIManager.Instance.ShowUI(UIid.LoadingUI);
        MessageCenter.Send(EMessageType.LoadingScene, new object());
    }
Exemple #11
0
    public void OnCirclefieldTimeBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int HoldTime = p.GetInt(startIndex, ref startIndex);

        //HUDUI倒计时显示
        countdownTime = HoldTime;
        Moving        = false;
    }
    /// <summary>
    /// 魔法回调
    /// </summary>
    /// <param name="protocol"></param>
    private void OnPlayerMagicBack(BaseProtocol protocol)
    {
        BytesProtocol p = protocol as BytesProtocol;
        RaycastHit    hitInfo;
        Vector3       targetPoint;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string MagicName = p.GetString(startIndex, ref startIndex);
        float  posX      = p.GetFloat(startIndex, ref startIndex);
        float  posY      = p.GetFloat(startIndex, ref startIndex);
        float  posZ      = p.GetFloat(startIndex, ref startIndex);
        float  rotX      = p.GetFloat(startIndex, ref startIndex);
        float  rotY      = p.GetFloat(startIndex, ref startIndex);
        float  rotZ      = p.GetFloat(startIndex, ref startIndex);

        GameObject go = NetPoolManager.Instantiate(MagicName, new Vector3(posX, posY, posZ), Quaternion.Euler(rotX, rotY, rotZ));

        go.GetComponent <MagicBehaviour>().isHit = true;
        Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
    }
Exemple #13
0
    /// <summary>
    /// 开门
    /// </summary>
    /// <param name="protocol"></param>
    public void OnDoorOpen(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int DoorID = p.GetInt(startIndex, ref startIndex);

        if (itemSpawnPoint.DoorSpawnPoints[DoorID] != null)
        {
            Doors[DoorID].gameObject.GetComponent <DoorControl>().ControlDoor();
        }
    }
Exemple #14
0
    /// <summary>
    /// 游戏物品被拾取处理
    /// </summary>
    /// <param name="protocol"></param>
    public void OnPickItem(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int GroundItemID = p.GetInt(startIndex, ref startIndex);

        if (Items.ContainsKey(GroundItemID))
        {
            Items[GroundItemID].Hide();
        }
    }
Exemple #15
0
    private void OnLeaveRoomBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int returnCode = p.GetInt(startIndex, ref startIndex);

        if (returnCode == 0)
        {
            UIManager.Instance.ShowUI(UIid.MainUI);
        }
    }
Exemple #16
0
    /// <summary>
    /// 所有人加载完毕后的处理
    /// </summary>
    /// <param name="protocol"></param>
    public void OnAllPlayerLoaded(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        UIManager.Instance.HideTheUI(UIid.LoginUI, delegate { });
        UIManager.Instance.HideTheUI(UIid.MainUI, delegate { });
        UIManager.Instance.HideTheUI(UIid.RoomUI, delegate { });
        UIManager.Instance.HideTheUI(UIid.LoadingUI, delegate { });
        UIManager.Instance.ShowUI(UIid.HUDUI);

        NetworkManager.SendGetPlayersInfo();
    }
Exemple #17
0
    private void OnPlayerSuccess(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        UIManager.Instance.ShowUI(UIid.FinishUI);
        object[] param = new object[3];
        param[0] = "无畏之争,无胃之争";
        param[1] = "今晚不会有人抢你的鸡吃了";
        param[2] = "胜利者 ";
        MessageCenter.Send_Multparam(EMessageType.FinishUI, param);
        CameraBase.Instance.isFollowing = false;
    }
Exemple #18
0
    private void OnPlayerDead(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        string KilledPlayerName = p.GetString(startIndex, ref startIndex);

        if (KilledPlayerName == NetworkManager.PlayerName)
        {
            if (CameraBase.Instance.isEscape == false)
            {
                UIManager.Instance.ShowUI(UIid.FinishUI);
                object[] param = new object[3];
                param[0] = "无畏之争,无谓之争";
                param[1] = "你被暗影毒杀";
                param[2] = " ";
                MessageCenter.Send_Multparam(EMessageType.FinishUI, param);
                CameraBase.Instance.isFollowing = false;
            }
        }
        DelPlayer(KilledPlayerName);
    }
Exemple #19
0
    /// <summary>
    /// 下降点回调
    /// </summary>
    public void OnDroppointBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int index = p.GetInt(startIndex, ref startIndex);

        if (DebugMode == false)
        {
            CameraBase.Instance.gameObject.transform.position = Droppoint[index].position;
            CameraBase.Instance.player.transform.position     = Droppoint[index].position;
        }
    }
Exemple #20
0
    private void GetRoomInfo(BaseProtocol protocol)
    {
        for (int j = 0; j < 10; j++)
        {
            MemberListItems[j].SetActive(false);
        }
        MemberListItem memberListItem;
        BytesProtocol  p          = protocol as BytesProtocol;
        int            startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int PlayerNum = p.GetInt(startIndex, ref startIndex);

        for (int i = 0; i < PlayerNum; i++)
        {
            memberListItem = MemberListItems[i].GetComponent <MemberListItem>();
            string playerName = p.GetString(startIndex, ref startIndex);
            memberListItem.Text_PlayerName.text = playerName;

            int isMaster = p.GetInt(startIndex, ref startIndex);

            if (playerName == NetworkManager.PlayerName)
            {
                if (isMaster == 1)
                {
                    memberListItem.Text_Rank.text = "房主";
                    Btn_Start.gameObject.SetActive(true);
                }
                else
                {
                    Btn_Start.gameObject.SetActive(false);
                }
            }

            MemberListItems[i].SetActive(true);
        }
    }
Exemple #21
0
    /// <summary>
    /// 接收到物品被扔消息
    /// </summary>
    public void OnDropItem(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int   GroundItemID = p.GetInt(startIndex, ref startIndex);
        float posX         = p.GetFloat(startIndex, ref startIndex);
        float posY         = p.GetFloat(startIndex, ref startIndex);
        float posZ         = p.GetFloat(startIndex, ref startIndex);

        if (Items.ContainsKey(GroundItemID))
        {
            Items[GroundItemID].Show();
            Items[GroundItemID].transform.position = new Vector3(posX, posY, posZ);
        }
    }
Exemple #22
0
    private void OnRequestStartGameBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int returnCode = p.GetInt(startIndex, ref startIndex);

        Debug.Log("RequestStartGameBack Return code: " + returnCode.ToString());
        if (returnCode == -1)
        {
            UIManager.Instance.ShowUI(UIid.TipsUI);
            object[] param = new object[2];
            param[0] = "无法开始,人数不够";
            param[1] = "返回";
            MessageCenter.Send_Multparam(EMessageType.TipsUI, param);
        }
    }
Exemple #23
0
    private void GetRoomList(BaseProtocol protocol)
    {
        for (int j = 0; j < RoomList.content.childCount; j++)
        {
            Destroy(RoomList.content.GetChild(j).gameObject);
        }

        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;
        string        MethodName = p.GetString(startIndex, ref startIndex);
        int           RoomCount  = p.GetInt(startIndex, ref startIndex);

        for (int i = 0; i < RoomCount; i++)

        {
            int playerNum  = p.GetInt(startIndex, ref startIndex);
            int RoomStatus = p.GetInt(startIndex, ref startIndex);
            AddRoomListItem(i, playerNum, RoomStatus);
        }
    }
Exemple #24
0
    /// <summary>
    /// 毒圈回调
    /// </summary>
    /// <param name="protocol"></param>
    public void OnCirclefieldBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        float X             = p.GetFloat(startIndex, ref startIndex);
        float Y             = p.GetFloat(startIndex, ref startIndex);
        float shrinkPercent = p.GetFloat(startIndex, ref startIndex);
        int   Movetime      = p.GetInt(startIndex, ref startIndex);

        //HUDUI倒计时显示
        countdownTime = Movetime;
        Moving        = true;
        CircleCenter  = new Vector3(X, 0, Y);

        isBegin = true;
        iTween.ScaleTo(Circlefield, iTween.Hash("x", Circlefield.transform.localScale.x * shrinkPercent, "y", Circlefield.transform.localScale.y * shrinkPercent, "time", Movetime, "easeType", iTween.EaseType.linear));
        iTween.MoveTo(Circlefield, iTween.Hash("position", new Vector3(X, 0, Y), "time", Movetime, "easeType", iTween.EaseType.linear));
    }
Exemple #25
0
    private void OnJoinRoomBack(BaseProtocol protocol)
    {
        BytesProtocol p          = protocol as BytesProtocol;
        int           startIndex = 0;

        p.GetString(startIndex, ref startIndex);
        int returnCode = p.GetInt(startIndex, ref startIndex);

        if (returnCode == 0)
        {
            UIManager.Instance.ShowUI(UIid.RoomUI);
        }
        else
        {
            UIManager.Instance.ShowUI(UIid.TipsUI);
            object[] param = new object[2];
            param[0] = "加入房间失败";
            param[1] = "返回";
            MessageCenter.Send_Multparam(EMessageType.TipsUI, param);
        }
    }