36 lines
960 B
C#
36 lines
960 B
C#
using System;
|
|
using Reset;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class InputFinder : MonoBehaviour{
|
|
public InputActionMap actionMap;
|
|
|
|
void Start(){
|
|
actionMap.actions[0].performed += ctx => { InputPressed(ctx); };
|
|
|
|
GetComponent<UIDocument>().enabled = false;
|
|
}
|
|
|
|
public void AwaitNewInput(){
|
|
GameManager.ClearCurrentController();
|
|
|
|
GetComponent<UIDocument>().enabled = true;
|
|
actionMap.Enable();
|
|
}
|
|
|
|
void InputPressed(InputAction.CallbackContext context){
|
|
try {
|
|
GameManager.AttachControllerToPlayer(context.control.device);
|
|
Debug.Log(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();
|
|
}
|
|
}
|