This commit is contained in:
Bragin Stepan
2026-02-19 23:19:33 +05:00
parent e07bde989a
commit 1174be2d43
70 changed files with 3307 additions and 591 deletions

View File

@@ -1,3 +1,3 @@
fileFormatVersion: 2
guid: f03531ec1be8466f8e4dc6bff6bacff6
timeCreated: 1770396920
guid: 525e15ae6349432194c910fa34806bb0
timeCreated: 1771524166

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 34ffa6b3aff14a1eaeb9f4876beb1b12
timeCreated: 1770416206

View File

@@ -0,0 +1,13 @@
using System;
namespace _Project.Develop.Runtime.Utils.InputManagement
{
public interface IInput : IDisposable
{
bool IsEnabled { get; }
void Enable();
void Disable();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8e6f13ff5fdd4bfcae00ac967fe1803a
timeCreated: 1770406587

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using UnityEngine.InputSystem;
namespace _Project.Develop.Runtime.Utils.InputManagement.Inputs
{
public abstract class InputBase : IDisposable
{
public bool IsEnabled { get; private set; }
private readonly List<IDisposable> _disposables = new();
protected InputState<T> Register<T>(InputAction action) where T : struct
{
InputState<T> state = new(action);
if (state is IDisposable disposable)
_disposables.Add(disposable);
return state;
}
public virtual void Enable() => IsEnabled = true;
public virtual void Disable() => IsEnabled = false;
public virtual void Dispose()
{
Disable();
foreach (IDisposable disposable in _disposables)
disposable.Dispose();
_disposables.Clear();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2ea9e4fc30604b498571755608da3e91
timeCreated: 1770464464

View File

@@ -0,0 +1,68 @@
using System;
using UnityEngine.InputSystem;
namespace _Project.Develop.Runtime.Utils.InputManagement
{
public class InputState<T> : IDisposable where T : struct
{
public event Action<T> Enter;
public event Action<T> Perform;
public event Action<T> Exit;
public bool IsActive { get; private set; }
public T Value { get; private set; }
private readonly InputAction _inputAction;
public InputState(InputAction inputAction)
{
_inputAction = inputAction;
Subscribe();
}
private void Subscribe()
{
_inputAction.started += OnStarted;
_inputAction.performed += OnPerformed;
_inputAction.canceled += OnCanceled;
}
private void Unsubscribe()
{
_inputAction.started -= OnStarted;
_inputAction.performed -= OnPerformed;
_inputAction.canceled -= OnCanceled;
}
private void OnStarted(InputAction.CallbackContext ctx)
{
T value = ctx.ReadValue<T>();
Value = value;
IsActive = true;
Enter?.Invoke(value);
}
private void OnPerformed(InputAction.CallbackContext ctx)
{
T value = ctx.ReadValue<T>();
Value = value;
Perform?.Invoke(value);
}
private void OnCanceled(InputAction.CallbackContext ctx)
{
T value = ctx.ReadValue<T>();
Value = value;
IsActive = false;
Exit?.Invoke(value);
}
public void Dispose()
{
Unsubscribe();
Enter = null;
Perform = null;
Exit = null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e8cfbe040c144edc86e9ada246bf8b52
timeCreated: 1770416153

View File

@@ -1,77 +0,0 @@
using System;
using UnityEngine;
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public class DesktopPlayerInputService : IPlayerInputService
{
public event Action OnJump;
public event Action OnInteract;
public event Action OnPrevious;
public event Action OnNext;
private const string HorizontalAxisKey = "Horizontal";
private const string VerticalAxisKey = "Vertical";
private const KeyCode JumpKey = KeyCode.Space;
private const KeyCode InteractKey = KeyCode.F;
private const KeyCode PreviousKey = KeyCode.Q;
private const KeyCode NextKey = KeyCode.E;
public bool IsEnabled { get; set; } = true;
public Vector2 Move
{
get
{
if (IsEnabled == false)
return Vector2.zero;
return new Vector2(Input.GetAxisRaw(HorizontalAxisKey), Input.GetAxisRaw(VerticalAxisKey));
}
}
public void Enable() => IsEnabled = true;
public void Disable() => IsEnabled = false;
public void Update(float deltaTime)
{
if (IsEnabled == false)
return;
if (Input.GetKeyDown(JumpKey))
OnJump?.Invoke();
if (Input.GetKeyDown(InteractKey))
OnInteract?.Invoke();
if (Input.GetKeyDown(PreviousKey))
OnPrevious?.Invoke();
if (Input.GetKeyDown(NextKey))
OnNext?.Invoke();
}
public string GetKeyboardInput()
{
if (IsEnabled == false)
return null;
for (int i = 0; i <= 9; i++)
if (Input.GetKeyDown(KeyCode.Alpha0 + i))
return i.ToString();
for (int i = 0; i < 26; i++)
{
if (Input.GetKeyDown(KeyCode.A + i))
{
char letter = (char)('A' + i);
return letter.ToString();
}
}
return null;
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6e89482289184f2b93a4ddf77af98da7
timeCreated: 1770397340

View File

@@ -1,13 +0,0 @@
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public interface IInput
{
bool IsEnabled { get; set; }
void Enable();
void Disable();
void Update(float deltaTime);
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 1d448be7d0ba4d988578d646da708c41
timeCreated: 1770397262

View File

@@ -1,20 +0,0 @@
using System;
using UnityEngine;
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public interface IPlayerInputService : IInput
{
event Action OnJump;
event Action OnInteract;
event Action OnPrevious;
event Action OnNext;
Vector2 Move { get; }
string GetKeyboardInput();
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: de8df9e58e214573bb1d44996dc62484
timeCreated: 1770396950

View File

@@ -1,7 +0,0 @@
namespace _Project.Develop.Runtime.Utilities.InputManagement
{
public interface IUIInputService : IInput
{
// всякие клики
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: f60f1acd260a4846943950a6e6682a9b
timeCreated: 1770397255

View File

@@ -0,0 +1,13 @@
using _Project.Develop.Runtime.Utils.InputManagement.Inputs;
namespace _Project.Develop.Runtime.Utils.InputManagement
{
public class InputFactory
{
private UserInputAction _userInput = new();
public PlayerInput CreatePlayerInput() => new(_userInput.Player);
public UIInput CreateUIInput() => new(_userInput.UI);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 31af757382f6411f879de037849b5195
timeCreated: 1770410738

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 13a43e150c044c9aa77c0ac983add8d2
timeCreated: 1770408893

View File

@@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace _Project.Develop.Runtime.Utils.InputManagement
{
public interface IPlayerInput : IInput
{
InputState<Vector2> Move { get; }
InputState<Vector2> Look { get; }
InputState<float> Jump { get; }
InputState<float> Sprint { get; }
InputState<float> Interact { get; }
InputState<float> Crouch { get; }
InputState<float> Previous { get; }
InputState<float> Next { get; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 26e35755eaef45dc9366a75a77333fae
timeCreated: 1770408646

View File

@@ -0,0 +1,15 @@
using System;
using UnityEngine;
namespace _Project.Develop.Runtime.Utils.InputManagement
{
public interface IUIInput : IInput
{
InputState<Vector2> Point { get; }
InputState<Vector2> Navigate { get; }
InputState<float> Click { get; }
InputState<float> RightClick { get; }
InputState<float> MiddleClick { get; }
InputState<Vector2> ScrollWheel { get; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 68276677297d4ea2b4cf908903e2f927
timeCreated: 1770408654

View File

@@ -0,0 +1,52 @@
using UnityEngine;
using PlayerActions = UserInputAction.PlayerActions;
namespace _Project.Develop.Runtime.Utils.InputManagement.Inputs
{
public class PlayerInput : InputBase, IPlayerInput
{
public InputState<Vector2> Move { get; }
public InputState<Vector2> Look { get; }
public InputState<float> Jump { get; }
public InputState<float> Sprint { get; }
public InputState<float> Interact { get; }
public InputState<float> Crouch { get; }
public InputState<float> Previous { get; }
public InputState<float> Next { get; }
private readonly PlayerActions _playerActions;
public PlayerInput(PlayerActions playerActions)
{
_playerActions = playerActions;
Move = Register<Vector2>(_playerActions.Move);
Look = Register<Vector2>(_playerActions.Look);
Jump = Register<float>(_playerActions.Jump);
Sprint = Register<float>(_playerActions.Sprint);
Interact = Register<float>(_playerActions.Interact);
Crouch = Register<float>(_playerActions.Crouch);
Previous = Register<float>(_playerActions.Previous);
Next = Register<float>(_playerActions.Next);
}
public void Initialize()
{
Disable();
}
public override void Enable()
{
base.Enable();
_playerActions.Enable();
}
public override void Disable()
{
base.Disable();
_playerActions.Disable();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3f24c94d005646f18e40368665121d62
timeCreated: 1770408676

View File

@@ -0,0 +1,49 @@
using UnityEngine;
using UIActions = UserInputAction.UIActions;
namespace _Project.Develop.Runtime.Utils.InputManagement.Inputs
{
public class UIInput : InputBase, IUIInput
{
public InputState<Vector2> Point { get; }
public InputState<Vector2> Navigate { get; }
public InputState<float> Click { get; }
public InputState<float> RightClick { get; }
public InputState<float> MiddleClick { get; }
public InputState<Vector2> ScrollWheel { get; }
// public InputState<Vector2> DeviceOrientation { get; }
private readonly UIActions _uiActions;
public UIInput(UIActions uiActions)
{
_uiActions = uiActions;
Point = Register<Vector2>(_uiActions.Point);
Navigate = Register<Vector2>(_uiActions.Navigate);
Click = Register<float>(_uiActions.Click);
RightClick = Register<float>(_uiActions.RightClick);
MiddleClick = Register<float>(_uiActions.MiddleClick);
ScrollWheel = Register<Vector2>(_uiActions.ScrollWheel);
// DeviceOrientation = Register<Vector2>(_uiActions.TrackedDeviceOrientation);
}
public void Initialize()
{
Disable();
}
public override void Enable()
{
base.Enable();
_uiActions.Enable();
}
public override void Disable()
{
base.Disable();
_uiActions.Disable();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bdb01f1b865b461f816e8d4dff0c0aeb
timeCreated: 1770414125

View File

@@ -0,0 +1,7 @@
namespace _Project.Develop.Runtime.Utils.InputManagement
{
public class RebindInputService
{
// ахаха захотел он смену клавиш
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a0db421683434be6adebcb01ebb5b2ff
timeCreated: 1770413119

View File

@@ -1,11 +0,0 @@
using System;
namespace _Project.Develop.Runtime.Utilities.StateMachine
{
public interface IStateChanger
{
event Action<State> Changed;
StateMachine ChangeState<TState>() where TState : State;
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 8b705c6047e545c483833a0fe80a6850
timeCreated: 1770390018

View File

@@ -1,17 +0,0 @@
using System;
namespace _Project.Develop.Runtime.Utilities.StateMachine
{
public abstract class State
{
public event Action Entered;
public event Action Exited;
public virtual void OnEnter() => Entered?.Invoke();
public virtual void OnExit() => Exited?.Invoke();
public virtual void Update(float deltaTime) { }
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 991e020273854d7683766af332608683
timeCreated: 1770376146

View File

@@ -1,79 +0,0 @@
using System;
using System.Collections.Generic;
namespace _Project.Develop.Runtime.Utilities.StateMachine
{
public abstract class StateMachine : IStateChanger
{
public event Action<State> Changed;
public State Current { get; private set; }
private readonly Dictionary<Type, State> _states = new();
private bool _isRunning;
public StateMachine(params State[] states)
{
foreach (State state in states)
Add(state);
}
public void Update(float deltaTime)
{
if (_isRunning == false)
return;
Current?.Update(deltaTime);
}
public StateMachine Add(State state)
{
if (state == null)
throw new ArgumentNullException(nameof(state));
Type type = state.GetType();
if (_states.TryAdd(type, state) == false)
throw new InvalidOperationException($"[StateMachine] State {type.Name} is already registered");
return this;
}
public StateMachine Remove<TState>() where TState : State
{
Type type = typeof(TState);
if (_states.Remove(type) == false)
throw new InvalidOperationException($"[StateMachine] State {type.Name} is not registered");
return this;
}
public StateMachine ChangeState<TState>() where TState : State
{
Type type = typeof(TState);
if (_states.TryGetValue(type, out State state) == false)
throw new InvalidOperationException($"[StateMachine] State {type.Name} is not registered");
SwitchState(state);
return this;
}
private void SwitchState(State newState)
{
if (newState == null)
throw new ArgumentNullException(nameof(newState));
if (Current != null)
Current.OnExit();
else
_isRunning = true;
Current = newState;
Changed?.Invoke(Current);
Current.OnEnter();
}
}
}

View File

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