Files
project-reset/Assets/Scripts/Core/InputFinder.cs

37 lines
1010 B
C#

using System;
using Reset;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;
namespace Reset.Units{
public class InputFinder : MonoBehaviour{
public InputActionMap actionMap;
void Start(){
actionMap.actions[0].performed += ctx => { InputPressed(ctx); };
GetComponent<UIDocument>().enabled = false;
}
public void AwaitNewInput(){
PlayerManager.ClearCurrentController();
GetComponent<UIDocument>().enabled = true;
actionMap.Enable();
}
void InputPressed(InputAction.CallbackContext context){
try {
PlayerManager.AttachControllerToPlayer(context.control.device);
} catch (Exception e) {
Debug.LogError($"Failed to set the new device to the player: {e.Message}");
return;
}
GetComponent<UIDocument>().enabled = false;
actionMap.Disable();
}
}
}