private void controllerAllplayers(AllPlayerOperation allPlayerOperation)
 {
     for (int i = 0; i < allPlayerOperation.PlayerOperation.Count; i++)
     {
         //找到当前页面上的所有player
         GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
         bool         isfind  = false;
         foreach (var player in players)
         {
             if (player.GetComponent <PlayerInfo>().Id == allPlayerOperation.PlayerOperation[i].Id)
             {
                 movePlayer(player, allPlayerOperation.PlayerOperation[i]);
                 isfind = true;
                 //该角色已移动
                 break;
             }
         }
         if (isfind != true)
         {
             //没有找到对应角色。生成一个角色。
             GameObject playerCreated = createBot(allPlayerOperation.PlayerOperation[i]);
             movePlayer(playerCreated, allPlayerOperation.PlayerOperation[i]);
         }
     }
 }
Exemple #2
0
    public void Logic_Operation(AllPlayerOperation _allOp)
    {
        foreach (var item in _allOp.operations)
        {
            dic_role [item.battleID].Logic_UpdateMoveDir(item.move);
            if (item.rightOperation == RightOpType.noop || item.operationID == 0)
            {
                //无操作
            }
            else
            {
                if (BattleData.Instance.IsValidRightOp(item.battleID, item.operationID))
                {
                    //操作有效
                    switch (item.rightOperation)
                    {
                    case RightOpType.attack:
                    {
                        dic_role [item.battleID].Logic_NormalAttack();
                    }
                    break;

                    default:
                        break;
                    }

                    BattleData.Instance.UpdateRightOperationID(item.battleID, item.operationID, item.rightOperation);
                }
            }
        }
    }
Exemple #3
0
    public void AddNewFrameData(int _frameID, AllPlayerOperation _ops)
    {
        dic_frameData[_frameID] = _ops;
        for (int i = maxFrameID + 1; i < _frameID; i++)
        {
            lackFrame.Add(i);
            Debug.Log("缺失:" + i);
        }
        maxFrameID = _frameID;

        //  发送缺失帧数据
        //  只发送所有缺失帧的前5个
        if (lackFrame.Count > 0)
        {
            if (lackFrame.Count > maxSendNum)
            {
                List <int> sendList = lackFrame.GetRange(0, maxSendNum);
                BattleConn.Instance.SendDeltaFrames(SelfOperation.BattleID, sendList);
            }
            else
            {
                BattleConn.Instance.SendDeltaFrames(SelfOperation.BattleID, lackFrame);
            }
        }
    }
Exemple #4
0
 public void Logic_Operation(AllPlayerOperation _op)
 {
     Debug.Log("更新操作:按键为" + _op.Operations[0].Keyinput);
     foreach (PlayerOperation op in _op.Operations)
     {
         Logic_HandleInput(roles[op.BattleID], op);
     }
 }
Exemple #5
0
 public void AddLackFrameData(int _frameID, AllPlayerOperation _newOps)
 {
     //  删除缺失的帧记录
     if (lackFrame.Contains(_frameID))
     {
         dic_frameData[_frameID] = _newOps;
         lackFrame.Remove(_frameID);
         Debug.Log("补上:" + _frameID);
     }
 }
Exemple #6
0
        public async Task <AllPlayerOperation> receiveOperate()
        {
            while (await call.ResponseStream.MoveNext())
            {
                AllPlayerOperation allPlayerOperation = call.ResponseStream.Current;
                return(await Task.FromResult(allPlayerOperation));
            }

            return(null);
        }
        // Fixed update is called in sync with physics
        private async void FixedUpdate()
        {
            // read inputs
            float h      = Input.GetAxis("Horizontal");
            float v      = Input.GetAxis("Vertical");
            bool  crouch = Input.GetKey(KeyCode.C);

            // calculate move direction to pass to character
            if (m_Cam != null)
            {
                // calculate camera relative direction to move:
                m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
                m_Move       = v * m_CamForward + h * m_Cam.right;
            }
            else
            {
                // we use world-relative directions in the case of no main camera
                m_Move = v * Vector3.forward + h * Vector3.right;
            }
#if !MOBILE_INPUT
            // walk speed multiplier
            if (Input.GetKey(KeyCode.LeftShift))
            {
                m_Move *= 0.5f;
            }
#endif

            // 把这句里的参数发送到服务器上。服务器返回后再移动。这里应该有个固定时长来做统一。

            sendToServer(m_Move, crouch);
            //放到一个单独逻辑中。更新所有玩家状态。目前还没有做玩家加入操作
            AllPlayerOperation allPlayerOperation = await playerOperator.receiveOperate();

            // Debug.Log(Time.deltaTime);
            controllerAllplayers(allPlayerOperation);

            m_Jump = false;
        }
Exemple #8
0
    public void AddNewFrameData(int _frameID, AllPlayerOperation _op)
    {
        dic_frameDate [_frameID] = _op;
        for (int i = maxFrameID + 1; i < _frameID; i++)
        {
            lackFrame.Add(i);
            Debug.Log("缺失 :" + i);
        }
        maxFrameID = _frameID;

        //发送缺失帧数据
        if (lackFrame.Count > 0)
        {
            if (lackFrame.Count > maxSendNum)
            {
                List <int> sendList = lackFrame.GetRange(0, maxSendNum);
                UdpPB.Instance().SendDeltaFrames(selfOperation.battleID, sendList);
            }
            else
            {
                UdpPB.Instance().SendDeltaFrames(selfOperation.battleID, lackFrame);
            }
        }
    }
Exemple #9
0
    public bool TryGetNextPlayerOp(out AllPlayerOperation _op)
    {
        int _frameID = curFrameID + 1;

        return(dic_frameData.TryGetValue(_frameID, out _op));
    }
Exemple #10
0
 public UdpDownFrameOperations() : base()
 {
     Ops = new AllPlayerOperation();
 }