示例#1
0
        void Update()
        {
            if (controllerMode == ControllerMode.SELF)
            {
                if (first)
                {
                    first = false;
                    RandomWeapon();
                }

                if (soldier.IsFreeze())
                {
                    RobotStop();
                    soldier.UpdateOperation(action);
                    UnLockAnemey();
                    if (reportTransform.CheckAndRun())
                    {
                        UserSynchronizationRouter.ReportTransform(soldier.GetUserID(), soldier.GetTransform());
                    }
                    return;
                }

                if (robotFindRoad.CheckAndRun())
                {
                    //EventMgr.Instance.EventTrigger(EventName.FIND_ROAD, soldier.GetUserID());
                }

                if (robotLostGoal.CheckAndRun())
                {
                    UnLockAnemey();
                }

                EventMgr.Instance.EventTrigger(EventName.NEUTRAL_ROBOT_CHOOSE_GOAL, soldier.GetUserID());

                CalculateMove();

                if (!soldier.Death() && attackCD.CheckAndRun())
                {
                    AttackCheck();
                }

                if (reportTransform.CheckAndRun())
                {
                    UserSynchronizationRouter.ReportTransform(soldier.GetUserID(), soldier.GetTransform());
                }

                if (reportActions.CheckAndRun())
                {
                    ReportActions();
                }
                soldier.UpdateOperation(action);
            }
            else if (controllerMode == ControllerMode.NETWORK)
            {
                if (queryTransform.CheckAndRun())
                {
                    UserSynchronizationRouter.QueryUsersTransform(soldier.GetUserID());
                }
            }
        }
示例#2
0
        void Update()
        {
            soldier.SetSpeeds(speeds);  // 调手感用,编辑器调试时能让速度直接改变
            action.Init();

            if (OperationMode.Instance.IsLock())
            {
                if (reportTransform.CheckAndRun())
                {
                    UserSynchronizationRouter.ReportTransform(soldier.GetUserID(), soldier.GetTransform());
                }
                return;
            }

            if (soldier.IsFreeze())
            {
                EventMgr.Instance.EventTrigger(EventName.MAIN_PLAYER_ACTION, action);
                if (reportTransform.CheckAndRun())
                {
                    UserSynchronizationRouter.ReportTransform(soldier.GetUserID(), soldier.GetTransform());
                }
                return;
            }

            WeaponChangeAction();

            if (Input.GetMouseButton(0))
            {
                action.Add(EPlayerAction.SHOOT);
            }
            if (Input.GetMouseButton(1))
            {
                action.Add(EPlayerAction.SHOOT_BURST);
            }

            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                action.Add(EPlayerAction.SHOOT_LINE);
            }

            if (Input.GetKey(KeyCode.R))
            {
                action.Add(EPlayerAction.RELOAD);
            }

            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                action.Add(EPlayerAction.BEGIN_RUN);
            }
            else
            {
                action.Add(EPlayerAction.END_RUN);
            }

            if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
            {
                action.Add(EPlayerAction.BEGIN_CROUCH);
            }
            else
            {
                action.Add(EPlayerAction.END_CROUCH);
            }

            if (Input.GetKey(KeyCode.Space))
            {
                action.Add(EPlayerAction.DUMP);
            }

            float h      = Input.GetAxis("Horizontal");
            float v      = Input.GetAxis("Vertical");
            float mouseX = Input.GetAxis("Mouse X");
            float mouseY = Input.GetAxis("Mouse Y");

            action.SetMove(h, v);
            action.SetMouse(mouseX, mouseY);

            // 在武器箱面前,按了E,换武器
            if (MemeryCacheMgr.Instance.Get(UICacheKeys.BULLET_BOX_WARN_MESSAGE) != null && Input.GetKeyDown(KeyCode.E))
            {
                if (MemeryCacheMgr.Instance.Get(UICacheKeys.WEAPON_BOX) is WeaponBoxBase weaponBox)
                {
                    soldier.SetWeapon(weaponBox.CreatorWeapon(), weaponBox.GetWeaponBagPos());
                    GameMgrRouter.NewWeaponRequestCall((int)weaponBox.GetWeaponTypeID(), soldier.GetUserID(), (int)weaponBox.GetWeaponBagPos());
                    weaponBox.Destory();
                }
            }

            // 触发直接影响角色行为。不等服务端校验完,体验好一点。
            EventMgr.Instance.EventTrigger(EventName.MAIN_PLAYER_ACTION, action);

            if (reportTransform.CheckAndRun())
            {
                UserSynchronizationRouter.ReportTransform(soldier.GetUserID(), soldier.GetTransform());
            }

            if (reportActions.CheckAndRun())
            {
                ReportActions();
            }
        }