mirror of
https://gitee.com/dgflash/oops-framework.git
synced 2026-05-31 18:59:19 +08:00
补全资源管理模块注释
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-07-14 10:57:43
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-07-14 16:09:20
|
||||
* @LastEditTime: 2022-07-18 14:24:55
|
||||
*/
|
||||
import { Node, Slider, _decorator } from 'cc';
|
||||
import { oops } from '../../../extensions/oops-framework/assets/core/Oops';
|
||||
@@ -23,7 +23,7 @@ export class Main extends Root {
|
||||
sliderMusicHandle: Node = null!;
|
||||
|
||||
start() {
|
||||
oops.audio.musicVolume = this.sliderMusicVolume.progress;
|
||||
oops.audio.volumeMusic = this.sliderMusicVolume.progress;
|
||||
|
||||
this.sliderMusicHandle.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
|
||||
this.sliderMusicHandle.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
|
||||
@@ -50,13 +50,12 @@ export class Main extends Root {
|
||||
oops.audio.setMusicComplete(() => {
|
||||
oops.gui.toast("音乐播放完成");
|
||||
});
|
||||
|
||||
oops.audio.playMusic("audios/nocturne");
|
||||
}
|
||||
|
||||
/** 调解背景音乐音量 */
|
||||
onSliderMusicVolume(slider: Slider, customEventData: string) {
|
||||
oops.audio.musicVolume = slider.progress;
|
||||
oops.audio.volumeMusic = slider.progress;
|
||||
}
|
||||
|
||||
/** 播放背景音效 */
|
||||
|
||||
@@ -121,7 +121,7 @@ export class Demo extends Component {
|
||||
|
||||
/** 背景音乐 */
|
||||
private btn_audio_open1(event: EventTouch, data: any) {
|
||||
oops.audio.musicVolume = 0.5;
|
||||
oops.audio.volumeMusic = 0.5;
|
||||
|
||||
oops.audio.setMusicComplete(() => {
|
||||
oops.audio.playMusic("audios/nocturne");
|
||||
|
||||
@@ -5,6 +5,7 @@ import { AudioMusic } from "./AudioMusic";
|
||||
|
||||
const LOCAL_STORE_KEY = "game_audio";
|
||||
|
||||
/** 音频管理 */
|
||||
export class AudioManager extends Component {
|
||||
private static _instance: AudioManager;
|
||||
public static get instance(): AudioManager {
|
||||
@@ -35,14 +36,6 @@ export class AudioManager extends Component {
|
||||
private _switch_music: boolean = true;
|
||||
private _switch_effect: boolean = true;
|
||||
|
||||
/** 获取音乐播放进度 */
|
||||
get progressMusic(): number {
|
||||
return this.music.progress;
|
||||
}
|
||||
set progressMusic(value: number) {
|
||||
this.music.progress = value;
|
||||
}
|
||||
|
||||
/** 音乐播放完成回调 */
|
||||
setMusicComplete(callback: Function | null = null) {
|
||||
this.music.onComplete = callback;
|
||||
@@ -59,6 +52,34 @@ export class AudioManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取音乐播放进度 */
|
||||
get progressMusic(): number {
|
||||
return this.music.progress;
|
||||
}
|
||||
set progressMusic(value: number) {
|
||||
this.music.progress = value;
|
||||
}
|
||||
|
||||
/** 背景音乐音量 */
|
||||
get volumeMusic(): number {
|
||||
return this._volume_music;
|
||||
}
|
||||
set volumeMusic(value: number) {
|
||||
this._volume_music = value;
|
||||
this.music.volume = value;
|
||||
}
|
||||
|
||||
/** 音乐开关 */
|
||||
get switchMusic(): boolean {
|
||||
return this._switch_music;
|
||||
}
|
||||
set switchMusic(value: boolean) {
|
||||
this._switch_music = value;
|
||||
|
||||
if (value == false)
|
||||
this.music.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放音效
|
||||
* @param url 资源地址
|
||||
@@ -69,45 +90,26 @@ export class AudioManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/** 背景音乐音量 */
|
||||
public get musicVolume(): number {
|
||||
return this._volume_music;
|
||||
}
|
||||
public set musicVolume(value: number) {
|
||||
this._volume_music = value;
|
||||
this.music.volume = value;
|
||||
}
|
||||
|
||||
/** 音效音量 */
|
||||
public get effectVolume(): number {
|
||||
get volumeEffect(): number {
|
||||
return this._volume_effect;
|
||||
}
|
||||
public set effectVolume(value: number) {
|
||||
set volumeEffect(value: number) {
|
||||
this._volume_effect = value;
|
||||
this.effect.volume = value;
|
||||
}
|
||||
|
||||
/** 音乐开关 */
|
||||
public getSwitchMusic(): boolean {
|
||||
return this._switch_music;
|
||||
}
|
||||
public setSwitchMusic(value: boolean) {
|
||||
this._switch_music = value;
|
||||
|
||||
if (value == false)
|
||||
this.music.stop();
|
||||
}
|
||||
|
||||
/** 音效开关 */
|
||||
getSwitchEffect(): boolean {
|
||||
get switchEffect(): boolean {
|
||||
return this._switch_effect;
|
||||
}
|
||||
setSwitchEffect(value: boolean) {
|
||||
set switchEffect(value: boolean) {
|
||||
this._switch_effect = value;
|
||||
if (value == false)
|
||||
this.effect.stop();
|
||||
}
|
||||
|
||||
/** 恢复当前暂停的音乐与音效播放 */
|
||||
resumeAll() {
|
||||
if (this.music) {
|
||||
this.music.play();
|
||||
@@ -115,6 +117,7 @@ export class AudioManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/** 暂停当前音乐与音效的播放 */
|
||||
pauseAll() {
|
||||
if (this.music) {
|
||||
this.music.pause();
|
||||
@@ -122,6 +125,7 @@ export class AudioManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/** 停止当前音乐与音效的播放 */
|
||||
stopAll() {
|
||||
if (this.music) {
|
||||
this.music.stop();
|
||||
@@ -129,6 +133,7 @@ export class AudioManager extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存音乐音效的音量、开关配置数据到本地 */
|
||||
save() {
|
||||
this.local_data.volume_music = this._volume_music;
|
||||
this.local_data.volume_effect = this._volume_effect;
|
||||
@@ -139,6 +144,8 @@ export class AudioManager extends Component {
|
||||
storage.set(LOCAL_STORE_KEY, data);
|
||||
}
|
||||
|
||||
|
||||
/** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
|
||||
load() {
|
||||
let data = storage.get(LOCAL_STORE_KEY);
|
||||
if (data) {
|
||||
|
||||
@@ -152,6 +152,7 @@ export default class ResLoader {
|
||||
return bundle!.get(path, type);
|
||||
}
|
||||
|
||||
/** 打印缓存中所有资源信息(用于调试) */
|
||||
public dump() {
|
||||
assetManager.assets.forEach((value: Asset, key: string) => {
|
||||
console.log(assetManager.assets.get(key));
|
||||
|
||||
Reference in New Issue
Block a user