Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace UnityEngine.InputSystem
///
/// <example>
/// <code>
/// using UnityEngine;
/// using UnityEngine.InputSystem;
/// // Component to sit next to PlayerInput.
/// [RequireComponent(typeof(PlayerInput))]
/// public class MyPlayerLogic : MonoBehaviour
Expand Down Expand Up @@ -519,6 +521,8 @@ public PlayerNotifications notificationBehavior
/// <remarks>
/// This array is only used if <see cref="notificationBehavior"/> is set to
/// <see cref="UnityEngine.InputSystem.PlayerNotifications.InvokeUnityEvents"/>.
///
/// The list of actions will be dependent on the <see cref="InputActionAsset"/> specified in the <see cref="PlayerInput"/> Editor UI.
/// </remarks>
public ReadOnlyArray<ActionEvent> actionEvents
{
Expand Down Expand Up @@ -783,7 +787,7 @@ public ReadOnlyArray<InputDevice> devices
/// </summary>
/// <value>True if the player is missing devices required by the control scheme.</value>
/// <remarks>
/// This can happen, for example, if the a device is unplugged during the game.
/// This can happen, for example, if a device is unplugged during the game.
/// </remarks>
/// <seealso cref="InputControlScheme.deviceRequirements"/>
/// <seealso cref="InputUser.hasMissingRequiredDevices"/>
Expand Down Expand Up @@ -1978,19 +1982,67 @@ private void SwitchControlSchemeInternal(ref InputControlScheme controlScheme, p
}
}

/// <summary>
/// An event associated with an PlayerInput action.
/// </summary>
/// <remarks>
/// Represents an event invoked in response to actions being triggered.
///
/// Contains the ID and name of the <see cref="InputAction"/> being triggered and the associated <see cref="UnityAction"/> to handle the action response.
///
/// The list of action events is specified in <see cref="PlayerInput"/> Editor UI based on the selected <see cref="InputActionAsset"/>.
/// The individual action callbacks are then specified in a <see cref="MonoBehaviour"/>.
///
/// <example>
/// <code>
/// public class MyPlayerScript : MonoBehaviour
/// {
/// void OnFireEvent(InputAction.CallbackContext context)
/// {
/// // Handle fire event
/// }
/// }
/// </code>
/// </example>
/// </remarks>
/// <seealso cref="PlayerInput.actionEvents"/>
[Serializable]
public class ActionEvent : UnityEvent<InputAction.CallbackContext>
{
/// <summary>
/// Action GUID string for the action that triggered the event.
/// </summary>
public string actionId => m_ActionId;

/// <summary>
/// Name of the action that triggered the event.
/// </summary>
public string actionName => m_ActionName;

[SerializeField] private string m_ActionId;
[SerializeField] private string m_ActionName;

/// <summary>
/// Construct an empty action event.
/// </summary>
/// <remarks>
/// The event will not have an associated action.
/// </remarks>
/// <seealso cref="PlayerInput.actionEvents"/>
public ActionEvent()
{
}

/// <summary>
/// Construct an action event and associate it with an action.
/// </summary>
/// <remarks>
/// The event will be associated with the specified action. The action must be part of an action asset.
/// </remarks>
/// <param name="action">The action to associate with the event. The action must be part of an action asset.</param>
/// <exception cref="ArgumentNullException">The action is <c>null</c>.</exception>
/// <exception cref="ArgumentException">The action is not part of an action asset.</exception>
/// <seealso cref="PlayerInput.actionEvents"/>
public ActionEvent(InputAction action)
{
if (action == null)
Expand All @@ -2004,6 +2056,15 @@ public ActionEvent(InputAction action)
m_ActionName = $"{action.actionMap.name}/{action.name}";
}

/// <summary>
/// Construct an action event and associated it with an action by GUID.
/// </summary>
/// <remarks>
/// The event will be associated with the specified action.
/// </remarks>
/// <param name="actionGUID">Action GUID</param>
/// <param name="name">Name of the action</param>
/// <seealso cref="PlayerInput.actionEvents"/>
public ActionEvent(Guid actionGUID, string name = null)
{
m_ActionId = actionGUID.ToString();
Expand Down
Loading