working on multiplayer
This commit is contained in:
60
Runtime/Engine/Code/Input/InputService.cs
Normal file
60
Runtime/Engine/Code/Input/InputService.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using RebootKit.Engine.Foundation;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace RebootKit.Engine.Services.Input {
|
||||
public class InputService : IService {
|
||||
readonly Config m_Config;
|
||||
|
||||
AsyncOperationHandle<InputActionAsset> m_Handle;
|
||||
InputActionAsset m_InputActionAsset;
|
||||
|
||||
public InputService(Config config) {
|
||||
m_Config = config;
|
||||
|
||||
m_Handle = Addressables.LoadAssetAsync<InputActionAsset>(m_Config.inputAssetReference);
|
||||
m_InputActionAsset = m_Handle.WaitForCompletion();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
m_InputActionAsset = null;
|
||||
|
||||
Addressables.Release(m_Handle);
|
||||
m_Handle = default;
|
||||
}
|
||||
|
||||
public void EnableControls() {
|
||||
m_InputActionAsset.Enable();
|
||||
}
|
||||
|
||||
public void DisableControls() {
|
||||
m_InputActionAsset.Disable();
|
||||
}
|
||||
|
||||
public bool AreControlsEnabled() {
|
||||
return m_InputActionAsset.enabled;
|
||||
}
|
||||
|
||||
public InputAction FindInputAction(string path) {
|
||||
return m_InputActionAsset.FindAction(path);
|
||||
}
|
||||
|
||||
public void LockCursor() {
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
public void UnlockCursor() {
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Config {
|
||||
public AssetReferenceT<InputActionAsset> inputAssetReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user