52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Reset.Core.Tools;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.InputSystem.Users;
|
|
|
|
namespace Reset{
|
|
public static class GameManager{
|
|
public static GameObject UI;
|
|
public static GameObject Camera;
|
|
public static GameObject Input;
|
|
public static SessionManager Session;
|
|
|
|
public static GameObject Player;
|
|
|
|
[RuntimeInitializeOnLoadMethod]
|
|
static void PopulateSceneReferences(){
|
|
try {
|
|
UI = GameObject.Find("UICanvas");
|
|
Camera = GameObject.Find("CameraGroup");
|
|
Input = GameObject.Find("InputManager");
|
|
} catch (Exception e) {
|
|
Console.WriteLine(e);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public static void AttachControllerToPlayer(InputDevice device){
|
|
if (!Player) {
|
|
throw new Exception(message: "There is no player to attach this new input device to.");
|
|
}
|
|
|
|
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
|
playerUser = InputUser.PerformPairingWithDevice(device, playerUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
|
|
}
|
|
|
|
public static void RequestNewController(){
|
|
try {
|
|
GameObject.Find("Input Selector").GetComponent<InputFinder>().AwaitNewInput();
|
|
} catch (Exception e) {
|
|
Debug.LogError($"Can't request a new controller: {e.Message}");
|
|
}
|
|
}
|
|
|
|
public static void ClearCurrentController(){
|
|
InputUser playerUser = Player.GetComponent<PlayerInput>().user;
|
|
playerUser.UnpairDevices();
|
|
}
|
|
|
|
}
|
|
} |