示例#1
0
        public void OnLoadSucc(string source, UnityObject unityObj)
        {
            SingletonManager.Get <SubProgressBlackBoard>().Step();
            var manager = new UserInputManager.Lib.UserInputManager();

            if (!_inputContext.hasUserInputManager)
            {
                var helper = new UserInputHelper(manager);
                _inputContext.SetUserInputManager(manager, helper);
            }
            {
                var cfg = unityObj.As <TextAsset>();
                if (null != cfg)
                {
                    var content  = cfg.text;
                    var inputCfg = InputConfigLoader <InputConfig> .Load(content);

                    manager.Initialize(inputCfg);
                }
                else
                {
                    Logger.Error("Cfg is null or not text asset");
                }
            }
            _sessionState.FullfillExitCondition(typeof(InputConfigInitSystem));
        }
示例#2
0
 public PickUpUiAdapter(PlayerContext player, SceneObjectContext sceneObject, MapObjectContext mapObject, SessionContext session, VehicleContext vehicle, FreeMoveContext freeMove, UserInputManager.Lib.UserInputManager userInputManager, UiContext uiContext)
 {
     this.player           = player;
     this.sceneObject      = sceneObject;
     this.mapObject        = mapObject;
     this.session          = session;
     this.vehicle          = vehicle;
     this.freeMove         = freeMove;
     this.userInputManager = userInputManager;
     this.uiContext        = uiContext;
 }
        public UnityVehicleCmdGenerator(UserInputManager.Lib.UserInputManager manager)
        {
            _lastCmd      = new VehicleCmd();
            _inputManager = manager;
            // 界面不会影响车辆控制
            var keyhandler = new KeyHandler(Layer.Ui, BlockType.None);

            _inputManager.RegisterKeyhandler(keyhandler);
            keyhandler.BindKeyAction(UserInputKey.MoveVertical, data => _lastCmd.MoveVertical     = data.Axis);
            keyhandler.BindKeyAction(UserInputKey.MoveHorizontal, data => _lastCmd.MoveHorizontal = data.Axis);
            keyhandler.BindKeyAction(UserInputKey.VehicleSpeedUp, data => _lastCmd.IsSpeedup      = true);
            keyhandler.BindKeyAction(UserInputKey.VehicleBrake, data => _lastCmd.IsHandbrake      = true);
            keyhandler.BindKeyAction(UserInputKey.VehicleHorn, data => _lastCmd.IsHornOn          = true);

            keyhandler.BindKeyAction(UserInputKey.VehicleLeftShift, data => _lastCmd.IsLeftShift   = true);
            keyhandler.BindKeyAction(UserInputKey.VehicleRightShift, data => _lastCmd.IsRightShift = true);
            keyhandler.BindKeyAction(UserInputKey.VehicleStunt, data => _lastCmd.IsStunt           = true);
        }
        //这里所有的操作层级都设置为Env,如果有特殊遮挡需求请修改层级并修改这段注释
        public void BeginReceiveUserInput(UserInputManager.Lib.UserInputManager manager)
        {
            userInputManager = manager;
            #region Env keyhandler

            // 有UI打开的情况下,不能开枪, 不能瞄准
            _specialKeyHandler = new KeyHandler(UiConstant.specicalCmdKeyLayer, BlockType.None);
            for (int i = 0; i < inputMapperList.Count; i++)
            {
                inputMapperList[i].RegisterSpecialCmdKeyInput(_specialKeyHandler, userCmd);
            }
            _specialKeyHandler.BindKeyAction(UserInputKey.Fire, (data) => userCmd.IsLeftAttack         = true);
            _specialKeyHandler.BindKeyAction(UserInputKey.RightAttack, (data) => userCmd.IsRightAttack = true);
            _specialKeyHandler.BindKeyAction(UserInputKey.CameraFocus, (data) => userCmd.IsCameraFocus = true);
            userInputManager.RegisterKeyhandler(_specialKeyHandler);

            _keyHandler = new KeyHandler(UiConstant.userCmdKeyLayer, BlockType.None);
            for (int i = 0; i < inputMapperList.Count; i++)
            {
                inputMapperList[i].RegisterEnvKeyInput(_keyHandler, userCmd);
            }
            _keyHandler.BindKeyAction(UserInputKey.SwitchFireMode, (data) => userCmd.IsSwitchFireMode = true);
            _keyHandler.BindKeyAction(UserInputKey.DrawWeapon, (data) => userCmd.IsDrawWeapon         = true);
            _keyHandler.BindKeyAction(UserInputKey.Throwing, (data) => userCmd.IsThrowing             = true);
            _keyHandler.BindKeyAction(UserInputKey.FirstPerson, (data) => userCmd.ChangeCamera        = true);
            _keyHandler.BindKeyAction(UserInputKey.FreeCamera, (data) => userCmd.IsCameraFree         = true);
            _keyHandler.BindKeyAction(UserInputKey.Jump, (data) => userCmd.IsJump     = true);
            _keyHandler.BindKeyAction(UserInputKey.Crouch, (data) => userCmd.IsCrouch = true);
            _keyHandler.BindKeyAction(UserInputKey.Prone, (data) => userCmd.IsProne   = true);
            //keyhandler.AddAction(UserInputKey.Injured, (data) => userCmd.BeState = 2);
            //keyhandler.AddAction(UserInputKey.Swim, (data) => userCmd.BeState = 1);
            _keyHandler.BindKeyAction(UserInputKey.Reload, (data) => userCmd.IsReload             = true);
            _keyHandler.BindKeyAction(UserInputKey.PeekLeft, (data) => userCmd.IsPeekLeft         = true);
            _keyHandler.BindKeyAction(UserInputKey.PeekRight, (data) => userCmd.IsPeekRight       = true);
            _keyHandler.BindKeyAction(UserInputKey.SwitchWeapon, (data) => userCmd.IsSwitchWeapon = true);
            _keyHandler.BindKeyAction(UserInputKey.DropWeapon, (data) => userCmd.IsDropWeapon     = true);
            _keyHandler.BindKeyAction(UserInputKey.Switch1, data => userCmd.SwitchNumber          = 1);
            _keyHandler.BindKeyAction(UserInputKey.Switch7, data => userCmd.SwitchNumber          = 7);
            _keyHandler.BindKeyAction(UserInputKey.IsPDown, data => userCmd.IsPDown               = true);
            _keyHandler.BindKeyAction(UserInputKey.IsYDown, data => userCmd.IsYDown               = true);
            _keyHandler.BindKeyAction(UserInputKey.AddMark, data => userCmd.IsAddMark             = true);
            _keyHandler.BindKeyAction(UserInputKey.BreathHold, data => userCmd.IsHoldBreath       = true);
            _keyHandler.BindKeyAction(UserInputKey.SwitchAutoRun, data => userCmd.IsSwitchAutoRun = true);
            _keyHandler.BindKeyAction(UserInputKey.IsCDown, data => userCmd.IsCDown               = true);
            _keyHandler.BindKeyAction(UserInputKey.IsSpaceDown, data => userCmd.IsSpaceDown       = true);
            _keyHandler.BindKeyAction(UserInputKey.HoldF, data => userCmd.IsF = true);
            _keyHandler.BindKeyAction(UserInputKey.SprayPaint, data => userCmd.IsSprayPaint = true);
            _keyHandler.BindKeyAction(UserInputKey.ScopeIn, data => userCmd.IsScopeIn       = true);
            _keyHandler.BindKeyAction(UserInputKey.ScopeOut, data => userCmd.IsScopeOut     = true);
            userInputManager.RegisterKeyhandler(_keyHandler);

            #endregion
            _bioSpecialKeyHandler = new KeyHandler(UiConstant.specicalCmdKeyLayer, BlockType.None);
            _bioSpecialKeyHandler.BindKeyAction(UserInputKey.Fire, (data) => userCmd.IsLeftAttack         = true);
            _bioSpecialKeyHandler.BindKeyAction(UserInputKey.RightAttack, (data) => userCmd.IsRightAttack = true);
            _bioSpecialKeyHandler.BindKeyAction(UserInputKey.CameraFocus, (data) => userCmd.IsCameraFocus = true);

            _bioKeyHandler = new KeyHandler(UiConstant.userCmdKeyLayer, BlockType.None);
            _bioKeyHandler.BindKeyAction(UserInputKey.Throwing, (data) => userCmd.IsThrowing         = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.FreeCamera, (data) => userCmd.IsCameraFree     = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.Jump, (data) => userCmd.IsJump                 = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.Crouch, (data) => userCmd.IsCrouch             = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.Prone, (data) => userCmd.IsProne               = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.IsPDown, data => userCmd.IsPDown               = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.IsYDown, data => userCmd.IsYDown               = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.AddMark, data => userCmd.IsAddMark             = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.BreathHold, data => userCmd.IsHoldBreath       = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.SwitchAutoRun, data => userCmd.IsSwitchAutoRun = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.IsCDown, data => userCmd.IsCDown               = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.IsSpaceDown, data => userCmd.IsSpaceDown       = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.HoldF, data => userCmd.IsF = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.SprayPaint, data => userCmd.IsSprayPaint = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.ScopeIn, data => userCmd.IsScopeIn       = true);
            _bioKeyHandler.BindKeyAction(UserInputKey.ScopeOut, data => userCmd.IsScopeOut     = true);
            #region bioMain


            #endregion

            #region Ui Keyreciever

            _uKeyHandler = new KeyHandler(UiConstant.userCmdUIKeyLayer, BlockType.None);
            _uKeyHandler.BindKeyAction(UserInputKey.MoveHorizontal, (data) => userCmd.MoveHorizontal = data.Axis);
            _uKeyHandler.BindKeyAction(UserInputKey.MoveVertical, (data) => userCmd.MoveVertical     = data.Axis);
            _uKeyHandler.BindKeyAction(UserInputKey.MoveUpDown, (data) => userCmd.MoveUpDown         = data.Axis);
            _uKeyHandler.BindKeyAction(UserInputKey.Run, (data) => userCmd.IsRun             = true);
            _uKeyHandler.BindKeyAction(UserInputKey.IsTabDown, data => userCmd.IsTabDown     = true);
            _uKeyHandler.BindKeyAction(UserInputKey.SlightWalk, data => userCmd.IsSlightWalk = true);
            userInputManager.RegisterKeyhandler(_uKeyHandler);

            #endregion

#if UNITYEDITOR
            foreach (var mockCmd in mockCmdList)
            {
                mockCmd(userCmd);
            }
#endif

            var pointerhandler = new PointerKeyHandler(UiConstant.userCmdPointLayer, BlockType.None);
            pointerhandler.BindPointAction(UserInputKey.Yaw, (keyData) =>
            {
                var pointerData = keyData as PointerData;
                for (int i = 0; i < yaws.Length - 1; i++)
                {
                    yaws[i] = yaws[i + 1];
                }
                yaws[yaws.Length - 1] = pointerData.MouseX;
                float total           = 0;
                for (int i = yaws.Length - 1; i >= Math.Max(0, yaws.Length - BigMapDebug.SmoothFactor); i--)
                {
                    total = total + yaws[i];
                }
                total = total / (float)BigMapDebug.SmoothFactor;
                //Debug.LogFormat("deltaYaw is {0}, deltaTime {1}", total, Time.deltaTime);
#if UNITYEDITOR
                if (!Cursor.visible)
                {
                    userCmd.DeltaYaw = total;
                }
#else
                userCmd.DeltaYaw = total;
#endif
            });
            pointerhandler.BindPointAction(UserInputKey.Pitch, (keyData) =>
            {
                var pointerData = keyData as PointerData;
                for (int i = 0; i < pitchs.Length - 1; i++)
                {
                    pitchs[i] = pitchs[i + 1];
                }
                pitchs[pitchs.Length - 1] = pointerData.MouseY;
                float total = 0;
                for (int i = pitchs.Length - 1; i >= Math.Max(0, pitchs.Length - BigMapDebug.SmoothFactor); i--)
                {
                    total = total + pitchs[i];
                }
                total = total / (float)BigMapDebug.SmoothFactor;
#if UNITYEDITOR
                if (!Cursor.visible)
                {
                    userCmd.DeltaPitch = -total;
                }
#else
                userCmd.DeltaPitch = -total;
#endif
            });

            userInputManager.RegisterPointerhandler(pointerhandler);
        }
示例#5
0
        public void Handle(SimpleProto data)
        {
            Contexts contexts = SingletonManager.Get <FreeUiManager>().Contexts1;

            if (data.Key == FreeMessageConstant.PlayerCmd)
            {
                int          id     = data.Ks[1];
                PlayerEntity player = contexts.player.GetEntityWithEntityKey(new EntityKey(id, (short)EEntityType.Player));
                if (player != null)
                {
                    player.playerIntercept.InterceptType = data.Ks[0];
                    PlayerActEnum.CmdType type = (PlayerActEnum.CmdType)data.Ks[0];
                    switch (type)
                    {
                    case PlayerActEnum.CmdType.Walk:
                        player.playerIntercept.MovePos = new Vector3(data.Fs[0], data.Fs[1], data.Fs[2]);
                        break;

                    case PlayerActEnum.CmdType.ClearKeys:
                        player.playerIntercept.InterceptKeys.Clear();
                        player.playerIntercept.PressKeys.Clear();
                        break;

                    case PlayerActEnum.CmdType.PressKey:
                        player.playerIntercept.PressKeys.AddKeyTime(data.Ins[1], data.Ins[0]);
                        break;

                    case PlayerActEnum.CmdType.InterceptKey:
                        player.playerIntercept.InterceptKeys.AddKeyTime(data.Ins[1], data.Ins[0]);
                        break;

                    case PlayerActEnum.CmdType.Attack:
                        player.playerIntercept.AttackPlayerId = data.Ks[2];
                        break;

                    default:
                        break;
                    }
                }
            }

            if (data.Key == FreeMessageConstant.PlayerPressKey)
            {
                KeyCode code = KeyCode.None;
                foreach (KeyCode kc in Enum.GetValues(typeof(KeyCode)))
                {
                    if (Enum.GetName(typeof(KeyCode), kc).ToLower().Equals(data.Ss[0].ToLower()))
                    {
                        code = kc;
                    }
                }

                if (code == KeyCode.None)
                {
                    return;
                }

                UserInputManager.Lib.UserInputManager             manager = contexts.userInput.userInputManager.Instance;
                Dictionary <UserInputKey, List <KeyConvertItem> > config  = manager.InputConvertDict;
                PlayerEntity player = contexts.player.flagSelfEntity;

                string keyName = "None";
                bool   positive = true, hold = false;
                foreach (InputAction ia in Luminosity.IO.InputManager.GetControlScheme("normal").Actions)
                {
                    foreach (InputBinding ib in ia.Bindings)
                    {
                        if (ib.Positive == code || ib.Negative == code)
                        {
                            keyName  = ia.Name;
                            positive = ib.Positive == code;
                            hold     = ib.Type == InputType.DigitalAxis;
                        }
                    }
                }

                if (data.Bs[0])
                {
                    Dictionary <UserInputKey, int>  PosDict  = new Dictionary <UserInputKey, int>();
                    Dictionary <UserInputKey, bool> HoldDict = new Dictionary <UserInputKey, bool>();
                    foreach (UserInputKey uik in config.Keys)
                    {
                        foreach (KeyConvertItem item in config[uik])
                        {
                            if (item.Key == code && item.State == UserInputState.KeyDown)
                            {
                                PosDict.Add(uik, 0);
                                HoldDict.Add(uik, false);
                            }

                            if (item.Key == code && item.State == UserInputState.KeyHold)
                            {
                                PosDict.Add(uik, 0);
                                HoldDict.Add(uik, true);
                            }

                            if (keyName.Equals(item.InputKey))
                            {
                                PosDict.Add(uik, positive ? 1 : -1);
                                HoldDict.Add(uik, hold);
                            }
                        }
                    }

                    if (PosDict.Count > 0)
                    {
                        foreach (UserInputKey uik in PosDict.Keys)
                        {
                            if (data.Ins[0] == 0 || !HoldDict[uik])
                            {
                                manager.InsertKey(new KeyData(uik, PosDict[uik]));
                            }

                            if (data.Ins[0] > 0 && HoldDict[uik])
                            {
                                player.playerIntercept.RealPressKeys.AddKeyTime((int)uik, data.Ins[0], PosDict[uik]);
                            }
                        }
                    }
                }
                else
                {
                    Dictionary <UserInputKey, int> UpDict     = new Dictionary <UserInputKey, int>();
                    Dictionary <UserInputKey, int> RealseDict = new Dictionary <UserInputKey, int>();

                    foreach (UserInputKey uik in config.Keys)
                    {
                        foreach (KeyConvertItem item in config[uik])
                        {
                            if (item.Key == code)
                            {
                                if (item.State == UserInputState.KeyUp)
                                {
                                    UpDict.Add(uik, 0);
                                }
                                else
                                {
                                    RealseDict.Add(uik, 0);
                                }
                            }

                            if (keyName.Equals(item.InputKey))
                            {
                                RealseDict.Add(uik, 0);
                            }
                        }
                    }

                    if (UpDict.Count > 0)
                    {
                        foreach (UserInputKey uik in UpDict.Keys)
                        {
                            manager.InsertKey(new KeyData(uik));
                        }
                    }

                    if (RealseDict.Count > 0)
                    {
                        foreach (UserInputKey uik in RealseDict.Keys)
                        {
                            player.playerIntercept.RealPressKeys.Release((int)uik);
                        }
                    }
                }
            }
        }
 public FreeObjectCastLogic(FreeMoveContext freeMoveContext, PlayerContext playerContext, UserInputManager.Lib.UserInputManager userInputManager, float distance) : base(playerContext, distance)
 {
     _freeMoveContext  = freeMoveContext;
     _playerContext    = playerContext;
     _userInputManager = userInputManager;
 }