移动和旋转
This commit is contained in:
@@ -39,8 +39,8 @@ namespace NBF
|
||||
}
|
||||
}
|
||||
Log.Error($"showCursor={showCursor}");
|
||||
InputManager.IsUIStopInput = showCursor;
|
||||
InputManager.SetMouseCursor(showCursor);
|
||||
// Game.Input.IsUIStopInput = showCursor;
|
||||
// Game.Input.SetMouseCursor(showCursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using NBC;
|
||||
// using Rewired;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public enum ControllerType
|
||||
{
|
||||
KeyboardMouse = 0,
|
||||
GamePad = 1
|
||||
}
|
||||
|
||||
public class InputManager : MonoService<InputManager>
|
||||
{
|
||||
public static bool IsOp1;
|
||||
public static bool IsOp2;
|
||||
|
||||
public static event Action<bool> OnOp1Action;
|
||||
public static event Action<bool> OnOp2Action;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件
|
||||
/// </summary>
|
||||
public static event Action<string> OnUIPerformed;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件完毕
|
||||
/// </summary>
|
||||
public static event Action<string> OnUICanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件
|
||||
/// </summary>
|
||||
public static event Action<string> OnPlayerPerformed;
|
||||
|
||||
/// <summary>
|
||||
/// 执行输入事件完毕
|
||||
/// </summary>
|
||||
public static event Action<string> OnPlayerCanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 触发交互游戏对象
|
||||
/// </summary>
|
||||
public static event Action<InteractiveObject> OnInteractiveObjectAction;
|
||||
|
||||
public static PlayerInputControl PlayerInputControl { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 手柄输入
|
||||
/// </summary>
|
||||
public static bool IsControllerInput;
|
||||
|
||||
/// <summary>
|
||||
/// ui阻止游戏输入
|
||||
/// </summary>
|
||||
public static bool IsUIStopInput;
|
||||
|
||||
public static ControllerType ControllerType = ControllerType.KeyboardMouse;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
InputCursorExtension.InputInit();
|
||||
DontDestroyOnLoad(gameObject);
|
||||
PlayerInputControl = new PlayerInputControl();
|
||||
PlayerInputControl.Enable();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
AddEvent();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
RemoveEvent();
|
||||
InputCursorExtension.Dispose();
|
||||
}
|
||||
|
||||
|
||||
public static void SetMouseCursor(bool val)
|
||||
{
|
||||
if (val)
|
||||
{
|
||||
if (ControllerType == ControllerType.KeyboardMouse)
|
||||
{
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
else if (ControllerType == ControllerType.KeyboardMouse)
|
||||
{
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
Cursor.visible = val;
|
||||
if (!val)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector2 GetMovementInput()
|
||||
{
|
||||
if (IsUIStopInput) return Vector2.zero;
|
||||
return PlayerInputControl.Player.Move?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
public static Vector2 GetLookInput()
|
||||
{
|
||||
if (IsUIStopInput) return Vector2.zero;
|
||||
return PlayerInputControl.Player.Look?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
|
||||
private void AddEvent()
|
||||
{
|
||||
foreach (var actionMap in PlayerInputControl.asset.actionMaps)
|
||||
{
|
||||
actionMap.Enable();
|
||||
if (actionMap.name == "UI")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed += OnUIButtonPerformed;
|
||||
action.canceled += OnUIButtonCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (actionMap.name == "Player")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed += OnPlayerButtonPerformed;
|
||||
action.canceled += OnPlayerButtonCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveEvent()
|
||||
{
|
||||
OnUIPerformed = null;
|
||||
OnUICanceled = null;
|
||||
OnPlayerPerformed = null;
|
||||
OnPlayerCanceled = null;
|
||||
}
|
||||
|
||||
private void OnUIButtonPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
OnUIPerformed?.Invoke(context.action.name);
|
||||
}
|
||||
|
||||
private void OnUIButtonCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
OnUICanceled?.Invoke(context.action.name);
|
||||
}
|
||||
|
||||
private void OnPlayerButtonPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
var actionName = context.action.name;
|
||||
if (actionName == "Op1")
|
||||
{
|
||||
OnOp1Action?.Invoke(true);
|
||||
}
|
||||
else if (actionName == "Op2")
|
||||
{
|
||||
OnOp2Action?.Invoke(true);
|
||||
}
|
||||
|
||||
OnPlayerPerformed?.Invoke(actionName);
|
||||
}
|
||||
|
||||
private void OnPlayerButtonCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
var actionName = context.action.name;
|
||||
if (actionName == "Op1")
|
||||
{
|
||||
OnOp1Action?.Invoke(false);
|
||||
}
|
||||
else if (actionName == "Op2")
|
||||
{
|
||||
OnOp2Action?.Invoke(false);
|
||||
}
|
||||
|
||||
OnPlayerCanceled?.Invoke(actionName);
|
||||
}
|
||||
|
||||
|
||||
public void OnInteractiveObject(InteractiveObject interactiveObject)
|
||||
{
|
||||
Debug.LogError($"OnInteractiveObject {interactiveObject != null}");
|
||||
OnInteractiveObjectAction?.Invoke(interactiveObject);
|
||||
}
|
||||
|
||||
public void SendUIInput(string actionName)
|
||||
{
|
||||
OnUIPerformed?.Invoke(actionName);
|
||||
OnUICanceled?.Invoke(actionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fecc50928be248b896f6ee0a17e7b76d
|
||||
timeCreated: 1746892722
|
||||
@@ -8,7 +8,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.AddBob;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.AddBob;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.Chat;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.Chat;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.Help;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.Help;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.SubBob;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.SubBob;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.ToBag;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.ToBag;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.UseTelescope;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.UseTelescope;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace NBF.Setting
|
||||
public override string Group => SettingsDef.Group.Keyboard;
|
||||
public override string Tab => SettingsDef.Tab.Keyboard;
|
||||
|
||||
public override InputAction InputAction => InputManager.PlayerInputControl.Player.UseTorch;
|
||||
public override InputAction InputAction => Game.Input.PlayerInputControl.Player.UseTorch;
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace NBF
|
||||
Log.Debug($"登录到Gate服务器成功!ErrorCode:{loginResponse.ErrorCode}");
|
||||
await role.GetRoleInfo();
|
||||
Log.Debug(
|
||||
$"获取角色信息成功!roleId={role.Id} Room={role.RoomId} RoleInfo={JsonConvert.SerializeObject(role.Info)}");
|
||||
$"获取角色信息成功!roleId={role.Id} Room={role.RoomCode} RoleInfo={JsonConvert.SerializeObject(role.Info)}");
|
||||
var mapId = role.Info.MapId;
|
||||
if (mapId == 0)
|
||||
{
|
||||
@@ -70,7 +70,8 @@ namespace NBF
|
||||
mapId = 99;
|
||||
}
|
||||
|
||||
await MapHelper.EnterMap(mapId, role.RoomId);
|
||||
Game.SelfId = loginResponse.RoleId;
|
||||
await MapHelper.EnterMap(mapId, role.RoomCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user