コード例 #1
0
    public void UIRotation(Vector3 direction, float speed)
    {
        if (DataController.instance.ActorList[myIndex].CurState == RoomActorState.Dead)
        {
            return;
        }
        //int lookAt = (int)myModel.eulerAngles.y;
        NetVector3 dir    = DataController.BackNetLimetByType(direction, NetLimetType.保留1位);
        float      _speed = DataController.BackNetLimetByType(speed, NetLimetType.保留1位);
        //int rotateIndex = eulerLimet;

        ActorRotateDirection tempRotate = new ActorRotateDirection()
        {
            userIndex = DataController.instance.MyLocateIndex,
            direction = dir,
            speed     = _speed,
        };

        if (lastRotate == null ||
            dir.x != lastRotate.direction.x ||
            dir.y != lastRotate.direction.y ||
            dir.z != lastRotate.direction.z ||
            _speed != lastRotate.speed
            )
        {
            lastRotate = tempRotate;
            byte[] sendData = SerializeHelper.Serialize <ActorRotateDirection>(tempRotate);
            //SocketManager.instance.SendSave((byte)MessageConvention.rotateDirection, sendData, false);
            UDPManager.instance.SendSave((byte)MessageConvention.rotateDirection, sendData);
        }
    }
コード例 #2
0
 public void BeStop()
 {
     netMove    = new ActorMoveDirection();
     lastMove   = new ActorMoveDirection();
     netRotate  = new ActorRotateDirection();
     lastRotate = new ActorRotateDirection();
 }
コード例 #3
0
 public void SetNetDirection(ActorRotateDirection dir)
 {
     //if (myIndex == DataController.instance.MyLocateIndex)//自身在收到服务器消息之前已旋转
     //    return;
     //SetRotate(new Vector3(0, dir.rotateY, 0));//单纯的设置旋转方向就行了
     //SetRotate(SerializeHelper.BackVector(dir.direction));
     netRotate = dir;
 }
コード例 #4
0
ファイル: UdpServer2.cs プロジェクト: lxc1030/ServerTest
    public byte[] SelectMessage(byte[] data, EndPoint endPoint)
    {
        string strPoint = endPoint.ToString();

        byte[]       newBuffer = null;
        MessageXieYi xieyi     = MessageXieYi.FromBytes(data);

        if (xieyi == null)
        {
            return(newBuffer);
        }

        byte[]             tempMessageContent = xieyi.MessageContent;
        ActorMoveDirection moveDirection      = null;
        SingleRoom         room  = null;
        UDPLogin           login = null;

        //该处RoomList没有加锁
        if (ServerDataManager.instance.allRoom.RoomList.ContainsKey(allUDPs[strPoint].roomID))
        {
            room = ServerDataManager.instance.allRoom.RoomList[allUDPs[strPoint].roomID];
        }

        switch ((MessageConvention)xieyi.XieYiFirstFlag)
        {
        case MessageConvention.setUDP:
            login       = SerializeHelper.Deserialize <UDPLogin>(tempMessageContent);
            login.login = strPoint;
            allUDPs[strPoint].roomID = login.roomID;
            allUDPs[strPoint].unique = login.unique;
            Log4Debug("UDP login 房间号:" + login.roomID);
            newBuffer = SerializeHelper.Serialize <UDPLogin>(login);
            break;

        case MessageConvention.moveDirection:
            moveDirection = SerializeHelper.Deserialize <ActorMoveDirection>(tempMessageContent);
            if (room.ActorList[moveDirection.userIndex].CurState != RoomActorState.Dead)
            {
                //Log4Debug("将历史帧:" + moveDirection.frameIndex + "保存到" + (moveDirection.frameIndex + room.RoomInfo.frameInterval) + "/" + room.RoomInfo.FrameIndex);
                room.SetRecondFrame(xieyi.ToBytes());
                //Log4Debug("站位:" + moveDirection.userIndex + " 更新了方向:" + "["
                //    + moveDirection.direction.x + ","
                //    + moveDirection.direction.y + ","
                //    + moveDirection.direction.z + "]"
                //    + "/速度:" + moveDirection.speed);
            }
            else
            {
                Log4Debug("死亡用户不更新移动。");
            }
            break;

        case MessageConvention.rotateDirection:
            ActorRotateDirection netRotation = SerializeHelper.Deserialize <ActorRotateDirection>(tempMessageContent);
            if (room.ActorList[netRotation.userIndex].CurState != RoomActorState.Dead)
            {
                room.SetRecondFrame(xieyi.ToBytes());
                //Log4Debug("站位:" + netRotation.userIndex + " 更新了旋转:" + netRotation.rotateY);
            }
            else
            {
                Log4Debug("死亡用户不更新旋转。");
            }
            break;

        case MessageConvention.jump:
            ActorJump netJump = SerializeHelper.Deserialize <ActorJump>(tempMessageContent);
            if (room.ActorList[netJump.userIndex].CurState != RoomActorState.Dead)
            {
                room.SetRecondFrame(xieyi.ToBytes());
            }
            else
            {
                Log4Debug("死亡用户不更新跳跃。");
            }
            break;

        case MessageConvention.shootBullet:
            ShootInfo shootInfo = SerializeHelper.Deserialize <ShootInfo>(tempMessageContent);
            if (room.ActorList[shootInfo.userIndex].CurState != RoomActorState.Dead)
            {
                room.SetRecondFrame(xieyi.ToBytes());
                //Log4Debug("站位:" + netRotation.userIndex + " 更新了旋转:" + netRotation.rotateY);
            }
            else
            {
                Log4Debug("死亡用户不更新射击。");
            }
            break;

        case MessageConvention.bulletInfo:
            //
            BulletInfo bulletInfo = SerializeHelper.Deserialize <BulletInfo>(xieyi.MessageContent);
            room.UpdateBulletInfo(bulletInfo);    //更新
            //room.SetRecondFrame(xieyi.ToBytes());
            break;

        default:
            Log4Debug("检查协议->" + (MessageConvention)xieyi.XieYiFirstFlag);
            break;
        }

        byte[] sendBuffer = null;
        if (newBuffer != null)//用户需要服务器返回值给自己的话
        {
            xieyi      = new MessageXieYi(xieyi.XieYiFirstFlag, xieyi.XieYiSecondFlag, newBuffer);
            sendBuffer = xieyi.ToBytes();
        }
        return(sendBuffer);
    }
コード例 #5
0
ファイル: GameManager.cs プロジェクト: lxc1030/ServerTest
    /// <summary>
    /// 解析所有帧操作指令并在本客户端复现
    /// </summary>
    /// <param name="xieyi"></param>
    private void SelectFrameInfo(MessageXieYi xieyi)
    {
        byte[]          tempMessageContent = xieyi.MessageContent;
        string          messageInfo        = "";
        CharacterCommon member             = null;
        BuffInfo        buffInfo           = null;

        switch ((MessageConvention)xieyi.XieYiFirstFlag)
        {
        case MessageConvention.moveDirection:
            ActorMoveDirection moveDir = SerializeHelper.Deserialize <ActorMoveDirection>(tempMessageContent);
            member = GameManager.instance.memberGroup[moveDir.userIndex];
            //用上次移动操作到这次操作的时间,算出当前位置,并移动到该点
            //member.transform.DOMove(SerializeHelper.BackVector(moveDir.position), DataController.FrameFixedTime);
            //member.SetPosition(SerializeHelper.BackVector(moveDir.position));
            member.SetNetDirection(moveDir);
            break;

        case MessageConvention.rotateDirection:
            ActorRotateDirection rotateDir = SerializeHelper.Deserialize <ActorRotateDirection>(tempMessageContent);
            //判断用户
            //Debug.LogError("玩家接收方向移动:" + messageInfo);
            member = GameManager.instance.memberGroup[rotateDir.userIndex];
            member.SetNetDirection(rotateDir);
            break;

        case MessageConvention.jump:
            ActorJump netJump = SerializeHelper.Deserialize <ActorJump>(tempMessageContent);
            member = GameManager.instance.memberGroup[netJump.userIndex];
            member.SetJump();
            break;

        case MessageConvention.shootBullet:
            ShootInfo shootInfo = SerializeHelper.Deserialize <ShootInfo>(tempMessageContent);
            member = GameManager.instance.memberGroup[shootInfo.userIndex];
            if (shootInfo.userIndex != DataController.instance.MyLocateIndex)    //自身在收到服务器消息之前已旋转
            {
                member.ShowBullet(shootInfo);
            }
            break;

        case MessageConvention.bulletInfo:
            BulletInfo bulletInfo = SerializeHelper.Deserialize <BulletInfo>(tempMessageContent);
            switch (bulletInfo.shootTag)
            {
            case ShootTag.Box:
                BoxManager.instance.SetBulletInfo(bulletInfo);
                break;

            case ShootTag.Character:
                UpdateMemberShoot(xieyi);
                break;

            case ShootTag.Wall:
                Debug.Log("射中Wall:" + bulletInfo.shootInfo);
                break;

            case ShootTag.Buff:
                Debug.LogError("Buff不算是子弹");
                break;
            }

            break;

        case MessageConvention.createBuff:
            buffInfo = SerializeHelper.Deserialize <BuffInfo>(tempMessageContent);
            GameObject obj = PoolManager.instance.GetPoolObjByType(PreLoadType.Buff, GameManager.instance.transBuff);
            obj.transform.position = BoxManager.instance.GetBoxInfoByIndex(buffInfo.boxIndex).transform.position;
            MagicBuff buff = obj.GetComponent <MagicBuff>();
            buff.Init(buffInfo);
            break;

        case MessageConvention.getBuff:
            buffInfo = SerializeHelper.Deserialize <BuffInfo>(tempMessageContent);
            BoxManager.instance.SetBuffData(buffInfo);
            break;
        }
    }