feat(): 大量更新

This commit is contained in:
2025-10-15 21:31:13 +08:00
parent 546f08c53a
commit 668bfe12eb
178 changed files with 11318 additions and 446 deletions

View File

@@ -2,7 +2,6 @@
"name": "Core",
"rootNamespace": "",
"references": [
"GUID:9e4105fe56ff4b1789a1683a3c08d507",
"GUID:75469ad4d38634e559750d17036d5f7c"
],
"includePlatforms": [],

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 656856e514875b444af5c8db9035beea
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,91 +0,0 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace Core
{
public class InputManager : MonoSingleton<InputManager>
{
private PlayerInputActions _input; // 自动生成的输入类
// 当前输入值
public Vector2 Move { get; private set; }
public Vector2 Look { get; private set; }
public bool PausePressed { get; private set; }
private void Awake()
{
_input = new PlayerInputActions();
}
private void OnEnable()
{
_input.Enable();
// 注册事件
_input.Player.Move.performed += ctx => Move = ctx.ReadValue<Vector2>();
_input.Player.Move.canceled += ctx => Move = Vector2.zero;
_input.Player.Look.performed += ctx => Look = ctx.ReadValue<Vector2>();
_input.Player.Look.canceled += ctx => Look = Vector2.zero;
//
// _input.Player.Jump.performed += ctx => JumpPressed = true;
// _input.Player.Jump.canceled += ctx => JumpPressed = false;
//
}
private void OnDisable()
{
_input.Disable();
}
private void Update()
{
// 在此更新一次性触发的输入,例如“按下瞬间触发”
// if (PausePressed)
// {
// Debug.Log("Pause Pressed!");
// PausePressed = false; // 手动清除
// }
}
// 🔧 示例方法:允许外部模块手动启用/禁用输入(比如暂停菜单)
public void SetInputEnabled(bool enabled)
{
if (enabled) _input.Enable();
else _input.Disable();
}
public void SetCursorState(bool visible, CursorLockMode lockMode)
{
Cursor.visible = visible;
Cursor.lockState = lockMode;
}
public void SetInputForLook(bool enabled)
{
if (enabled)
{
_input.Player.Look.Enable();
}
else
{
_input.Player.Look.Disable();
Look = Vector2.zero; // 禁用时清除Look值
}
}
public void SetInputForMove(bool enabled)
{
if (enabled)
{
_input.Player.Move.Enable();
}
else
{
_input.Player.Move.Disable();
Move = Vector2.zero; // 禁用时清除Move值
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: c9d73a7b65ad4d43a9587b5060528a3c
timeCreated: 1760403080

View File

@@ -1,205 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.11.2
// from Assets/Settings/Input/PlayerInputActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
namespace Core
{
public partial class @PlayerInputActions: IInputActionCollection2, IDisposable
{
public InputActionAsset asset { get; }
public @PlayerInputActions()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""PlayerInputActions"",
""maps"": [
{
""name"": ""Player"",
""id"": ""c76c22e9-2e4a-4535-bf00-ee32c0071ec4"",
""actions"": [
{
""name"": ""Move"",
""type"": ""Button"",
""id"": ""cba876cd-5594-42ac-a4b0-2f2ed0f0e120"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Look"",
""type"": ""Value"",
""id"": ""e288a319-23aa-463c-bd94-e6a00eec4e3b"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
}
],
""bindings"": [
{
""name"": """",
""id"": ""dab4d8f6-9492-4327-8944-76f09907ba54"",
""path"": ""<Keyboard>/w"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""d7c34f0b-b18e-4498-8d3e-1bdec4cb355d"",
""path"": ""<Mouse>/position"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Look"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
],
""controlSchemes"": []
}");
// Player
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_Move = m_Player.FindAction("Move", throwIfNotFound: true);
m_Player_Look = m_Player.FindAction("Look", throwIfNotFound: true);
}
~@PlayerInputActions()
{
UnityEngine.Debug.Assert(!m_Player.enabled, "This will cause a leak and performance issues, PlayerInputActions.Player.Disable() has not been called.");
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
public IEnumerable<InputBinding> bindings => asset.bindings;
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
{
return asset.FindAction(actionNameOrId, throwIfNotFound);
}
public int FindBinding(InputBinding bindingMask, out InputAction action)
{
return asset.FindBinding(bindingMask, out action);
}
// Player
private readonly InputActionMap m_Player;
private List<IPlayerActions> m_PlayerActionsCallbackInterfaces = new List<IPlayerActions>();
private readonly InputAction m_Player_Move;
private readonly InputAction m_Player_Look;
public struct PlayerActions
{
private @PlayerInputActions m_Wrapper;
public PlayerActions(@PlayerInputActions wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Player_Move;
public InputAction @Look => m_Wrapper.m_Player_Look;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(PlayerActions set) { return set.Get(); }
public void AddCallbacks(IPlayerActions instance)
{
if (instance == null || m_Wrapper.m_PlayerActionsCallbackInterfaces.Contains(instance)) return;
m_Wrapper.m_PlayerActionsCallbackInterfaces.Add(instance);
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Look.started += instance.OnLook;
@Look.performed += instance.OnLook;
@Look.canceled += instance.OnLook;
}
private void UnregisterCallbacks(IPlayerActions instance)
{
@Move.started -= instance.OnMove;
@Move.performed -= instance.OnMove;
@Move.canceled -= instance.OnMove;
@Look.started -= instance.OnLook;
@Look.performed -= instance.OnLook;
@Look.canceled -= instance.OnLook;
}
public void RemoveCallbacks(IPlayerActions instance)
{
if (m_Wrapper.m_PlayerActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
public void SetCallbacks(IPlayerActions instance)
{
foreach (var item in m_Wrapper.m_PlayerActionsCallbackInterfaces)
UnregisterCallbacks(item);
m_Wrapper.m_PlayerActionsCallbackInterfaces.Clear();
AddCallbacks(instance);
}
}
public PlayerActions @Player => new PlayerActions(this);
public interface IPlayerActions
{
void OnMove(InputAction.CallbackContext context);
void OnLook(InputAction.CallbackContext context);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ff05c86378543b94488d735aea6436d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f02de2f72561440b862be76a712a53a6
timeCreated: 1760448092

View File

@@ -0,0 +1,16 @@
using UnityEngine;
namespace Core
{
public interface IInputManager
{
public Vector2 Move { get; }
public Vector2 Look { get; }
public bool JumpPressed { get; }
public bool PausePressed { get; }
public bool InteractPressed { get; }
public void SetCursorState(bool visible, CursorLockMode lockMode);
public void SetInputForLook(bool enabled);
public void SetInputForMove(bool enabled);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b077e0f59a474f5a981770fae92ed42f
timeCreated: 1760447509

View File

@@ -25,6 +25,13 @@ namespace Core
private Dictionary<UILayer, Transform> layerRoots = new Dictionary<UILayer, Transform>();
private Dictionary<string, UIBase> openedUIs = new Dictionary<string, UIBase>();
private IInputManager inputManager;
public void RegisterInputManager(IInputManager inputMgr)
{
inputManager = inputMgr;
}
public void RegisterLayer(UILayer layer, Transform root)
{
@@ -122,18 +129,19 @@ namespace Core
private void UpdateCursorState()
{
if(inputManager == null) return;
bool shouldLockCursor = !IsHasNonBackgroundUIActive; //&& !isInMainMenu; // 仅在没有非Background UI且不在主菜单时锁定鼠标
if (shouldLockCursor)
{
InputManager.Instance.SetCursorState(false, CursorLockMode.Locked);
inputManager.SetCursorState(false, CursorLockMode.Locked);
}
else
{
InputManager.Instance.SetCursorState(true, CursorLockMode.None);
inputManager.SetCursorState(true, CursorLockMode.None);
}
InputManager.Instance.SetInputForLook(shouldLockCursor);
InputManager.Instance.SetInputForMove(shouldLockCursor);
inputManager.SetInputForLook(shouldLockCursor);
inputManager.SetInputForMove(shouldLockCursor);
}
}
}