音频播放bug修复
This commit is contained in:
@@ -2290,7 +2290,7 @@
|
|||||||
"__id__": 44
|
"__id__": 44
|
||||||
},
|
},
|
||||||
"_children": [],
|
"_children": [],
|
||||||
"_active": true,
|
"_active": false,
|
||||||
"_components": [
|
"_components": [
|
||||||
{
|
{
|
||||||
"__id__": 64
|
"__id__": 64
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { _decorator, Button, EventTouch, Node, Vec3 } from "cc";
|
import { _decorator, Button, EventTouch, Node, Vec3 } from "cc";
|
||||||
import AudioManager from "../Manager/AudioManager";
|
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
let _vec3 = new Vec3();
|
let _vec3 = new Vec3();
|
||||||
|
|||||||
@@ -4,4 +4,8 @@
|
|||||||
Lock,
|
Lock,
|
||||||
UnKnown,
|
UnKnown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum AudioConfig {
|
||||||
|
MainBGM = "sound/mainBGM",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
import { _decorator } from "cc";
|
|
||||||
import Utils from "../Common/Utils";
|
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
|
||||||
|
|
||||||
//配置表管理器
|
|
||||||
@ccclass('Resource')
|
|
||||||
export default class Resource {
|
|
||||||
|
|
||||||
static instance: Resource = null;
|
|
||||||
private _config = {};//策划数值表
|
|
||||||
|
|
||||||
static getInstance() {
|
|
||||||
if (!this.instance) this.init();
|
|
||||||
return this.instance;
|
|
||||||
}
|
|
||||||
//初始化
|
|
||||||
static init() {
|
|
||||||
if (!this.instance) {
|
|
||||||
this.instance = new Resource();
|
|
||||||
(window as any).Resource = this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**加载子包时添加 */
|
|
||||||
static addSubJsonConfig(name, tab) {
|
|
||||||
let _instance = this.getInstance();
|
|
||||||
if (!_instance._config) _instance._config = {};
|
|
||||||
if (!_instance._config[name]) _instance._config[name] = {};
|
|
||||||
let json_SS, json_key1, json_key2
|
|
||||||
for (const key in tab) {
|
|
||||||
json_SS = tab[key];
|
|
||||||
if (!json_key1){
|
|
||||||
json_key1 = json_SS.id ? "id" : "ID" //默认用id
|
|
||||||
}
|
|
||||||
json_key2 = json_SS[json_key1]
|
|
||||||
_instance._config[name][json_key2] = json_SS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取表数据
|
|
||||||
* @param table 表名
|
|
||||||
*/
|
|
||||||
static getConfig(table: string) {
|
|
||||||
if (!table) {
|
|
||||||
Utils.Log('策划数值表名为空!', table);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
let _instance = this.getInstance();
|
|
||||||
if (!_instance._config) _instance._config = {};
|
|
||||||
if (!_instance._config[table]) {
|
|
||||||
// _instance._config[table] = {};
|
|
||||||
Utils.Error("配置表未找到:", table)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
let config_D = _instance._config[table];
|
|
||||||
return config_D;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"ver": "4.0.24",
|
|
||||||
"importer": "typescript",
|
|
||||||
"imported": true,
|
|
||||||
"uuid": "34d91d70-8aac-44b4-9b4a-1a60185b2235",
|
|
||||||
"files": [],
|
|
||||||
"subMetas": {},
|
|
||||||
"userData": {}
|
|
||||||
}
|
|
||||||
@@ -1,129 +1,133 @@
|
|||||||
import { _decorator, Node, AudioClip, AudioSource, director, assetManager } from "cc";
|
import {
|
||||||
|
_decorator,
|
||||||
|
Node,
|
||||||
|
AudioClip,
|
||||||
|
AudioSource,
|
||||||
|
director,
|
||||||
|
assetManager,
|
||||||
|
} from "cc";
|
||||||
import PlayerDataManager from "./PlayerDataManager";
|
import PlayerDataManager from "./PlayerDataManager";
|
||||||
import ResManager from "./ResManager";
|
import ResManager from "./ResManager";
|
||||||
import Resource from "../Config/Resource";
|
|
||||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||||
|
import { Config18x } from "../Config/Config18x";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
//音频管理器
|
//音频管理器
|
||||||
@ccclass('AudioManager')
|
@ccclass("AudioManager")
|
||||||
export default class AudioManager {
|
export default class AudioManager {
|
||||||
|
private _audoSource: AudioSource;
|
||||||
|
private curBgId: string; //当前播放中的背景乐id 用于记录
|
||||||
|
private lastBgId: string; //上次播放的背景乐id 用于音乐开关切换时播放
|
||||||
|
private curBgId_confirm: string; //当前播放中的背景乐id 实际播放
|
||||||
|
|
||||||
private _audoSource: AudioSource;
|
private static _I: AudioManager = null;
|
||||||
private curBgId: number = -1; //当前播放中的背景乐id 用于记录
|
public static get I(): AudioManager {
|
||||||
private lastBgId: number = -1; //上次播放的背景乐id 用于音乐开关切换时播放
|
if (!AudioManager._I) {
|
||||||
private curBgId_confirm: number = -1; //当前播放中的背景乐id 实际播放
|
AudioManager._I = new AudioManager();
|
||||||
|
AudioManager._I.init();
|
||||||
|
}
|
||||||
|
return AudioManager._I;
|
||||||
|
}
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
let audioMgr = new Node();
|
||||||
|
audioMgr.name = "__audioMgr__";
|
||||||
|
director.getScene().addChild(audioMgr);
|
||||||
|
director.addPersistRootNode(audioMgr);
|
||||||
|
this._audoSource = audioMgr.addComponent(AudioSource);
|
||||||
|
}
|
||||||
|
|
||||||
private static _I: AudioManager = null;
|
/**播放音效 */
|
||||||
public static get I(): AudioManager {
|
PlayEffect(sound: string, volume: number = 1.0) {
|
||||||
if (!AudioManager._I) {
|
if (!sound) return;
|
||||||
AudioManager._I = new AudioManager();
|
if (!PlayerDataManager.I.IsSoundOn) {
|
||||||
AudioManager._I.init();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//let cfgs =
|
||||||
|
//if (!cfgs[sound]) return;
|
||||||
|
|
||||||
|
//let path = `Sound/${cfgs[sound].AssetName}`
|
||||||
|
logger.log("PlayEffect:", sound);
|
||||||
|
ResManager.I.getAudio(sound, (res: AudioClip) => {
|
||||||
|
this._audoSource.playOneShot(res, volume);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**播放背景乐 */
|
||||||
|
PlayMusic(sound: string, loop: boolean = true, volume: number = 1.0) {
|
||||||
|
if (!sound || sound == this.curBgId_confirm) return;
|
||||||
|
|
||||||
|
//let cfgs = Resource.getConfig("Music")
|
||||||
|
//if (!cfgs[sound]) return;
|
||||||
|
|
||||||
|
this.lastBgId = sound;
|
||||||
|
|
||||||
|
if (!PlayerDataManager.I.IsMusicOn) {
|
||||||
|
return; //这个放在记录后面判断,防止开关打开时,没有记录
|
||||||
|
}
|
||||||
|
|
||||||
|
this.StopMusic();
|
||||||
|
this.curBgId = sound;
|
||||||
|
this.curBgId_confirm = sound;
|
||||||
|
//let path = `Music/${cfgs[sound].AssetName}`
|
||||||
|
logger.log("PlayMusic:", sound);
|
||||||
|
ResManager.I.getAudio(sound, (res: AudioClip) => {
|
||||||
|
this._audoSource.clip = res;
|
||||||
|
this._audoSource.play();
|
||||||
|
this._audoSource.volume = volume;
|
||||||
|
this._audoSource.loop = loop;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**播放远程背景乐 */
|
||||||
|
PlayRemoteMusic(url, loop: boolean = true, volume: number = 1.0) {
|
||||||
|
logger.log(`下载远程背景乐: url= ${url}`);
|
||||||
|
assetManager.loadRemote<AudioClip>(
|
||||||
|
url,
|
||||||
|
{ ext: ".mp3" },
|
||||||
|
(err, res: AudioClip) => {
|
||||||
|
if (err) {
|
||||||
|
logger.log(err);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return AudioManager._I;
|
logger.log(`播放远程背景乐: res= ${res}`);
|
||||||
|
this.StopMusic();
|
||||||
|
this._audoSource.clip = res;
|
||||||
|
this._audoSource.play();
|
||||||
|
this._audoSource.volume = volume;
|
||||||
|
this._audoSource.loop = loop;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**停止播放背景乐 */
|
||||||
|
StopMusic() {
|
||||||
|
if (this.curBgId != null) {
|
||||||
|
this.lastBgId = this.curBgId;
|
||||||
}
|
}
|
||||||
|
this._audoSource.stop();
|
||||||
|
this.curBgId = null;
|
||||||
|
this.curBgId_confirm = null;
|
||||||
|
}
|
||||||
|
|
||||||
private init(){
|
// 重新播放背景乐
|
||||||
let audioMgr = new Node();
|
ReplayMusic(): boolean {
|
||||||
audioMgr.name = '__audioMgr__';
|
if (this.curBgId != null) return false;
|
||||||
director.getScene().addChild(audioMgr);
|
if (this.lastBgId == null) return false;
|
||||||
director.addPersistRootNode(audioMgr);
|
|
||||||
this._audoSource = audioMgr.addComponent(AudioSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.PlayMusic(this.lastBgId);
|
||||||
/**播放音效 */
|
return true;
|
||||||
PlayEffect(sound, volume:number=1.0) {
|
}
|
||||||
if (!sound) return;
|
|
||||||
if (!PlayerDataManager.I.IsSoundOn) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cfgs = Resource.getConfig("Sound")
|
|
||||||
if (!cfgs[sound]) return;
|
|
||||||
|
|
||||||
let path = `Sound/${cfgs[sound].AssetName}`
|
/**暂停播放背景乐 */
|
||||||
logger.log("PlayEffect:", sound, path)
|
PauseMusic() {
|
||||||
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
|
this._audoSource.pause();
|
||||||
this._audoSource.playOneShot(res, volume)
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**继续播放背景乐 */
|
||||||
/**播放背景乐 */
|
ResumeMusic() {
|
||||||
PlayMusic(sound, loop:boolean = true, volume:number=1.0) {
|
this._audoSource.play();
|
||||||
if (!sound || sound == this.curBgId_confirm) return;
|
}
|
||||||
|
}
|
||||||
let cfgs = Resource.getConfig("Music")
|
|
||||||
if (!cfgs[sound]) return;
|
|
||||||
|
|
||||||
this.lastBgId = sound;
|
|
||||||
|
|
||||||
if (!PlayerDataManager.I.IsMusicOn) {
|
|
||||||
return; //这个放在记录后面判断,防止开关打开时,没有记录
|
|
||||||
}
|
|
||||||
|
|
||||||
this.StopMusic()
|
|
||||||
this.curBgId = sound;
|
|
||||||
this.curBgId_confirm = sound;
|
|
||||||
let path = `Music/${cfgs[sound].AssetName}`
|
|
||||||
logger.log("PlayMusic:", sound, path)
|
|
||||||
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
|
|
||||||
this._audoSource.clip = res
|
|
||||||
this._audoSource.play()
|
|
||||||
this._audoSource.volume = volume
|
|
||||||
this._audoSource.loop = loop
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**播放远程背景乐 */
|
|
||||||
PlayRemoteMusic(url, loop:boolean = true, volume:number=1.0) {
|
|
||||||
logger.log(`下载远程背景乐: url= ${url}`)
|
|
||||||
assetManager.loadRemote<AudioClip>(url, { ext: '.mp3'}, (err, res: AudioClip) => {
|
|
||||||
if (err) {
|
|
||||||
logger.log(err);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logger.log(`播放远程背景乐: res= ${res}`)
|
|
||||||
this.StopMusic()
|
|
||||||
this._audoSource.clip = res
|
|
||||||
this._audoSource.play()
|
|
||||||
this._audoSource.volume = volume
|
|
||||||
this._audoSource.loop = loop
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**停止播放背景乐 */
|
|
||||||
StopMusic(){
|
|
||||||
this._audoSource.stop()
|
|
||||||
this.curBgId = -1
|
|
||||||
this.curBgId_confirm = -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新播放背景乐
|
|
||||||
ReplayMusic(){
|
|
||||||
if (this.curBgId > -1)
|
|
||||||
return
|
|
||||||
if (this.lastBgId < 0)
|
|
||||||
return
|
|
||||||
|
|
||||||
this.PlayMusic(this.lastBgId)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**暂停播放背景乐 */
|
|
||||||
PauseMusic(){
|
|
||||||
this._audoSource.pause()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**继续播放背景乐 */
|
|
||||||
ResumeMusic(){
|
|
||||||
this._audoSource.play()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { _decorator, Node, AudioClip, AudioSource, director, PhysicsSystem2D, EPhysics2DDrawFlags, Vec2, PHYSICS_2D_PTM_RATIO, v2 } from "cc";
|
import { _decorator, Node, AudioClip, AudioSource, director, PhysicsSystem2D, EPhysics2DDrawFlags, Vec2, PHYSICS_2D_PTM_RATIO, v2 } from "cc";
|
||||||
import PlayerDataManager from "./PlayerDataManager";
|
|
||||||
import ResManager from "./ResManager";
|
|
||||||
import Resource from "../Config/Resource";
|
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
|||||||
@@ -4,127 +4,140 @@ import { CommonConfig } from "../Config/CommonConfig";
|
|||||||
import AudioManager from "./AudioManager";
|
import AudioManager from "./AudioManager";
|
||||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass } = _decorator;
|
||||||
|
|
||||||
@ccclass('PlayerDataManager')
|
@ccclass("PlayerDataManager")
|
||||||
export default class PlayerDataManager {
|
export default class PlayerDataManager {
|
||||||
private static _I: PlayerDataManager = null;
|
private static _I: PlayerDataManager = null;
|
||||||
public static get I(): PlayerDataManager {
|
public static get I(): PlayerDataManager {
|
||||||
if (!PlayerDataManager._I) {
|
if (!PlayerDataManager._I) {
|
||||||
PlayerDataManager._I = new PlayerDataManager();
|
PlayerDataManager._I = new PlayerDataManager();
|
||||||
PlayerDataManager._I.init()
|
PlayerDataManager._I.init();
|
||||||
}
|
|
||||||
return PlayerDataManager._I;
|
|
||||||
}
|
}
|
||||||
|
return PlayerDataManager._I;
|
||||||
|
}
|
||||||
|
|
||||||
private isShakeOn: boolean = true; //震动
|
private isShakeOn: boolean = true; //震动
|
||||||
private isMusicOn: boolean = true; //音乐
|
private isMusicOn: boolean = true; //音乐
|
||||||
private isSoundOn: boolean = true; //音效
|
private isSoundOn: boolean = true; //音效
|
||||||
private guideMainFinished: boolean = false; //主界面引导是否完成
|
private guideMainFinished: boolean = false; //主界面引导是否完成
|
||||||
private guideTalkFinished: boolean = false; //聊天界面引导是否完成
|
private guideTalkFinished: boolean = false; //聊天界面引导是否完成
|
||||||
|
|
||||||
|
public get IsShakeOn(): boolean {
|
||||||
|
return this.isShakeOn;
|
||||||
|
}
|
||||||
|
public get IsMusicOn(): boolean {
|
||||||
|
return this.isMusicOn;
|
||||||
|
}
|
||||||
|
public get IsSoundOn(): boolean {
|
||||||
|
return this.isSoundOn;
|
||||||
|
}
|
||||||
|
public get GuideMainFinished(): boolean {
|
||||||
|
return this.guideMainFinished;
|
||||||
|
}
|
||||||
|
public get GuideTalkFinished(): boolean {
|
||||||
|
return this.guideTalkFinished;
|
||||||
|
}
|
||||||
|
|
||||||
public get IsShakeOn() : boolean {return this.isShakeOn;}
|
private init() {
|
||||||
public get IsMusicOn() : boolean {return this.isMusicOn;}
|
this.InitPlayerData();
|
||||||
public get IsSoundOn() : boolean {return this.isSoundOn;}
|
}
|
||||||
public get GuideMainFinished() : boolean {return this.guideMainFinished;}
|
public initEmpty() {}
|
||||||
public get GuideTalkFinished() : boolean {return this.guideTalkFinished;}
|
|
||||||
|
|
||||||
|
private InitPlayerData() {
|
||||||
|
// this.isShakeOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SHAKEON, true)
|
||||||
|
this.isMusicOn = PlayerDataManager.getForKey(
|
||||||
|
CommonConfig.StorageConfig.SETTING_MUSIC,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
this.isSoundOn = PlayerDataManager.getForKey(
|
||||||
|
CommonConfig.StorageConfig.SETTING_SOUND,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
this.guideMainFinished = PlayerDataManager.getForKey(
|
||||||
|
CommonConfig.StorageConfig.GUIDE_MAIN,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
this.guideTalkFinished = PlayerDataManager.getForKey(
|
||||||
|
CommonConfig.StorageConfig.GUIDE_TALK,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
logger.log(
|
||||||
|
"InitPlayerData",
|
||||||
|
`music=${this.isMusicOn}, sound=${this.isSoundOn}, guideMain=${this.guideMainFinished}, guideTalk=${this.guideTalkFinished}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private init(){
|
public SetMusicOn(bo: boolean) {
|
||||||
this.InitPlayerData();
|
if (this.isMusicOn == bo) return;
|
||||||
}
|
this.isMusicOn = bo;
|
||||||
public initEmpty(){
|
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_MUSIC, bo);
|
||||||
|
if (bo) {
|
||||||
|
AudioManager.I.ReplayMusic();
|
||||||
|
} else AudioManager.I.StopMusic();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetSoundOn(bo: boolean) {
|
||||||
|
if (this.isSoundOn == bo) return;
|
||||||
|
this.isSoundOn = bo;
|
||||||
|
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_SOUND, bo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**主界面引导完成*/
|
||||||
|
public SetGuideMainFinish(bo: boolean) {
|
||||||
|
if (this.guideMainFinished == bo) return;
|
||||||
|
this.guideMainFinished = bo;
|
||||||
|
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_MAIN, bo);
|
||||||
|
}
|
||||||
|
/**聊天界面引导完成*/
|
||||||
|
public SetGuideTalkFinish(bo: boolean) {
|
||||||
|
if (this.guideTalkFinished == bo) return;
|
||||||
|
this.guideTalkFinished = bo;
|
||||||
|
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_TALK, bo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型内部处理,外层部分类型 isBindingId //标识位数据需要绑定 playerid的时候,默认值为 true,若是传 false,则不进入绑定
|
||||||
|
* */
|
||||||
|
static setForKey(key: number | string, data) {
|
||||||
|
if (!key || void 0 === data) {
|
||||||
|
Utils.Log("key can`t nil");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
key = key + "";
|
||||||
|
sys.localStorage.setItem(key, JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
static getForKey(key: number | string, defaultVal): any {
|
||||||
private InitPlayerData() {
|
if (!key) {
|
||||||
// this.isShakeOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SHAKEON, true)
|
Utils.Log("key can`t nil");
|
||||||
this.isMusicOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_MUSIC, true)
|
return;
|
||||||
this.isSoundOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SOUND, true)
|
|
||||||
this.guideMainFinished = PlayerDataManager.getForKey(CommonConfig.StorageConfig.GUIDE_MAIN, false)
|
|
||||||
this.guideTalkFinished = PlayerDataManager.getForKey(CommonConfig.StorageConfig.GUIDE_TALK, false)
|
|
||||||
logger.log("InitPlayerData", `music=${this.isMusicOn}, sound=${this.isSoundOn}, guideMain=${this.guideMainFinished}, guideTalk=${this.guideTalkFinished}`)
|
|
||||||
}
|
}
|
||||||
|
key = key + "";
|
||||||
|
let jsonObj;
|
||||||
public SetMusicOn(bo: boolean) {
|
try {
|
||||||
if (this.isMusicOn == bo)
|
let str = sys.localStorage.getItem(key);
|
||||||
return
|
try {
|
||||||
this.isMusicOn = bo
|
jsonObj = JSON.parse(str);
|
||||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_MUSIC, bo)
|
} catch (error) {
|
||||||
if (bo)
|
jsonObj = str;
|
||||||
AudioManager.I.ReplayMusic()
|
}
|
||||||
else
|
} catch (error) {
|
||||||
AudioManager.I.StopMusic()
|
Utils.Log(`getForKey--->>>解析${key}的值的时候报错`);
|
||||||
}
|
}
|
||||||
|
if (jsonObj == null) {
|
||||||
|
jsonObj = defaultVal;
|
||||||
|
}
|
||||||
|
return jsonObj;
|
||||||
|
}
|
||||||
|
|
||||||
public SetSoundOn(bo: boolean) {
|
static removeForKey(key: number | string): void {
|
||||||
if (this.isSoundOn == bo)
|
key = key + "";
|
||||||
return
|
sys.localStorage.setItem(key, "");
|
||||||
this.isSoundOn = bo
|
}
|
||||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_SOUND, bo)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**主界面引导完成*/
|
/**清档 */
|
||||||
public SetGuideMainFinish(bo: boolean) {
|
static clearAll(): void {
|
||||||
if (this.guideMainFinished == bo)
|
sys.localStorage.clear();
|
||||||
return
|
}
|
||||||
this.guideMainFinished = bo
|
}
|
||||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_MAIN, bo)
|
|
||||||
}
|
|
||||||
/**聊天界面引导完成*/
|
|
||||||
public SetGuideTalkFinish(bo: boolean) {
|
|
||||||
if (this.guideTalkFinished == bo)
|
|
||||||
return
|
|
||||||
this.guideTalkFinished = bo
|
|
||||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_TALK, bo)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 类型内部处理,外层部分类型 isBindingId //标识位数据需要绑定 playerid的时候,默认值为 true,若是传 false,则不进入绑定
|
|
||||||
* */
|
|
||||||
static setForKey(key: number | string, data) {
|
|
||||||
if (!key || void (0) === data) {
|
|
||||||
Utils.Log("key can`t nil");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
key = key + "";
|
|
||||||
sys.localStorage.setItem(key, JSON.stringify(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
static getForKey(key: number | string, defaultVal): any {
|
|
||||||
if (!key) {
|
|
||||||
Utils.Log("key can`t nil");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
key = key + "";
|
|
||||||
let jsonObj;
|
|
||||||
try {
|
|
||||||
let str = sys.localStorage.getItem(key);
|
|
||||||
try {
|
|
||||||
jsonObj = JSON.parse(str);
|
|
||||||
} catch (error) {
|
|
||||||
jsonObj = str;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Utils.Log(`getForKey--->>>解析${key}的值的时候报错`);
|
|
||||||
}
|
|
||||||
if (jsonObj == null){
|
|
||||||
jsonObj = defaultVal;
|
|
||||||
}
|
|
||||||
return jsonObj;
|
|
||||||
}
|
|
||||||
|
|
||||||
static removeForKey(key: number | string): void {
|
|
||||||
key = key + "";
|
|
||||||
sys.localStorage.setItem(key, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**清档 */
|
|
||||||
static clearAll(): void {
|
|
||||||
sys.localStorage.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -307,28 +307,25 @@ export default class ResManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 加载bundle中的音频文件*/
|
/** 加载bundle中的音频文件*/
|
||||||
getBundleAudio(url: string, cb) {
|
getAudio(url: string, cb) {
|
||||||
let bundle = assetManager.getBundle("Audio");
|
//let bundle = assetManager.getBundle("Audio");
|
||||||
if (bundle) {
|
// if (bundle) {
|
||||||
bundle.load(url, AudioClip, (err, res: AudioClip) => {
|
// bundle.load(url, AudioClip, (err, res: AudioClip) => {
|
||||||
if (err) {
|
// if (err) {
|
||||||
logger.log(err);
|
// logger.log(err);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
cb && cb(res);
|
// cb && cb(res);
|
||||||
});
|
// });
|
||||||
} else {
|
// } else {
|
||||||
assetManager.loadBundle(
|
resources.load(url, AudioClip, (err, res: AudioClip) => {
|
||||||
"Audio",
|
if (err) {
|
||||||
(err: Error, _bundle: AssetManager.Bundle) => {
|
logger.log(err);
|
||||||
if (err) {
|
return;
|
||||||
logger.log(err);
|
}
|
||||||
return;
|
cb && cb(res);
|
||||||
}
|
});
|
||||||
this.getBundleAudio(url, cb);
|
//}
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 加载bundle中的配置表*/
|
/** 加载bundle中的配置表*/
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
} from "cc";
|
} from "cc";
|
||||||
import { GButton } from "../../Main/Common/GButton";
|
import { GButton } from "../../Main/Common/GButton";
|
||||||
import ResManager from "../../Main/Manager/ResManager";
|
import ResManager from "../../Main/Manager/ResManager";
|
||||||
import Resource from "../../Main/Config/Resource";
|
|
||||||
import { SDKManager } from "../../Main/Channel/SDKManager";
|
import { SDKManager } from "../../Main/Channel/SDKManager";
|
||||||
import HttpUnit from "../../Main/Common/HttpUnit";
|
import HttpUnit from "../../Main/Common/HttpUnit";
|
||||||
import GlobalValue from "../../Main/Common/GlobalValue";
|
import GlobalValue from "../../Main/Common/GlobalValue";
|
||||||
@@ -47,6 +46,8 @@ import { ViewManager } from "../../Main/Manager/ViewManager";
|
|||||||
import { MainScene } from "../MainScene";
|
import { MainScene } from "../MainScene";
|
||||||
import { prodConfig } from "../../chat18x/config/env/prod";
|
import { prodConfig } from "../../chat18x/config/env/prod";
|
||||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||||
|
import AudioManager from "../../Main/Manager/AudioManager";
|
||||||
|
import { Config18x } from "../../Main/Config/Config18x";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -109,6 +110,8 @@ export class PreloadUI extends Component {
|
|||||||
// 设备号
|
// 设备号
|
||||||
DeviceIdService.I.init();
|
DeviceIdService.I.init();
|
||||||
|
|
||||||
|
AudioManager.I.PlayMusic(Config18x.AudioConfig.MainBGM);
|
||||||
|
|
||||||
SDKManager.init();
|
SDKManager.init();
|
||||||
|
|
||||||
this.preloadFiles();
|
this.preloadFiles();
|
||||||
|
|||||||
@@ -1,25 +1,17 @@
|
|||||||
import {
|
import {
|
||||||
_decorator,
|
_decorator,
|
||||||
Component,
|
|
||||||
Node,
|
|
||||||
Label,
|
Label,
|
||||||
Sprite,
|
Sprite,
|
||||||
Button,
|
|
||||||
tween,
|
|
||||||
Vec3,
|
|
||||||
} from "cc";
|
} from "cc";
|
||||||
import Utils from "../../../Main/Common/Utils";
|
import Utils from "../../../Main/Common/Utils";
|
||||||
import li_BaseView from "../../../Main/Common/li_BaseView";
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
||||||
import { GButton } from "../../../Main/Common/GButton";
|
import { GButton } from "../../../Main/Common/GButton";
|
||||||
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
|
||||||
import { DataManager, DataId } from "../../data/DataManager";
|
import { DataManager, DataId } from "../../data/DataManager";
|
||||||
import { PlayerData } from "../../data/PlayerData";
|
import { PlayerData } from "../../data/PlayerData";
|
||||||
import { AccountData } from "../../data/AccountData";
|
import { AccountData } from "../../data/AccountData";
|
||||||
import { WalletData } from "../../data/WalletData";
|
import { WalletData } from "../../data/WalletData";
|
||||||
import LanguageUtils, {
|
import LanguageUtils, {
|
||||||
LanguageType,
|
|
||||||
} from "../../../Main/Common/LanguageUtils";
|
} from "../../../Main/Common/LanguageUtils";
|
||||||
import AudioManager from "../../../Main/Manager/AudioManager";
|
|
||||||
import {
|
import {
|
||||||
NavigationManager,
|
NavigationManager,
|
||||||
PageTransitionType,
|
PageTransitionType,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import LanguageUtils, {
|
|||||||
import AudioManager from "../../../Main/Manager/AudioManager";
|
import AudioManager from "../../../Main/Manager/AudioManager";
|
||||||
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
||||||
import { NavigationManager } from "../../manager/NavigationManager";
|
import { NavigationManager } from "../../manager/NavigationManager";
|
||||||
|
import { Config18x } from "../../../Main/Config/Config18x";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
interface LanguageButton {
|
interface LanguageButton {
|
||||||
@@ -190,6 +191,7 @@ export class SettingPanel extends li_BaseView {
|
|||||||
switchMusic() {
|
switchMusic() {
|
||||||
const currentState = PlayerDataManager.I.IsMusicOn;
|
const currentState = PlayerDataManager.I.IsMusicOn;
|
||||||
PlayerDataManager.I.SetMusicOn(!currentState);
|
PlayerDataManager.I.SetMusicOn(!currentState);
|
||||||
|
|
||||||
this.updateAudioButtonStates();
|
this.updateAudioButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user