docs.unity3d.com
    Show / Hide Table of Contents

    Struct FrameTime

    A struct that represents a time relative to a frame sequence, with an optional subframe value.

    Namespace: Unity.LiveCapture
    Syntax
    public struct FrameTime : IComparable, IComparable<FrameTime>, IEquatable<FrameTime>

    Constructors

    FrameTime(Int32, Subframe)

    Creates a new FrameTime instance.

    Declaration
    public FrameTime(int frameNumber, Subframe subframe = default(Subframe))
    Parameters
    Type Name Description
    Int32 frameNumber

    The number of the frame in the sequence.

    Subframe subframe

    The subframe value used to indicate a time somewhere within the duration of the frame.

    Properties

    FrameNumber

    The number of the frame in the sequence.

    Declaration
    public readonly int FrameNumber { get; }
    Property Value
    Type Description
    Int32

    Subframe

    The time within the frame.

    Declaration
    public readonly Subframe Subframe { get; }
    Property Value
    Type Description
    Subframe

    Methods

    Ceil()

    Gets the frame time rounded up to the start of the next frame.

    Declaration
    public FrameTime Ceil()
    Returns
    Type Description
    FrameTime

    A FrameTime with no subframe component.

    CompareTo(Object)

    Compares this instance to a specified object and returns an indication of their relative values.

    Declaration
    public int CompareTo(object obj)
    Parameters
    Type Name Description
    Object obj

    The object to compare with this instance.

    Returns
    Type Description
    Int32

    A signed number indicating the relative values of this instance and obj.

    • Returns a negative value when obj is not a valid FrameTime instance or this instance is less than obj.
    • Returns zero when this instance is the same as obj.
    • Returns a positive value when this instance is greater than obj.

    CompareTo(FrameTime)

    Compares this instance to a specified FrameTime and returns an indication of their relative values.

    Declaration
    public int CompareTo(FrameTime other)
    Parameters
    Type Name Description
    FrameTime other

    The value to compare with this instance.

    Returns
    Type Description
    Int32

    A signed number indicating the relative values of this instance and other.

    • Returns a negative value when this instance is less than other.
    • Returns zero when this instance is the same as other.
    • Returns a positive value when this instance is greater than other.

    Equals(Object)

    Returns a value indicating whether this instance is equal to a specified object.

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

    An object to compare with this instance.

    Returns
    Type Description
    Boolean

    true if obj is an instance of FrameTime and equals the value of this instance; otherwise, false.

    Equals(FrameTime)

    Returns a value indicating whether this instance is equal to a specified FrameTime.

    Declaration
    public bool Equals(FrameTime other)
    Parameters
    Type Name Description
    FrameTime other

    A value to compare with this instance.

    Returns
    Type Description
    Boolean

    true if other has the same value as this instance; otherwise, false.

    Floor()

    Gets the frame time rounded down to the start of the current frame.

    Declaration
    public FrameTime Floor()
    Returns
    Type Description
    FrameTime

    A FrameTime with no subframe component.

    FromFrameTime(Double, Int32)

    Creates a new FrameTime instance from a frame time.

    Declaration
    public static FrameTime FromFrameTime(double frameTime, int subframeResolution = null)
    Parameters
    Type Name Description
    Double frameTime

    The frame time with the frame number in the integer part and the subframe in the decimal part.

    Int32 subframeResolution

    The number of possible subframe values in the frame. If this value is not greater than zero, the subframe value is treated as zero.

    Returns
    Type Description
    FrameTime

    A new FrameTime that represents the given frame time.

    FromSeconds(FrameRate, Double, Int32)

    Creates a new FrameTime instance from a time in seconds and a frame rate.

    Declaration
    public static FrameTime FromSeconds(FrameRate frameRate, double time, int subframeResolution = null)
    Parameters
    Type Name Description
    FrameRate frameRate

    The frame rate of the frame sequence.

    Double time

    The time in seconds.

    Int32 subframeResolution

    The number of possible subframe values in the frame. If this value is not greater than zero, the subframe value is treated as zero.

    Returns
    Type Description
    FrameTime

    A new FrameTime that represents the given time, or langword_csharp_default if frameRate is invalid.

    Remarks

    The input time is clamped to the range [-MaxRepresentableSeconds(FrameRate), MaxRepresentableSeconds(FrameRate)] defined for the provided FrameRate.

    GetHashCode()

    Returns the hash code for this instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    The hash code for this instance.

    MaxRepresentableSeconds(FrameRate)

    Calculates the maximum length of a frame sequence in seconds that can be represented by a FrameTime.

    Declaration
    public static double MaxRepresentableSeconds(FrameRate frameRate)
    Parameters
    Type Name Description
    FrameRate frameRate

    The frame rate of the frame sequence.

    Returns
    Type Description
    Double

    The maximum time in seconds, or langword_csharp_default if frameRate is invalid.

    Remap(FrameTime, FrameRate, FrameRate)

    Converts a FrameTime in a frame sequence with a given FrameRate to a time in a frame sequence with a different FrameTime.

    Declaration
    public static FrameTime Remap(FrameTime frameTime, FrameRate srcRate, FrameRate dstRate)
    Parameters
    Type Name Description
    FrameTime frameTime

    The frame time to remap.

    FrameRate srcRate

    The original frame rate.

    FrameRate dstRate

    The frame rate to convert to.

    Returns
    Type Description
    FrameTime

    A new FrameTime remapped to the the target frame rate, or langword_csharp_default if srcRate or dstRate is invalid.

    Round()

    Gets the frame time rounded to the nearest start of a frame.

    Declaration
    public FrameTime Round()
    Returns
    Type Description
    FrameTime

    A FrameTime with no subframe component.

    Remarks

    Subframe values exactly half way in a frame are rounded towards negative infinity.

    ToSeconds(FrameRate)

    Gets the time in seconds represented by this FrameTime for a given FrameRate.

    Declaration
    public double ToSeconds(FrameRate frameRate)
    Parameters
    Type Name Description
    FrameRate frameRate

    The frame rate of the frame sequence.

    Returns
    Type Description
    Double

    The time in seconds since the start of the frame sequence, or langword_csharp_default if frameRate is invalid.

    ToString()

    Returns a string that represents the current instance.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String

    A string that represents the current instance.

    Operators

    Addition(FrameTime, FrameTime)

    Calculates the sum of two specified FrameTime values.

    Declaration
    public static FrameTime operator +(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first frame time.

    FrameTime b

    The second frame time.

    Returns
    Type Description
    FrameTime

    The sum of a and b.

    Decrement(FrameTime)

    Decrements a FrameTime by a single frame.

    Declaration
    public static FrameTime operator --(FrameTime a)
    Parameters
    Type Name Description
    FrameTime a

    The frame time to Decrement.

    Returns
    Type Description
    FrameTime

    The decremented frame time.

    Equality(FrameTime, FrameTime)

    Determines whether two specified instances of FrameTime are equal.

    Declaration
    public static bool operator ==(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first instance to compare.

    FrameTime b

    The second instance to compare.

    Returns
    Type Description
    Boolean

    true if a and b represent the same value; otherwise, false.

    Explicit(FrameTime to Double)

    Gets the value of a FrameTime as a .

    Declaration
    public static explicit operator double (FrameTime rate)
    Parameters
    Type Name Description
    FrameTime rate

    The value to cast.

    Returns
    Type Description
    Double

    The frame time with the frame number in the integer part and the subframe in the decimal part.

    Explicit(FrameTime to Single)

    Gets the value of a FrameTime as a .

    Declaration
    public static explicit operator float (FrameTime rate)
    Parameters
    Type Name Description
    FrameTime rate

    The value to cast.

    Returns
    Type Description
    Single

    The frame time with the frame number in the integer part and the subframe in the decimal part.

    GreaterThan(FrameTime, FrameTime)

    Determines whether one specified FrameTime is later than another specified FrameTime.

    Declaration
    public static bool operator>(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first instance to compare.

    FrameTime b

    The second instance to compare.

    Returns
    Type Description
    Boolean

    true if a is later than b; otherwise, false.

    GreaterThanOrEqual(FrameTime, FrameTime)

    Determines whether one specified FrameTime is later than or the same as another specified FrameTime.

    Declaration
    public static bool operator >=(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first instance to compare.

    FrameTime b

    The second instance to compare.

    Returns
    Type Description
    Boolean

    true if a is later than or the same as b; otherwise, false.

    Increment(FrameTime)

    Increments a FrameTime by a single frame.

    Declaration
    public static FrameTime operator ++(FrameTime a)
    Parameters
    Type Name Description
    FrameTime a

    The frame time to increment.

    Returns
    Type Description
    FrameTime

    The incremented frame time.

    Inequality(FrameTime, FrameTime)

    Determines whether two specified instances of FrameTime are not equal.

    Declaration
    public static bool operator !=(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first instance to compare.

    FrameTime b

    The second instance to compare.

    Returns
    Type Description
    Boolean

    true if a and b do not represent the same value; otherwise, false.

    LessThan(FrameTime, FrameTime)

    Determines whether one specified FrameTime is earlier than another specified FrameTime.

    Declaration
    public static bool operator <(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first instance to compare.

    FrameTime b

    The second instance to compare.

    Returns
    Type Description
    Boolean

    true if a is earlier than b; otherwise, false.

    LessThanOrEqual(FrameTime, FrameTime)

    Determines whether one specified FrameTime is earlier than or the same as another specified FrameTime.

    Declaration
    public static bool operator <=(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The first instance to compare.

    FrameTime b

    The second instance to compare.

    Returns
    Type Description
    Boolean

    true if a is earlier than or the same as b; otherwise, false.

    Subtraction(FrameTime, FrameTime)

    Calculates the difference between two specified FrameTime values.

    Declaration
    public static FrameTime operator -(FrameTime a, FrameTime b)
    Parameters
    Type Name Description
    FrameTime a

    The frame time.

    FrameTime b

    The frame time to subtract.

    Returns
    Type Description
    FrameTime

    The difference of a from b.

    In This Article
    • Constructors
      • FrameTime(Int32, Subframe)
    • Properties
      • FrameNumber
      • Subframe
    • Methods
      • Ceil()
      • CompareTo(Object)
      • CompareTo(FrameTime)
      • Equals(Object)
      • Equals(FrameTime)
      • Floor()
      • FromFrameTime(Double, Int32)
      • FromSeconds(FrameRate, Double, Int32)
      • GetHashCode()
      • MaxRepresentableSeconds(FrameRate)
      • Remap(FrameTime, FrameRate, FrameRate)
      • Round()
      • ToSeconds(FrameRate)
      • ToString()
    • Operators
      • Addition(FrameTime, FrameTime)
      • Decrement(FrameTime)
      • Equality(FrameTime, FrameTime)
      • Explicit(FrameTime to Double)
      • Explicit(FrameTime to Single)
      • GreaterThan(FrameTime, FrameTime)
      • GreaterThanOrEqual(FrameTime, FrameTime)
      • Increment(FrameTime)
      • Inequality(FrameTime, FrameTime)
      • LessThan(FrameTime, FrameTime)
      • LessThanOrEqual(FrameTime, FrameTime)
      • Subtraction(FrameTime, FrameTime)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023