The Component class is used to create the base class for components.

Component 类用于创建组件的基类。

层级 (查看完整内容)

属性

Extra data of the node.

组件的额外数据。IDE内部使用。

_id: number

Unique identifier for the component.

组件的唯一标识。

_singleton: boolean

Whether the component is a singleton, meaning only one instance of this type of script can be added to the same node.

是否为单例,即同一个节点只能添加此类型的脚本一次。

mode: "player" | "decoder" = "decoder"

视频播放模式。如果设置的模式不支持,会尝试使用另外一种模式。 -- player: 使用播放器。这时播放器是浮动在主画布上面(或下面)的,不能与嵌套在UI层级中。 -- decoder: 使用解码器。视频会被捕获到Texture再显示,因此可以嵌套在UI层级中。

Video playback mode. If the set mode is not supported, it will try to use another mode. -- player: Use the player. The player is floating above (or below) the main canvas and cannot be nested in the UI hierarchy. -- decoder: Use the decoder. The video is captured to a Texture and then displayed, so it can be nested in the UI hierarchy.

options: IVideoPlayerOptions = ...

Video player options. These options need to be set before setting the source, and if you change the settings, you need to reset the source.

视频播放器选项。这些选项需要在设置source前设置好,如果更改设置,需要重新设置source。

runInEditor: boolean

Whether the script can run in the IDE environment.

是否可以在 IDE 环境中运行。

scriptPath: string

The path of the script file.

脚本文件的路径。

访问器

  • get duration(): number
  • 返回 number

    The video duration in seconds. Available after the ready event is triggered.

    视频长度(秒)。ready 事件触发后可用。

  • get playbackRate(): number
  • 返回 number

    The current playback speed of the video. For example:

    • 1.0: Normal speed
    • 0.5: Half speed (slower)
    • 2.0: Double speed (faster)
    • -1.0: Backwards, normal speed
    • -0.5: Backwards, half speed Note: Only Google Chrome and Safari support the playbackRate property.

    视频的当前播放速度。例如:

    • 1.0:正常速度
    • 0.5:半速(更慢)
    • 2.0:倍速(更快)
    • -1.0:向后,正常速度
    • -0.5:向后,半速 注意:只有 Google Chrome 和 Safari 支持 playbackRate 属性。
  • set playbackRate(value): void
  • 参数

    • value: number

    返回 void

  • get readyState(): number
  • 返回 number

    The ready state of the video element:

    • 0 = HAVE_NOTHING - No information is available about the audio/video readiness
    • 1 = HAVE_METADATA - Metadata about the audio/video is ready
    • 2 = HAVE_CURRENT_DATA - Data for the current playback position is available, but not enough to play the next frame/millisecond
    • 3 = HAVE_FUTURE_DATA - Data for the current and at least the next frame is available
    • 4 = HAVE_ENOUGH_DATA - Enough data is available to begin playback

    视频元素的就绪状态:

    • 0 = HAVE_NOTHING - 没有关于音频/视频是否就绪的信息
    • 1 = HAVE_METADATA - 关于音频/视频就绪的元数据
    • 2 = HAVE_CURRENT_DATA - 关于当前播放位置的数据是可用的,但没有足够的数据来播放下一帧/毫秒
    • 3 = HAVE_FUTURE_DATA - 当前及至少下一帧的数据是可用的
    • 4 = HAVE_ENOUGH_DATA - 可用数据足以开始播放
  • get videoHeight(): number
  • 返回 number

    The video source height. Available after the ready event is triggered.

    视频源高度。ready 事件触发后可用。

  • get videoWidth(): number
  • 返回 number

    The video source width. Available after the ready event is triggered.

    视频源宽度。ready 事件触发后可用。

方法

  • 返回 void

    Called after the component is added to a node. Unlike Awake, onAdded is called even if the node is not active.

    组件被添加到节点后调用,与 onAwake 不同的是,即使节点未激活也会调用 onAdded。

  • 返回 void

    Executed after the component is activated. At this point, all nodes and components have been created. This method is executed only once.

    组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次。

  • 返回 void

    Resets the component's parameters to their default values. If this function is implemented, the component will be reset and automatically recycled for future use. If not reset, it will not be recycled for reuse.

    将组件的参数重置为默认值。如果实现了这个函数,组件将被重置并自动回收到对象池,方便下次复用。 如果没有重置,则不会进行回收复用。

  • 返回 void

    Executed every frame during the update phase. Avoid writing complex loop logic or using the getComponent method here.

    每帧更新时执行,在 update 阶段。尽量不要在这里写大循环逻辑或使用 getComponent 方法。