using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace SC.XR.Unity.Simulation {
///
/// Use this class to automatically enable or disable all the inputs of type
/// in a list of assets of type .
///
///
/// Actions are initially disabled, meaning they do not listen/react to input yet. This class
/// is used to mass enable actions so that they actively listen for input and run callbacks.
///
///
public class InputActionManager : MonoBehaviour
{
[SerializeField]
[Tooltip("Input action assets to affect when inputs are enabled or disabled.")]
List m_ActionAssets;
///
/// Input action assets to affect when inputs are enabled or disabled.
///
public List actionAssets
{
get => m_ActionAssets;
set => m_ActionAssets = value ?? throw new ArgumentNullException(nameof(value));
}
protected void OnEnable()
{
EnableInput();
}
protected void OnDisable()
{
DisableInput();
}
///
/// Enable all actions referenced by this component.
///
///
/// This function will automatically be called when this component is enabled.
/// However, this method can be called to enable input manually, such as after disabling it with .
///
/// Note that enabling inputs will only enable the action maps contained within the referenced
/// action map assets (see ).
///
///
public void EnableInput()
{
if (m_ActionAssets == null)
return;
foreach (var actionAsset in m_ActionAssets)
{
if (actionAsset != null)
{
actionAsset.Enable();
}
}
}
///
/// Disable all actions referenced by this component.
///
///
/// This function will automatically be called when this component is disabled.
/// However, this method can be called to disable input manually, such as after enabling it with .
///
/// Note that disabling inputs will only disable the action maps contained within the referenced
/// action map assets (see ).
///
///
public void DisableInput()
{
if (m_ActionAssets == null)
return;
foreach (var actionAsset in m_ActionAssets)
{
if (actionAsset != null)
{
actionAsset.Disable();
}
}
}
}
}