docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct ActionSegment<T>

    ActionSegment is a data structure that allows access to a segment of an underlying array in order to avoid the copying and allocation of sub-arrays. The segment is defined by the offset into the original array, and an length.

    Implements
    IEnumerable<T>
    IEnumerable
    IEquatable<ActionSegment<T>>
    Inherited Members
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.MLAgents.Actuators
    Assembly: Unity.ML-Agents.dll
    Syntax
    public readonly struct ActionSegment<T> : IEnumerable<T>, IEnumerable, IEquatable<ActionSegment<T>> where T : struct
    Type Parameters
    Name Description
    T

    The type of object stored in the underlying Array

    Constructors

    ActionSegment(T[])

    Construct an ActionSegment<T> with just an actionArray. The Offset will be set to 0 and the Length will be set to actionArray.Length.

    Declaration
    public ActionSegment(T[] actionArray)
    Parameters
    Type Name Description
    T[] actionArray

    The action array to use for the this segment.

    ActionSegment(T[], int, int)

    Construct an ActionSegment<T> with an underlying array and offset, and a length.

    Declaration
    public ActionSegment(T[] actionArray, int offset, int length)
    Parameters
    Type Name Description
    T[] actionArray

    The underlying array which this segment has a view into

    int offset

    The zero-based offset into the underlying array.

    int length

    The length of the segment.

    Fields

    Empty

    An Empty segment which has an offset of 0, a Length of 0, and it's underlying array is also empty.

    Declaration
    public static ActionSegment<T> Empty
    Field Value
    Type Description
    ActionSegment<T>

    Length

    The number of items this segment can access in the underlying array.

    Declaration
    public readonly int Length
    Field Value
    Type Description
    int

    Offset

    The zero-based offset into the original array at which this segment starts.

    Declaration
    public readonly int Offset
    Field Value
    Type Description
    int

    Properties

    Array

    Get the underlying Array of this segment.

    Declaration
    public T[] Array { get; }
    Property Value
    Type Description
    T[]

    this[int]

    Allows access to the underlying array using array syntax.

    Declaration
    public T this[int index] { get; set; }
    Parameters
    Type Name Description
    int index

    The zero-based index of the segment.

    Property Value
    Type Description
    T
    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown when the index is less than 0 or greater than or equal to Length

    Methods

    Clear()

    Sets the segment of the backing array to all zeros.

    Declaration
    public void Clear()

    Equals(object)

    Indicates whether the current ActionSegment is equal to another ActionSegment.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    An ActionSegment to compare with this ActionSegment.

    Returns
    Type Description
    bool

    true if the current ActionSegment is equal to the other parameter; otherwise, false.

    Overrides
    ValueType.Equals(object)

    Equals(ActionSegment<T>)

    Indicates whether the current ActionSegment is equal to another ActionSegment.

    Declaration
    public bool Equals(ActionSegment<T> other)
    Parameters
    Type Name Description
    ActionSegment<T> other

    An ActionSegment to compare with this ActionSegment.

    Returns
    Type Description
    bool

    true if the current ActionSegment is equal to the other parameter; otherwise, false.

    GetEnumerator()

    Returns an enumerator that iterates through the ActionSegment.

    Declaration
    public IEnumerator GetEnumerator()
    Returns
    Type Description
    IEnumerator

    An IEnumerator object that can be used to iterate through the ActionSegment.

    GetHashCode()

    Computes the hash code of the ActionSegment.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A hash code for the current ActionSegment.

    Overrides
    ValueType.GetHashCode()

    IsEmpty()

    Check if the segment is empty.

    Declaration
    public bool IsEmpty()
    Returns
    Type Description
    bool

    Whether or not the segment is empty.

    Implements

    IEnumerable<T>
    IEnumerable
    IEquatable<T>
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)