From 81d6e0922c3d7cd5d4db5d63c05e01d784e7fd50 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Tue, 2 Jul 2019 23:42:39 +0800 Subject: [PATCH] minor (#4795) --- cocos/3d/assets/audio/clip.ts | 31 +++++++++++-------- cocos/3d/assets/audio/player-wx.ts | 1 + cocos/3d/assets/material.ts | 2 +- cocos/3d/framework/audio-source-component.ts | 13 +++----- .../batched-skinning-model-component.ts | 4 +-- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/cocos/3d/assets/audio/clip.ts b/cocos/3d/assets/audio/clip.ts index a3b2000ee1..0ee77c5558 100644 --- a/cocos/3d/assets/audio/clip.ts +++ b/cocos/3d/assets/audio/clip.ts @@ -42,6 +42,12 @@ export const AudioType = Enum({ UNKNOWN_AUDIO: 3, }); +/** + * @zh + * 音频片段资源,每个片段知道自己应该如何播放、寻址等。 + * 每当音频片段实际开始播放时,会发出 'started' 事件; + * 每当音频片段自然结束播放时,会发出 'ended' 事件。 + */ @ccclass('cc.AudioClip') export class AudioClip extends Asset { @@ -49,22 +55,26 @@ export class AudioClip extends Asset { public static AudioType = AudioType; public static preventDeferredLoadDependents = true; - @property // we serialize this because it's unavailable at runtime on some platforms - protected _duration = 0; - @property({ - type: AudioType, - }) + @property + protected _duration = 0; // we serialize this because it's unavailable at runtime on some platforms + + @property({ type: AudioType }) protected _loadMode = AudioType.UNKNOWN_AUDIO; protected _audio: any = null; - private _player: AudioPlayer | null = null; + protected _player: AudioPlayer | null = null; constructor () { super(); this.loaded = false; } - public set _nativeAsset (clip: any) { + public destroy () { + if (this._player) { this._player.destroy(); } + return super.destroy(); + } + + set _nativeAsset (clip: any) { this._audio = clip; if (clip) { let ctor: any; @@ -89,15 +99,10 @@ export class AudioClip extends Asset { } } - public get _nativeAsset () { + get _nativeAsset () { return this._audio; } - public destroy () { - if (this._player) { this._player.destroy(); } - return super.destroy(); - } - get loadMode () { return this._loadMode; } diff --git a/cocos/3d/assets/audio/player-wx.ts b/cocos/3d/assets/audio/player-wx.ts index 723a0b0259..303c85d508 100644 --- a/cocos/3d/assets/audio/player-wx.ts +++ b/cocos/3d/assets/audio/player-wx.ts @@ -82,6 +82,7 @@ export class AudioPlayerWX extends AudioPlayer { /* InnerAudioContext doesn't support multiple playback at the same time so here we fall back to re-start style approach */ if (!this._audio) { return; } + this._audio.seek(0); this._audio.volume = volume; if (this._oneShoting) { return; } this._audio.loop = false; diff --git a/cocos/3d/assets/material.ts b/cocos/3d/assets/material.ts index 552a5c1557..b680a32990 100644 --- a/cocos/3d/assets/material.ts +++ b/cocos/3d/assets/material.ts @@ -312,7 +312,7 @@ export class Material extends Asset { } } } else { - if (passIdx >= this._props.length) { console.warn(`illegal pass index: ${passIdx}.`); return; } + if (passIdx >= this._props.length) { console.warn(`illegal pass index: ${passIdx}.`); return null; } const props = this._props[passIdx]; for (const p of Object.keys(props)) { if (p === name) { return props[p]; } diff --git a/cocos/3d/framework/audio-source-component.ts b/cocos/3d/framework/audio-source-component.ts index 6cc62b412e..cee4076aeb 100644 --- a/cocos/3d/framework/audio-source-component.ts +++ b/cocos/3d/framework/audio-source-component.ts @@ -92,7 +92,7 @@ export class AudioSourceComponent extends Component { * @zh * 是否启用自动播放。
* 请注意,根据最新的自动播放策略,现在大部分时候,自动播放只会在第一次收到用户输入后生效。
- * @see https://www.chromium.org/audio-video/autoplay + * 参考:https://www.chromium.org/audio-video/autoplay */ @property set playOnAwake (val) { @@ -173,8 +173,8 @@ export class AudioSourceComponent extends Component { * 注意,对同一个音频片段,不同平台多重播放效果存在差异。
* 在 Web Audio 模式下,可以同时维护多个播放进度,达到多重播放。
* 其他模式下都不支持多重播放,如前一次尚未播完,则会立即重新播放。 - * @param clip - the clip being played - * @param volumeScale - the scale of the volume (0-1). + * @param clip 要播放的音频 + * @param volumeScale 相对当前音量的缩放,默认为 1 */ public playOneShot (clip: AudioClip, volumeScale = 1) { clip.playOneShot(this._volume * volumeScale); @@ -193,7 +193,7 @@ export class AudioSourceComponent extends Component { * set current playback time, in seconds * @zh * 以秒为单位设置当前播放时间。 - * @param num the playback time you want to jump to + * @param num 要跳转到的播放时间 */ set currentTime (num: number) { this._cachedCurrentTime = num; @@ -206,7 +206,6 @@ export class AudioSourceComponent extends Component { * get the current playback time, in seconds * @zh * 以秒为单位获取当前播放时间。 - * @returns time current playback time */ get currentTime () { if (!this._clip) { return this._cachedCurrentTime; } @@ -217,8 +216,7 @@ export class AudioSourceComponent extends Component { * @en * get the audio duration, in seconds * @zh - * 以秒为单位获取音频持续时间。 - * @returns audio duration + * 获取以秒为单位的音频总时长。 */ get duration () { if (!this._clip) { return 0; } @@ -230,7 +228,6 @@ export class AudioSourceComponent extends Component { * get current audio state * @zh * 获取当前音频状态。 - * @returns current audio state */ get state () { if (!this._clip) { return AudioClip.PlayingState.INITIALIZING; } diff --git a/cocos/3d/framework/batched-skinning-model-component.ts b/cocos/3d/framework/batched-skinning-model-component.ts index b6a9a90947..dd317c76b0 100644 --- a/cocos/3d/framework/batched-skinning-model-component.ts +++ b/cocos/3d/framework/batched-skinning-model-component.ts @@ -177,11 +177,11 @@ export class BatchedSkinningModelComponent extends SkinningModelComponent { public cookMaterials () { const mat = this.getMaterial(0); - if (!mat || !this._batchMaterial || !mat.effectAsset) { + if (!mat || !this._batchMaterial || !this._batchMaterial.effectAsset) { console.warn('incomplete batch material!'); return; } mat.copy(this._batchMaterial); this.resizeAtlases(); - const tech = mat.effectAsset.techniques[mat.technique]; + const tech = mat.effectAsset!.techniques[mat.technique]; for (let i = 0; i < tech.passes.length; i++) { const pass = tech.passes[i]; if (!pass.properties) { continue; }