Skip to content

Game.Input.CompositeUtility

Assembly:
{{ Likely part of the game's input assembly (not specified in file). Include the project/game assembly that contains the Game.Input namespace. }}

Namespace: Game.Input

Type: static class

Base: System.Object

Summary:
Utility helpers for working with input binding composites used by the game's input system. Provides methods to safely read composite part values (including support for modifiers), convert action components to higher-level action types and input action metadata, get/format composite type names, and split/compose Guid values into two 64-bit parts. Many helper methods are extension-style helpers (for ActionComponent/ActionType) and small conversion utilities commonly used by composite input implementations. Some methods rely on UnityEngine.InputSystem types and on project-specific types such as ModifiersComparer, ActionComponent and ActionType.


Fields

  • None
    {{ This is a static utility class and does not declare any fields. All functionality is exposed through static methods and extension methods. }}

Properties

  • None
    {{ There are no properties in this utility class. All features are provided as static methods. }}

Constructors

  • None (static class)
    {{ Being a static class, CompositeUtility has no instance constructor. Any static initialization would be handled via a static constructor if needed; none is present in the source. }}

Methods

  • public unsafe static T ReadValue<T>(ref InputBindingCompositeContext context, int button, bool allowModifiers, int modifier, IComparer<T> comparer) where T : struct
    {{ Reads a composite part value of type T from the given InputBindingCompositeContext. This method is unsafe (delegates to underlying state read) and generic-constrained to value types. It first checks that context.m_State is not null and that modifiers (if provided and allowed) pass via CheckModifiers. If those checks pass, it calls context.m_State.ReadCompositePartValue>(context.m_BindingIndex, button, null, out controlIndex, comparer) and returns the value read. If the state is null or the modifiers check fails, it returns default(T). The comparer parameter is forwarded to the underlying composite part read and can influence how values are aggregated/compared when the composite implementation requires it. Note: this relies on internal state of InputBindingCompositeContext (m_State, m_BindingIndex) and on the project's composite read implementation. }}

  • public static bool ReadValueAsButton(ref InputBindingCompositeContext context, int button, bool allowModifiers, int modifier)
    {{ Reads a composite part value treated as a boolean/button. If context.m_State is null or CheckModifiers fails, the method returns false. Otherwise it calls context.ReadValueAsButton(button) and returns that result. Use this when the composite part represents a binary button-like control. }}

  • public static bool CheckModifiers(ref InputBindingCompositeContext context, bool allowModifiers, int modifier)
    {{ Evaluates whether modifiers (if any) allow reading the composite part. If allowModifiers is true and modifier != 0, this method reads a float value for the modifier part via context.ReadValue(modifier). If the read value is not NaN, the result is true when the value != 0f. If allowModifiers is false or modifier is 0, the method returns true (it uses a default multiplier of 1f). If the value is NaN, the method returns false. In short: returns true when modifiers permit this composite part to be active. Note: ModifiersComparer and the modifier binding index are project-specific. }}

  • public static ActionType GetActionType(this ActionComponent component)
    {{ Extension method mapping an ActionComponent enum to the corresponding ActionType. Mapping implemented with a switch expression:

  • ActionComponent.Press -> ActionType.Button
  • ActionComponent.Negative -> ActionType.Axis
  • ActionComponent.Positive -> ActionType.Axis
  • ActionComponent.Down/Up/Left/Right -> ActionType.Vector2 Throws ArgumentOutOfRangeException for unknown component values. This is used to determine the higher-level action category for an individual component of a composite. }}

  • public static string GetCompositeTypeName(this ActionType actionType)
    {{ Extension method returning the textual composite type name for a given ActionType. Internally maps:

  • ActionType.Button -> name of ButtonWithModifiersComposite (trimmed of the "Composite" suffix)
  • ActionType.Axis -> name of AxisSeparatedWithModifiersComposite (trimmed)
  • ActionType.Vector2 -> name of Vector2SeparatedWithModifiersComposite (trimmed) Throws ArgumentOutOfRangeException for unknown action types. This is useful when constructing composite names for binding introspection or debugging. }}

  • public static InputActionType GetInputActionType(this ActionType actionType)
    {{ Maps ActionType to UnityEngine.InputSystem.InputActionType:

  • ActionType.Button -> InputActionType.Button
  • ActionType.Axis -> InputActionType.Value
  • ActionType.Vector2 -> InputActionType.Value Throws ArgumentOutOfRangeException for unknown action types. This helps set the InputActionType when creating or configuring input actions from the action type. }}

  • public static string GetExpectedControlLayout(this ActionType actionType)
    {{ Returns the expected control layout name for a given ActionType:

  • ActionType.Button -> "Button"
  • ActionType.Axis -> "Axis"
  • ActionType.Vector2 -> "Vector2" Throws ArgumentOutOfRangeException for unknown action types. Use this to assert or request a particular control layout for composite parts. }}

  • public static Guid GetGuid(long part1, long part2)
    {{ Helper to construct a System.Guid from two 64-bit pieces. It creates a 16-byte array, copies the bytes of part1 into the first 8 bytes and part2 into the next 8 bytes, then constructs and returns a Guid from that byte array. Useful when storing Guids as two long fields (e.g., in serialized data or for compact storage). }}

  • public static void SetGuid(Guid guid, out long part1, out long part2)
    {{ Splits a Guid into two 64-bit parts. It converts guid.ToByteArray() to a byte[] and then reads the first and second 8-byte chunks as Int64 to out parameters part1 and part2. This mirrors GetGuid/GetPart usage and is useful when interacting with code or data structures that store Guids as two long values. }}

  • public static string GetCompositeTypeName(Type type)
    {{ Returns a short composite type name for a given Type by taking type.Name and removing a trailing "Composite" suffix if present. For example, ButtonWithModifiersComposite -> ButtonWithModifiers. This is a small helper used by the ActionType->composite name mapping and for display or naming logic. }}

Usage Example

// Example usage patterns for CompositeUtility inside a composite read implementation
using UnityEngine.InputSystem;
using Game.Input;

// Read a typed value from a composite part (T = float here), respecting modifiers.
unsafe void ExampleRead(ref InputBindingCompositeContext context, int partIndex, int modifierIndex)
{
    // comparer can be null if not required by the underlying composite read
    float value = CompositeUtility.ReadValue<float>(ref context, partIndex, allowModifiers: true, modifier: modifierIndex, comparer: null);
    // value will be default(float) (0.0f) if context.m_State is null or modifiers prevent the read
}

// Read a boolean-style part (button) from a composite
bool ExampleReadButton(ref InputBindingCompositeContext context, int partIndex, int modifierIndex)
{
    return CompositeUtility.ReadValueAsButton(ref context, partIndex, allowModifiers: true, modifier: modifierIndex);
}

// Convert component -> high-level action type and expected control layout
void ExampleMappings(ActionComponent component)
{
    ActionType actionType = component.GetActionType();
    InputActionType inputActionType = actionType.GetInputActionType();
    string expectedLayout = actionType.GetExpectedControlLayout();
    string compositeName = actionType.GetCompositeTypeName();
    // Use these values to configure an InputAction or for diagnostics
}

// Guid packing/unpacking
void ExampleGuid()
{
    Guid original = Guid.NewGuid();
    CompositeUtility.SetGuid(original, out long p1, out long p2);
    Guid reconstructed = CompositeUtility.GetGuid(p1, p2);
    // reconstructed == original
}

{{ Additional notes: - The utility methods assume the presence of project-specific types such as ActionComponent, ActionType, and ModifiersComparer; ensure these enums/types are available and documented. - ReadValue uses internal fields of InputBindingCompositeContext (m_State, m_BindingIndex); these are internal details of the input system—use with care and ensure compatibility with the Unity Input System version used by the project. - Methods that map enums throw ArgumentOutOfRangeException for unknown values; callers should ensure valid enum values or handle exceptions. }}