# Class AudioManager

音频管理

### Example

    // 模块功能通过 oops.audio 调用
    oops.audio.playMusic("audios/nocturne");

#### Hierarchy

- Component
  - AudioManager

- Defined in assets/core/common/audio/AudioManager.ts:14

#####
Index

### Constructors

constructor

### Properties

__editorExtras__
__prefab
_enabled
_id
_name
_objFlags
_sceneGetter
_switch_effect
_switch_music
_volume_effect
_volume_music
effect
local_data
music
node
EventHandler
system

### Accessors

__scriptAsset
_isOnLoadCalled
enabled
enabledInHierarchy
hideFlags
isValid
name
progressMusic
switchEffect
switchMusic
uuid
volumeEffect
volumeMusic

### Methods

__preload?
_destroyImmediate
_destruct
_getLocalBounds?
_getRenderScene
_instantiate
_onPreDestroy
addComponent
destroy
getComponent
getComponentInChildren
getComponents
getComponentsInChildren
lateUpdate?
load
onDestroy?
onDisable?
onEnable?
onFocusInEditor?
onLoad?
onLostFocusInEditor?
onRestore?
pauseAll
playEffect
playMusic
playMusicLoop
releaseEffect
resetInEditor?
resumeAll
save
schedule
scheduleOnce
setMusicComplete
setState
setStateDefault
start?
stopAll
stopMusic
unschedule
unscheduleAllCallbacks
update?
_deferredDestroy

## Constructors

### constructor

- new AudioManager(name?: string): AudioManager

- #### Parameters

  - ##### `Optional` name: string

  #### Returns AudioManager

  Inherited from Component.constructor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20883

## Properties

### `Internal` __editorExtras__

__editorExtras__: unknown

Inherited from Component.__editorExtras__

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20877

### `Internal` __prefab

__prefab: null | CompPrefabInfo

Inherited from Component.__prefab

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25393

### _enabled

_enabled: boolean

### Deprecated

since v3.5.0, this is an engine private interface that will be removed in the future.

Inherited from Component._enabled

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25389

### _id

_id: string

For internal usage.

### Deprecated

since v3.5.0, this is an engine private interface that will be removed in the future.

Inherited from Component._id

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25402

### `Protected` _name

_name: string

Inherited from Component._name

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20882

### `Internal` _objFlags

_objFlags: number

Inherited from Component._objFlags

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20881

### `Internal` _sceneGetter

_sceneGetter: null | (() => RenderScene)

Inherited from Component._sceneGetter

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25397

### `Private` _switch_effect

_switch_effect: boolean = true

- Defined in assets/core/common/audio/AudioManager.ts:22

### `Private` _switch_music

_switch_music: boolean = true

- Defined in assets/core/common/audio/AudioManager.ts:21

### `Private` _volume_effect

_volume_effect: number = 1

- Defined in assets/core/common/audio/AudioManager.ts:20

### `Private` _volume_music

_volume_music: number = 1

- Defined in assets/core/common/audio/AudioManager.ts:19

### effect

effect: AudioEffect = ...

- Defined in assets/core/common/audio/AudioManager.ts:16

### `Private` local_data

local_data: any = {}

- Defined in assets/core/common/audio/AudioManager.ts:18

### music

music: AudioMusic = ...

- Defined in assets/core/common/audio/AudioManager.ts:15

### node

node: Node

### En

The node this component is attached to. A component is always attached to a node.

### Zh

该组件被附加到的节点。组件总会附加到一个节点。

### Example

    import { log } from 'cc';
    log(comp.node);

Inherited from Component.node

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25385

### `Static` EventHandler

EventHandler: typeof EventHandler

Inherited from Component.EventHandler

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25320

### `Static` system

system: null

Inherited from Component.system

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25375

## Accessors

### __scriptAsset

- get __scriptAsset(): null

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns null

  Inherited from Component.__scriptAsset

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25337

### _isOnLoadCalled

- get _isOnLoadCalled(): number

- ### En

  Returns a value which used to indicate the onLoad get called or not.

  ### Zh

  返回一个值用来判断 onLoad 是否被调用过，不等于 0 时调用过，等于 0 时未调用。

  ### Read Only

  ### Example

      import { log } from 'cc';
      log(this._isOnLoadCalled > 0);

  ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns number

  Inherited from Component._isOnLoadCalled

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25374

### enabled

- get enabled(): boolean

- ### En

  Indicates whether this component is enabled or not.

  ### Zh

  表示该组件自身是否启用。

  ### Default

  true

  ### Example

      import { log } from 'cc';
      comp.enabled = true;
      log(comp.enabled);

  #### Returns boolean

  Inherited from Component.enabled

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25349
- set enabled(value: boolean): void

- #### Parameters

  - ##### value: boolean

  #### Returns void

  Inherited from Component.enabled

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25350

### enabledInHierarchy

- get enabledInHierarchy(): boolean

- ### En

  Indicates whether this component is enabled and its node is also active in the hierarchy.

  ### Zh

  表示该组件是否被启用并且所在的节点也处于激活状态。

  ### Read Only

  ### Example

      import { log } from 'cc';
      log(comp.enabledInHierarchy);

  #### Returns boolean

  Inherited from Component.enabledInHierarchy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25361

### hideFlags

- get hideFlags(): Flags

- #### Returns Flags

  Inherited from Component.hideFlags

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20900
- set hideFlags(hideFlags: Flags): void

- ### En

  After inheriting CCObject objects, control whether you need to hide, lock, serialize, and other functions.

  ### Zh

  在继承 CCObject 对象后，控制是否需要隐藏，锁定，序列化等功能。

  #### Parameters

  - ##### hideFlags: Flags

  #### Returns void

  Inherited from Component.hideFlags

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20899

### isValid

- get isValid(): boolean

- ### En

  Indicates whether the object is not yet destroyed. (It will not be available after being destroyed)
  When an object's `destroy` is called, it is actually destroyed after the end of this frame. So `isValid` will return false from the next frame, while `isValid` in the current frame will still be true. If you want to determine whether the current frame has called `destroy`, use `isValid(obj, true)`, but this is often caused by a particular logical requirements, which is not normally required.

  ### Zh

  表示该对象是否可用（被 destroy 后将不可用）。
  当一个对象的 `destroy` 调用以后，会在这一帧结束后才真正销毁。
  因此从下一帧开始 `isValid` 就会返回 false，而当前帧内 `isValid` 仍然会是 true。
  如果希望判断当前帧是否调用过 `destroy`，请使用 `isValid(obj, true)`，不过这往往是特殊的业务需求引起的，通常情况下不需要这样。

  ### Default

  true

  ### Read Only

  ### Example

      import { Node, log } from 'cc';
      const node = new Node();
      log(node.isValid);    // true
      node.destroy();
      log(node.isValid);    // true, still valid in this frame
      // after a frame...
      log(node.isValid);    // false, destroyed in the end of last frame

  #### Returns boolean

  Inherited from Component.isValid

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20927

### name

- get name(): string

- #### Returns string

  Inherited from Component.name

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25321
- set name(value: string): void

- #### Parameters

  - ##### value: string

  #### Returns void

  Inherited from Component.name

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25322

### progressMusic

- get progressMusic(): number

- 获取背景音乐播放进度

  #### Returns number

  - Defined in assets/core/common/audio/AudioManager.ts:62
- set progressMusic(value: number): void

- 设置背景乐播放进度

  #### Parameters

  - ##### value: number

    播放进度值

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:69

### switchEffect

- get switchEffect(): boolean

- 获取音效开关值

  #### Returns boolean

  - Defined in assets/core/common/audio/AudioManager.ts:138
- set switchEffect(value: boolean): void

- 设置音效开关值

  #### Parameters

  - ##### value: boolean

    音效开关值

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:145

### switchMusic

- get switchMusic(): boolean

- 获取背景音乐开关值

  #### Returns boolean

  - Defined in assets/core/common/audio/AudioManager.ts:91
- set switchMusic(value: boolean): void

- 设置背景音乐开关值

  #### Parameters

  - ##### value: boolean

    开关值

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:98

### uuid

- get uuid(): string

- ### En

  The uuid for editor.

  ### Zh

  组件的 uuid，用于编辑器。

  ### Read Only

  ### Example

      import { log } from 'cc';
      log(comp.uuid);

  #### Returns string

  Inherited from Component.uuid

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25333

### volumeEffect

- get volumeEffect(): number

- 获取音效音量

  #### Returns number

  - Defined in assets/core/common/audio/AudioManager.ts:123
- set volumeEffect(value: number): void

- 设置获取音效音量

  #### Parameters

  - ##### value: number

    音效音量值

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:130

### volumeMusic

- get volumeMusic(): number

- 获取背景音乐音量

  #### Returns number

  - Defined in assets/core/common/audio/AudioManager.ts:76
- set volumeMusic(value: number): void

- 设置背景音乐音量

  #### Parameters

  - ##### value: number

    音乐音量值

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:83

## Methods

### `Optional` `Private` __preload

- __preload(): void
- `Private`

  ### En

  `__preload` is called before every onLoad.
  It is used to initialize the builtin components internally,
  to avoid checking whether onLoad is called before every public method calls.
  This method should be removed if script priority is supported.

  ### Zh

  `__preload` 在每次onLoad之前调用。
  它用于在内部初始化内置组件，
  以避免在每次公有方法调用之前检查是否调用了onLoad。
  如果支持脚本优先级，则应删除此方法。

  #### Returns void

  Inherited from Component.__preload

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25611

### _destroyImmediate

- _destroyImmediate(): void

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns void

  Inherited from Component._destroyImmediate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20978

### _destruct

- _destruct(): void

- ### En

  Clear all references in the instance.

  NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject.

  ### Zh

  清理实例的所有引用 注意：此方法不会清理实例上的 getter 与 setter 方法。

  ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  ### Example

      // You can override the _destruct method if you need, for example:
            _destruct: function () {
                for (var key in this) {
                    if (this.hasOwnProperty(key)) {
                        switch (typeof this[key]) {
                            case 'string':
                                this[key] = '';
                                break;
                            case 'object':
                            case 'function':
                                this[key] = null;
                                break;
                    }
                }
            }

  #### Returns void

  Inherited from Component._destruct

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20974

### `Optional` `Private` _getLocalBounds

- _getLocalBounds(out_rect: Rect): void
- `Private`

  ### En

  If the component's bounding box is different from the node's, you can implement this method to supply a custom axis aligned bounding box (AABB), so the editor's scene view can perform hit test properly.

  ### Zh

  如果组件的包围盒与节点不同，您可以实现该方法以提供自定义的轴向对齐的包围盒（AABB）， 以便编辑器的场景视图可以正确地执行点选测试。

  #### Parameters

  - ##### out_rect: Rect

    The rect to store the result bounding rect

  #### Returns void

  Inherited from Component._getLocalBounds

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25676

### _getRenderScene

- _getRenderScene(): RenderScene

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns RenderScene

  Inherited from Component._getRenderScene

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25406

### _instantiate

- _instantiate(cloned?: Component): undefined | Component

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Parameters

  - ##### `Optional` cloned: Component

  #### Returns undefined | Component

  Inherited from Component._instantiate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25530

### _onPreDestroy

- _onPreDestroy(): void

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns void

  Inherited from Component._onPreDestroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25526

### addComponent

- addComponent<T>(classConstructor: __types_globals__Constructor<T>): null | T

- ### En

  Adds a component class to the node. You can also add component to node by passing in the name of the script.

  ### Zh

  向节点添加一个指定类型的组件类，你还可以通过传入脚本的名称来添加组件。

  ### Example

      import { Sprite } from 'cc';
      const sprite = node.addComponent(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of component to be retrieved or to be created

  #### Returns null | T

  Inherited from Component.addComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25417
- addComponent(className: string): null | Component

- ### En

  Adds a component class to the node. You can also add component to node by passing in the name of the script.

  ### Zh

  向节点添加一个指定类型的组件类，你还可以通过传入脚本的名称来添加组件。

  ### Example

      const test = node.addComponent("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the component

  #### Returns null | Component

  Inherited from Component.addComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25427

### destroy

- destroy(): boolean

- #### Returns boolean

  Inherited from Component.destroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25522

### getComponent

- getComponent<T>(classConstructor: __types_globals__Constructor<T>): null | T

- ### En

  Returns the component of supplied type if the node has one attached, null if it doesn't.
  You can also get component in the node by passing in the name of the script.

  ### Zh

  获取节点上指定类型的组件，如果节点有附加指定类型的组件，则返回，如果没有则为空。
  传入参数也可以是脚本的名称。

  ### Example

      import { Sprite } from 'cc';
      // get sprite component.
      var sprite = node.getComponent(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of component to be retrieved or to be created

  #### Returns null | T

  Inherited from Component.getComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25443
- getComponent(className: string): null | Component

- ### En

  Returns the component of supplied type if the node has one attached, null if it doesn't.
  You can also get component in the node by passing in the name of the script.

  ### Zh

  获取节点上指定类型的组件，如果节点有附加指定类型的组件，则返回，如果没有则为空。
  传入参数也可以是脚本的名称。

  ### Example

      // get custom test calss.
      var test = node.getComponent("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the component

  #### Returns null | Component

  Inherited from Component.getComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25458

### getComponentInChildren

- getComponentInChildren<T>(classConstructor: __types_globals__Constructor<T>): null | T

- ### En

  Returns the component of supplied type in any of its children using depth first search.

  ### Zh

  递归查找所有子节点中第一个匹配指定类型的组件。

  ### Example

      import { Sprite } from 'cc';
      const sprite = node.getComponentInChildren(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of component to be retrieved

  #### Returns null | T

  Inherited from Component.getComponentInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25490
- getComponentInChildren(className: string): null | Component

- ### En

  Returns the component of supplied type in any of its children using depth first search.

  ### Zh

  递归查找所有子节点中第一个匹配指定类型的组件。

  ### Example

      var Test = node.getComponentInChildren("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the component

  #### Returns null | Component

  Inherited from Component.getComponentInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25500

### getComponents

- getComponents<T>(classConstructor: __types_globals__Constructor<T>): T[]

- ### En

  Returns all components of supplied type in the node.

  ### Zh

  返回节点上指定类型的所有组件。

  ### Example

      import { Sprite } from 'cc';
      const sprites = node.getComponents(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of components to be retrieved

  #### Returns T[]

  Inherited from Component.getComponents

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25469
- getComponents(className: string): Component[]

- ### En

  Returns all components of supplied type in the node.

  ### Zh

  返回节点上指定类型的所有组件。

  ### Example

      const tests = node.getComponents("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the components

  #### Returns Component[]

  Inherited from Component.getComponents

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25479

### getComponentsInChildren

- getComponentsInChildren<T>(classConstructor: __types_globals__Constructor<T>): T[]

- ### En

  Returns all components of supplied type in self or any of its children.

  ### Zh

  递归查找自身或所有子节点中指定类型的组件。

  ### Example

      import { Sprite } from 'cc';
      const sprites = node.getComponentsInChildren(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of components to be retrieved

  #### Returns T[]

  Inherited from Component.getComponentsInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25511
- getComponentsInChildren(className: string): Component[]

- ### En

  Returns all components of supplied type in self or any of its children.

  ### Zh

  递归查找自身或所有子节点中指定类型的组件。

  ### Example

      const tests = node.getComponentsInChildren("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the components

  #### Returns Component[]

  Inherited from Component.getComponentsInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25521

### `Protected` `Optional` lateUpdate

- lateUpdate(dt: number): void

- ### En

  LateUpdate is called every frame, if the Component is enabled.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  如果该组件启用，则每帧调用 LateUpdate。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Parameters

  - ##### dt: number

    the delta time in seconds it took to complete the last frame

  #### Returns void

  Inherited from Component.lateUpdate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25599

### load

- load(): void

- 本地加载音乐音效的音量、开关配置数据并设置到游戏中

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:186

### `Protected` `Optional` onDestroy

- onDestroy(): void

- ### En

  Called when this component will be destroyed.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  当该组件被销毁时调用
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Returns void

  Inherited from Component.onDestroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25657

### `Protected` `Optional` onDisable

- onDisable(): void

- ### En

  Called when this component becomes disabled or its node becomes inactive.
  This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  当该组件被禁用或节点变为无效时调用。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Returns void

  Inherited from Component.onDisable

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25649

### `Protected` `Optional` onEnable

- onEnable(): void

- ### En

  Called when this component becomes enabled and its node is active.
  This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  当该组件被启用，并且它的节点也激活时。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Returns void

  Inherited from Component.onEnable

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25641

### `Optional` onFocusInEditor

- onFocusInEditor(): void

- #### Returns void

  Inherited from Component.onFocusInEditor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25658

### `Protected` `Optional` onLoad

- onLoad(): void

- ### En

  When attaching to an active node or its node first activated.
  onLoad is always called before any start functions, this allows you to order initialization of scripts.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行，这能用于安排脚本的初始化顺序。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Returns void

  Inherited from Component.onLoad

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25622

### `Optional` onLostFocusInEditor

- onLostFocusInEditor(): void

- #### Returns void

  Inherited from Component.onLostFocusInEditor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25659

### `Protected` `Optional` onRestore

- onRestore(): void

- ### En

  onRestore is called after the user clicks the Reset item in the Inspector's context menu or performs an undo operation on this component.
  If the component contains the "internal state", short for "temporary member variables which not included
  in its CCClass properties", then you may need to implement this function.
  The editor will call the getset accessors of your component to record/restore the component's state
  for undo/redo operation. However, in extreme cases, it may not works well. Then you should implement
  this function to manually synchronize your component's "internal states" with its public properties.
  Once you implement this function, all the getset accessors of your component will not be called when
  the user performs an undo/redo operation. Which means that only the properties with default value
  will be recorded or restored by editor.
  Similarly, the editor may failed to reset your component correctly in extreme cases. Then if you need
  to support the reset menu, you should manually synchronize your component's "internal states" with its
  properties in this function. Once you implement this function, all the getset accessors of your component
  will not be called during reset operation. Which means that only the properties with default value
  will be reset by editor.

  This function is only called in editor mode.

  ### Zh

  onRestore 是用户在检查器菜单点击 Reset 时，对此组件执行撤消操作后调用的。
  如果组件包含了“内部状态”（不在 CCClass 属性中定义的临时成员变量），那么你可能需要实现该方法。
  编辑器执行撤销/重做操作时，将调用组件的 get set 来录制和还原组件的状态。 然而，在极端的情况下，它可能无法良好运作。
  那么你就应该实现这个方法，手动根据组件的属性同步“内部状态”。 一旦你实现这个方法，当用户撤销或重做时，组件的所有 get set 都不会再被调用。 这意味着仅仅指定了默认值的属性将被编辑器记录和还原。
  同样的，编辑可能无法在极端情况下正确地重置您的组件。
  于是如果你需要支持组件重置菜单，你需要在该方法中手工同步组件属性到“内部状态”。
  一旦你实现这个方法，组件的所有 get set 都不会在重置操作时被调用。 这意味着仅仅指定了默认值的属性将被编辑器重置。
  此方法仅在编辑器下会被调用。

  #### Returns void

  Inherited from Component.onRestore

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25717

### pauseAll

- pauseAll(): void

- 暂停当前音乐与音效的播放

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:159

### playEffect

- playEffect(url: string | AudioClip): void

- 播放音效

  #### Parameters

  - ##### url: string | AudioClip

    资源地址

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:109

### playMusic

- playMusic(url: string, callback?: Function): void

- 播放背景音乐

  #### Parameters

  - ##### url: string

    资源地址

  - ##### `Optional` callback: Function

    音乐播放完成事件

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:37

### playMusicLoop

- playMusicLoop(url: string): void

- 循环播放背景音乐

  #### Parameters

  - ##### url: string

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:45

### releaseEffect

- releaseEffect(url: string | AudioClip): void

- 释放音效资源

  #### Parameters

  - ##### url: string | AudioClip

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:116

### `Optional` resetInEditor

- resetInEditor(didResetToDefault?: boolean): void

- ### En

  Called to initialize the component or node’s properties when adding the component the first time or when the Reset command is used. This function is only called in editor.

  ### Zh

  用来初始化组件或节点的一些属性，当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。

  #### Parameters

  - ##### `Optional` didResetToDefault: boolean

  #### Returns void

  Inherited from Component.resetInEditor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25665

### resumeAll

- resumeAll(): void

- 恢复当前暂停的音乐与音效播放

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:151

### save

- save(): void

- 保存音乐音效的音量、开关配置数据到本地

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:175

### schedule

- schedule(callback: any, interval?: number, repeat?: number, delay?: number): void

- ### En

  Use Scheduler system to schedule a custom task.
  If the task is already scheduled, then the interval parameter will be updated without scheduling it again.

  ### Zh

  使用定时器系统调度一个自定义的回调任务。
  如果回调任务已调度，那么将不会重复调度它，只会更新时间间隔参数。

  ### Example

      import { log } from 'cc';
      this.schedule((dt) => void log(`time: ${dt}`), 1);

  #### Parameters

  - ##### callback: any

    The callback function of the task

  - ##### `Optional` interval: number

    The time interval between each invocation

  - ##### `Optional` repeat: number

    The repeat count of this task, the task will be invoked (repeat + 1) times, use macro.REPEAT_FOREVER to repeat a task forever

  - ##### `Optional` delay: number

    The delay time for the first invocation, Unit: s

  #### Returns void

  Inherited from Component.schedule

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25548

### scheduleOnce

- scheduleOnce(callback: any, delay?: number): void

- ### En

  Use Scheduler system to schedule a task that runs only once, with a delay of 0 or larger.

  ### Zh

  使用定时器系统调度一个只运行一次的回调任务，可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。

  ### Method

  scheduleOnce

  ### See

  schedule

  ### Example

      import { log } from 'cc';
      this.scheduleOnce((dt) => void log(`time: ${dt}`), 2);

  #### Parameters

  - ##### callback: any

    The callback function of the task

  - ##### `Optional` delay: number

    The delay time for the first invocation, Unit: s

  #### Returns void

  Inherited from Component.scheduleOnce

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25562

### setMusicComplete

- setMusicComplete(callback?: null | Function): void

- 设置背景音乐播放完成回调

  #### Parameters

  - ##### callback: null | Function = null

    背景音乐播放完成回调

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:28

### `Private` setState

- setState(): void

- #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:207

### `Private` setStateDefault

- setStateDefault(): void

- #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:214

### `Protected` `Optional` start

- start(): void

- ### En

  Called before all scripts' update if the Component is enabled the first time.
  Usually used to initialize some logic which need to be called after all components' `onload` methods called.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  如果该组件第一次启用，则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Returns void

  Inherited from Component.start

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25633

### stopAll

- stopAll(): void

- 停止当前音乐与音效的播放

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:167

### stopMusic

- stopMusic(): void

- 停止背景音乐播放

  #### Returns void

  - Defined in assets/core/common/audio/AudioManager.ts:53

### unschedule

- unschedule(callback_fn: any): void

- ### En

  Un-schedules a custom task.

  ### Zh

  取消调度一个自定义的回调任务。

  ### Example

      this.unschedule(_callback);

  #### Parameters

  - ##### callback_fn: any

    The callback function of the task

  #### Returns void

  Inherited from Component.unschedule

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25572

### unscheduleAllCallbacks

- unscheduleAllCallbacks(): void

- ### En

  unschedule all scheduled tasks.

  ### Zh

  取消调度所有已调度的回调函数。

  ### Example

      this.unscheduleAllCallbacks();

  #### Returns void

  Inherited from Component.unscheduleAllCallbacks

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25581

### `Protected` `Optional` update

- update(dt: number): void

- ### En

  Update is called every frame, if the Component is enabled.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  如果该组件启用，则每帧调用 update。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Parameters

  - ##### dt: number

    the delta time in seconds it took to complete the last frame

  #### Returns void

  Inherited from Component.update

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25590

### `Static` _deferredDestroy

- _deferredDestroy(): void

- #### Returns void

  Inherited from Component._deferredDestroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20873

Generated using TypeDoc