This commit is contained in:
2025-07-11 14:40:42 +02:00
parent c39b87ed44
commit 0da6f275c0
42 changed files with 756 additions and 226 deletions

View File

@@ -1,29 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RebootKit.Engine.Foundation;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Assertions;
using UnityEngine.InputSystem;
using UnityEngine.ResourceManagement.AsyncOperations;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Input {
public class InputState {
public string Name { get; private set; }
public bool HideCursor { get; private set; }
public bool LockCursor { get; private set; }
public InputState(string name, bool hideCursor = false, bool lockCursor = false) {
Name = name;
HideCursor = hideCursor;
LockCursor = lockCursor;
}
}
public class InputService : IService {
static readonly Logger s_Logger = new Logger(nameof(InputService));
readonly Config m_Config;
AsyncOperationHandle<InputActionAsset> m_Handle;
InputActionAsset m_InputActionAsset;
List<InputState> m_States = new List<InputState>(16);
public InputService(Config config) {
m_Config = config;
// m_Handle = Addressables.LoadAssetAsync<InputActionAsset>(m_Config.inputAssetReference);
m_InputActionAsset = config.inputActionAsset;
}
public void Dispose() {
m_InputActionAsset = null;
}
public void AddState(InputState state) {
Assert.IsFalse(m_States.Contains(state), "State already exists in the input service.");
Assert.IsNotNull(state, "Input state cannot be null.");
Assert.IsNull(m_States.FirstOrDefault(t => t.Name.Equals(state.Name, StringComparison.Ordinal)),
$"State with name '{state.Name}' already exists in the input service.");
// Addressables.Release(m_Handle);
m_Handle = default;
m_States.Add(state);
}
public void EnableControls() {
@@ -54,7 +76,6 @@ namespace RebootKit.Engine.Input {
[Serializable]
public class Config {
public AssetReferenceT<InputActionAsset> inputAssetReference;
public InputActionAsset inputActionAsset;
}
}

View File

@@ -1,15 +0,0 @@
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Input;
using UnityEngine;
namespace RebootKit.Engine.Services.Input {
[CreateAssetMenu(menuName = RConsts.k_ServiceAssetMenu + "Input")]
public class InputServiceAsset : ServiceAsset<InputService> {
[SerializeField] InputService.Config m_Config;
public override InputService Create() {
InputService instance = new InputService(m_Config);
return instance;
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 8fcf71fe79ef1ed4cbfdefde09e708d9

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace RebootKit.Engine.Services.Input {
namespace RebootKit.Engine.Input {
[CreateAssetMenu(menuName = RConsts.k_AddComponentMenu + "Input Action", fileName = "Input Action")]
public class ScriptableInputAction : ScriptableObject {
[field: SerializeField]