Utils is a utility class.

Utils 是工具类。

构造函数

方法

  • 参数

    • ver1: string

      The first version string.

    • ver2: string

      The second version string.

    返回 -1 | 0 | 1

    1 if ver1 > ver2, -1 if ver1 < ver2, 0 if they are equal.

    Compares two version strings.

    比较两个版本字符串。

  • 参数

    • path: string

      The file path.

    返回 string

    The base name of the file, including the extension.

    Gets the base name of the file from the specified path, including the extension.

    从指定路径中获取文件名(包含扩展名)。

  • 参数

    • path: string

      The file path.

    • withoutExtension: boolean

      Whether to exclude the file extension. Default is false.

    返回 string

    The base name of the file, optionally excluding the extension.

    Gets the base name of the file from the specified path, optionally excluding the extension.

    从指定路径中获取文件名(可选地不包含扩展名)。

  • 参数

    • path: string

    返回 string

    Gets the file extension from the specified path and converts it to lowercase. For example, "1. abc" will return abc.

    从指定路径获取文件扩展名,并转换为小写字母。例如"1.abc"将返回abc。

  • 参数

    • target: Object

      The target. It's optional.

    • 可选method: string | Function

      The method, it can be a function or a function name.

    返回 string

    A unique ID for the given target-method pair.

    Assigns a global unique ID for the given target-method pair.

    为一个target-method对分配一个全局唯一ID。

  • 参数

    • str: string

      The string to check.

    返回 boolean

    True if the string is in UUID format, false otherwise.

    Checks if the given string is a valid UUID format.

    判断一个字符串是否是有效的UUID格式。

  • 参数

    • str: string

      The string to be parsed.

    • radix: number = 0

      The radix for parsing the number (between 2 and 36). Defaults to 0, which means decimal. The other values range from 2 to 36. If it starts with "0xX" or "0X", it will be based on 16. If the parameter is not within the above range, this method returns 0.

    返回 number

    The parsed number.

    Parses a string and returns an integer. Unlike the native JavaScript parseInt, if the string is empty or not a number, this method returns 0 instead of NaN.

    解析字符串并返回一个整数。与 JavaScript 原生的 parseInt 不同,如果字符串为空或非数字,这里返回 0 而不是 NaN。

  • 参数

    • template: string

      The template string.

    • vars: Record<string, any>

      The specified values.

    返回 string

    The new string.

    Parses a template string and returns a new string by replacing the placeholders with the specified values.

    解析模板字符串,并返回一个新字符串,替换占位符为指定值。

  • 参数

    • path: string

      The file path.

    • newExt: string

      The new file extension.

    • 可选excludeDot: boolean

      Whether to exclude the dot prefix in the new extension. Default is false.

    返回 string

    The path with the new file extension.

    Changes the file extension of the specified path.

    更改指定路径的文件扩展名。

  • 类型参数

    • T
    • T2

    参数

    • datas: T2[]

      The array of data to process.

    • numParallelTasks: number

      The maximum number of parallel tasks to run.

    • taskFunc: ((data: T2, index: number) => T | Promise<T>)

      The function to run for each item in the datas array. It should return a value or a Promise.

        • (data, index): T | Promise<T>
        • 参数

          • data: T2
          • index: number

          返回 T | Promise<T>

    • 可选abortToken: IAbortToken

      An optional token to signal task

    返回 Promise<PromiseSettledResult<T>[]>

    Runs a task function for each item in the datas array, allowing a specified number of parallel tasks.

    运行任务函数处理 datas 数组中的每个项目,允许指定数量的并行任务。

  • 类型参数

    • T
    • T2

    参数

    • datas: T2[]

      The array of data to process.

    • checkConcurrency: ((numTasks: number) => boolean)

      it will be called with the number of tasks to determine if more tasks can be run.

        • (numTasks): boolean
        • 参数

          • numTasks: number

          返回 boolean

    • taskFunc: ((data: T2, index: number) => T | Promise<T>)

      The function to run for each item in the datas array. It should return a value or a Promise.

        • (data, index): T | Promise<T>
        • 参数

          • data: T2
          • index: number

          返回 T | Promise<T>

    • 可选abortToken: IAbortToken

      An optional token to signal task

    返回 Promise<PromiseSettledResult<T>[]>

    Runs a task function for each item in the datas array, allowing a specified number of parallel tasks.

    运行任务函数处理 datas 数组中的每个项目,允许指定数量的并行任务。

  • 类型参数

    • T
    • T2

    参数

    • datas: T2[]

      The array of data to process.

    • numParallelTasks: number

      The maximum number of parallel tasks to run.

    • taskFunc: ((data: T2, index: number) => T | Promise<T>)

      The function to run for each item in the datas array. It should return a value or a Promise.

        • (data, index): T | Promise<T>
        • 参数

          • data: T2
          • index: number

          返回 T | Promise<T>

    • 可选abortToken: IAbortToken

      An optional token to signal task abortion. If the token's aborted property is true, the task will be aborted.

    返回 Promise<T[]>

    Runs a task function for each item in the datas array, allowing a specified number of parallel tasks.

    运行任务函数处理 datas 数组中的每个项目,允许指定数量的并行任务。

  • 类型参数

    • T
    • T2

    参数

    • datas: T2[]

      The array of data to process.

    • checkConcurrency: ((numTasks: number) => boolean)

      It will be called with the number of tasks to determine if more tasks can be run.

        • (numTasks): boolean
        • 参数

          • numTasks: number

          返回 boolean

    • taskFunc: ((data: T2, index: number) => T | Promise<T>)

      The function to run for each item in the datas array. It should return a value or a Promise.

        • (data, index): T | Promise<T>
        • 参数

          • data: T2
          • index: number

          返回 T | Promise<T>

    • 可选abortToken: IAbortToken

      An optional token to signal task abortion. If the token's aborted property is true, the task will be aborted.

    返回 Promise<T[]>

    Runs a task function for each item in the datas array, allowing a specified number of parallel tasks.

    运行任务函数处理 datas 数组中的每个项目,允许指定数量的并行任务。

  • 参数

    • timeout: number

      The number of milliseconds to sleep.

    返回 Promise<void>

    Sleeps for the specified number of milliseconds.

    睡眠指定的毫秒数。

  • 参数

    • x: number

      The x-coordinate of the point.

    • y: number

      The y-coordinate of the point.

    • areaPoints: number[]

      An array of points representing the polygon, where each pair of numbers represents the x and y coordinates of a vertex.

    返回 boolean

    True if the point is inside the polygon, false otherwise.

    Determines whether a point is inside a polygon.

    坐标是否在多边形内

  • 参数

    • radian: number

      The radian value.

    返回 number

    The angle value in degrees.

    Converts radians to an angle.

    将弧度转换为角度。

  • 参数

    • angle: number

      The angle value.

    返回 number

    The radian value.

    Converts an angle to radians.

    将角度转换为弧度。

  • 参数

    返回 string

    The converted Base64 string

    请使用uint8ArrayToArrayBufferAsync函数代替

    Converts a RenderTexture to a Base64 encoded string.

    将RenderTexture转换为Base64

  • 参数

    返回 Promise<string>

    A promise that resolves to a Base64 string representing the RenderTexture.

    Converts a RenderTexture to a Base64 encoded string.

    将 RenderTexture 转换为 Base64 编码的字符串。

  • 参数

    • predicate: (() => boolean)

      The function to check the condition.

        • (): boolean
        • 返回 boolean

    • 可选timeout: number

      The maximum time to wait in milliseconds. If not specified,

    返回 Promise<void>

    Waits until the specified predicate function returns true or the timeout is reached.

    等待直到指定的谓词函数返回 true 或超时。