public UnityVehicleCmdGenerator(IUserInputManager manager) { _lastCmd = new VehicleCmd(); _inputManager = manager; // 界面不会影响车辆控制 var keyReceiver = new KeyReceiver(Layer.Ui, BlockType.None); _inputManager.RegisterKeyReceiver(keyReceiver); keyReceiver.AddAction(UserInputKey.MoveVertical, data => _lastCmd.MoveVertical = data.Axis); keyReceiver.AddAction(UserInputKey.MoveHorizontal, data => _lastCmd.MoveHorizontal = data.Axis); keyReceiver.AddAction(UserInputKey.VehicleSpeedUp, data => _lastCmd.IsSpeedup = true); keyReceiver.AddAction(UserInputKey.VehicleBrake, data => _lastCmd.IsHandbrake = true); keyReceiver.AddAction(UserInputKey.VehicleHorn, data => _lastCmd.IsHornOn = true); keyReceiver.AddAction(UserInputKey.VehicleLeftShift, data => _lastCmd.IsLeftShift = true); keyReceiver.AddAction(UserInputKey.VehicleRightShift, data => _lastCmd.IsRightShift = true); keyReceiver.AddAction(UserInputKey.VehicleStunt, data => _lastCmd.IsStunt = true); }
//这里所有的操作层级都设置为Env,如果有特殊遮挡需求请修改层级并修改这段注释 public void BeginReceiveUserInput(IUserInputManager manager) { _userInputManager = manager; #region Env keyreceiver // 有UI打开的情况下,不能开枪, 不能瞄准 _specialKeyReceiver = new KeyReceiver(UiConstant.specicalCmdKeyLayer, BlockType.None); for (int i = 0; i < _inputMapperList.Count; i++) { _inputMapperList[i].RegisterSpecialCmdKeyInput(_specialKeyReceiver, _userCmd); } _specialKeyReceiver.AddAction(UserInputKey.Fire, (data) => _userCmd.IsLeftAttack = true); _specialKeyReceiver.AddAction(UserInputKey.RightAttack, (data) => _userCmd.IsRightAttack = true); _specialKeyReceiver.AddAction(UserInputKey.CameraFocus, (data) => _userCmd.IsCameraFocus = true); _userInputManager.RegisterKeyReceiver(_specialKeyReceiver); _keyReceiver = new KeyReceiver(UiConstant.userCmdKeyLayer, BlockType.None); for (int i = 0; i < _inputMapperList.Count; i++) { _inputMapperList[i].RegisterEnvKeyInput(_keyReceiver, _userCmd); } _keyReceiver.AddAction(UserInputKey.SwitchFireMode, (data) => _userCmd.IsSwitchFireMode = true); _keyReceiver.AddAction(UserInputKey.DrawWeapon, (data) => _userCmd.IsDrawWeapon = true); _keyReceiver.AddAction(UserInputKey.Throwing, (data) => _userCmd.IsThrowing = true); _keyReceiver.AddAction(UserInputKey.FirstPerson, (data) => _userCmd.ChangeCamera = true); _keyReceiver.AddAction(UserInputKey.FreeCamera, (data) => _userCmd.IsCameraFree = true); _keyReceiver.AddAction(UserInputKey.Jump, (data) => _userCmd.IsJump = true); _keyReceiver.AddAction(UserInputKey.Crouch, (data) => _userCmd.IsCrouch = true); _keyReceiver.AddAction(UserInputKey.Prone, (data) => _userCmd.IsProne = true); //_keyReceiver.AddAction(UserInputKey.Injured, (data) => _userCmd.BeState = 2); //_keyReceiver.AddAction(UserInputKey.Swim, (data) => _userCmd.BeState = 1); _keyReceiver.AddAction(UserInputKey.Reload, (data) => _userCmd.IsReload = true); _keyReceiver.AddAction(UserInputKey.PeekLeft, (data) => _userCmd.IsPeekLeft = true); _keyReceiver.AddAction(UserInputKey.PeekRight, (data) => _userCmd.IsPeekRight = true); _keyReceiver.AddAction(UserInputKey.SwitchWeapon, (data) => _userCmd.IsSwitchWeapon = true); _keyReceiver.AddAction(UserInputKey.DropWeapon, (data) => _userCmd.IsDropWeapon = true); _keyReceiver.AddAction(UserInputKey.Switch1, data => _userCmd.SwitchNumber = 1); _keyReceiver.AddAction(UserInputKey.Switch7, data => _userCmd.SwitchNumber = 7); _keyReceiver.AddAction(UserInputKey.IsPDown, data => _userCmd.IsPDown = true); _keyReceiver.AddAction(UserInputKey.IsYDown, data => _userCmd.IsYDown = true); _keyReceiver.AddAction(UserInputKey.AddMark, data => _userCmd.IsAddMark = true); _keyReceiver.AddAction(UserInputKey.BreathHold, data => _userCmd.IsHoldBreath = true); _keyReceiver.AddAction(UserInputKey.SwitchAutoRun, data => _userCmd.IsSwitchAutoRun = true); _keyReceiver.AddAction(UserInputKey.IsCDown, data => _userCmd.IsCDown = true); _keyReceiver.AddAction(UserInputKey.IsSpaceDown, data => _userCmd.IsSpaceDown = true); _keyReceiver.AddAction(UserInputKey.HoldF, data => _userCmd.IsF = true); _keyReceiver.AddAction(UserInputKey.SprayPaint, data => _userCmd.IsSprayPaint = true); _keyReceiver.AddAction(UserInputKey.ScopeIn, data => _userCmd.IsScopeIn = true); _keyReceiver.AddAction(UserInputKey.ScopeOut, data => _userCmd.IsScopeOut = true); _userInputManager.RegisterKeyReceiver(_keyReceiver); #endregion #region Ui Keyreciever _uiKeyReceiver = new KeyReceiver(UiConstant.userCmdUIKeyLayer, BlockType.None); _uiKeyReceiver.AddAction(UserInputKey.MoveHorizontal, (data) => _userCmd.MoveHorizontal = data.Axis); _uiKeyReceiver.AddAction(UserInputKey.MoveVertical, (data) => _userCmd.MoveVertical = data.Axis); _uiKeyReceiver.AddAction(UserInputKey.MoveUpDown, (data) => _userCmd.MoveUpDown = data.Axis); _uiKeyReceiver.AddAction(UserInputKey.Run, (data) => _userCmd.IsRun = true); _uiKeyReceiver.AddAction(UserInputKey.IsTabDown, data => _userCmd.IsTabDown = true); _uiKeyReceiver.AddAction(UserInputKey.SlightWalk, data => _userCmd.IsSlightWalk = true); _userInputManager.RegisterKeyReceiver(_uiKeyReceiver); #endregion #if UNITY_EDITOR foreach (var mockCmd in _mockCmdList) { mockCmd(_userCmd); } #endif var pointerReceiver = new PointerReceiver(UiConstant.userCmdPointLayer, BlockType.None); pointerReceiver.AddAction(UserInputKey.Yaw, (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 UNITY_EDITOR if (!Cursor.visible) { _userCmd.DeltaYaw = total; } #else _userCmd.DeltaYaw = total; #endif }); pointerReceiver.AddAction(UserInputKey.Pitch, (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 UNITY_EDITOR if (!Cursor.visible) { _userCmd.DeltaPitch = -total; } #else _userCmd.DeltaPitch = -total; #endif }); _userInputManager.RegisterPointerReceiver(pointerReceiver); }
public void RegisterKeyReceiver(IKeyReceiver receiver) { userInputManager.RegisterKeyReceiver(receiver); }