The Script class is used to create the parent class of a script, which is an abstract class and does not allow instances.

Script 类用于创建脚本的父类,该类为抽象类,不允许实例。

层级 (查看完整内容)

构造函数

属性

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.

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

owner: Sprite | Sprite3D

Script belonging to sprite

脚本所属精灵

runInEditor: boolean

Whether the script can run in the IDE environment.

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

scriptPath: string

The path of the script file.

脚本文件的路径。

访问器

方法

  • 返回 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

    Called when a 3D physics collider event begins (not applicable to 2D).

    3D物理碰撞器事件开始时调用(不适用于2D)。

  • 参数

    返回 void

    Called when a 3D physics collider event ends (not applicable to 2D).

    3D物理碰撞器事件结束碰撞时调用(不适用于2D)。

  • 参数

    返回 void

    Called during the frame a 3D physics collider event stays collided (not applicable to 2D).

    3D物理碰撞器事件持续碰撞时调用(不适用于2D)。

  • 参数

    • evt: Event

      The keyboard event.

    返回 void

    Called when a key is pressed and holds long enough to generate a character.

    键盘产生一个字符时执行。

  • 参数

    • evt: Event

      The mouse event.

    返回 void

    Called when the mouse button is clicked (pressed and released) on the node.

    鼠标点击时执行。

  • 参数

    • evt: Event

      The mouse event.

    返回 void

    Called when the mouse is held down and an object is dragged.

    鼠标按住一个物体后,拖拽时执行。

  • 参数

    • evt: Event

      The mouse event.

    返回 void

    Called when the mouse button is released after dragging an object.

    鼠标按住一个物体,拖拽一定距离,释放鼠标按键后执行。

  • 参数

    • evt: Event

      The mouse event.

    返回 void

    Called when the right mouse button is clicked on the node.

    鼠标右键点击时执行。

  • 返回 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.

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

  • 参数

    • evt: Event

      The mouse event.

    返回 void

    Called when the right or middle mouse button is pressed down.

    鼠标右键或中键按下时执行。

  • 参数

    • evt: Event

      The mouse event.

    返回 void

    Called when the right or middle mouse button is released.

    鼠标右键或中键抬起时执行。

  • 参数

    • other: PhysicsColliderComponent | ColliderBase

      The collider component or base of the other object in the collision.

    • 可选self: ColliderBase

      The collider component or base of the object itself.

    • 可选contact: any

      The contact point information.

    返回 void

    Called when a 3D physics trigger event or a 2D physics collision event begins.

    开始碰撞时执行的3D物理触发器事件或2D物理碰撞事件。

  • 参数

    • other: PhysicsColliderComponent | ColliderBase

      The collider component or base of the other object in the collision.

    • 可选self: ColliderBase

      The collider component or base of the object itself.

    • 可选contact: any

      The contact point information.

    返回 void

    Called when a 3D physics trigger event or a 2D physics collision event ends.

    结束碰撞时执行的3D物理触发器事件或2D物理碰撞事件。

  • 参数

    • other: PhysicsColliderComponent | ColliderBase

      The collider component or base of the other object in the collision.

    • 可选self: ColliderBase

      The collider component or base of the object itself, if not provided it's assumed to be the owner of the script.

    • 可选contact: any

      The contact point information, can be any type depending on the physics engine used.

    返回 void

    Called during the frame a 3D physics trigger event or a 2D physics collision event stays collided.

    持续碰撞时执行的3D物理触发器事件或2D物理碰撞事件。

  • 返回 void

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

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