Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
This commit is contained in:
@@ -2290,7 +2290,7 @@
|
||||
"__id__": 44
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 64
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { _decorator, Button, EventTouch, Node, Vec3 } from "cc";
|
||||
import AudioManager from "../Manager/AudioManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
let _vec3 = new Vec3();
|
||||
|
||||
@@ -4,4 +4,8 @@
|
||||
Lock,
|
||||
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,20 +1,25 @@
|
||||
import { _decorator, Node, AudioClip, AudioSource, director, assetManager } from "cc";
|
||||
import {
|
||||
_decorator,
|
||||
Node,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
director,
|
||||
assetManager,
|
||||
} from "cc";
|
||||
import PlayerDataManager from "./PlayerDataManager";
|
||||
import ResManager from "./ResManager";
|
||||
import Resource from "../Config/Resource";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
import { Config18x } from "../Config/Config18x";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//音频管理器
|
||||
@ccclass('AudioManager')
|
||||
@ccclass("AudioManager")
|
||||
export default class AudioManager {
|
||||
|
||||
private _audoSource: AudioSource;
|
||||
private curBgId: number = -1; //当前播放中的背景乐id 用于记录
|
||||
private lastBgId: number = -1; //上次播放的背景乐id 用于音乐开关切换时播放
|
||||
private curBgId_confirm: number = -1; //当前播放中的背景乐id 实际播放
|
||||
|
||||
private curBgId: string; //当前播放中的背景乐id 用于记录
|
||||
private lastBgId: string; //上次播放的背景乐id 用于音乐开关切换时播放
|
||||
private curBgId_confirm: string; //当前播放中的背景乐id 实际播放
|
||||
|
||||
private static _I: AudioManager = null;
|
||||
public static get I(): AudioManager {
|
||||
@@ -27,37 +32,35 @@ export default class AudioManager {
|
||||
|
||||
private init() {
|
||||
let audioMgr = new Node();
|
||||
audioMgr.name = '__audioMgr__';
|
||||
audioMgr.name = "__audioMgr__";
|
||||
director.getScene().addChild(audioMgr);
|
||||
director.addPersistRootNode(audioMgr);
|
||||
this._audoSource = audioMgr.addComponent(AudioSource);
|
||||
}
|
||||
|
||||
|
||||
/**播放音效 */
|
||||
PlayEffect(sound, volume:number=1.0) {
|
||||
PlayEffect(sound: string, volume: number = 1.0) {
|
||||
if (!sound) return;
|
||||
if (!PlayerDataManager.I.IsSoundOn) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cfgs = Resource.getConfig("Sound")
|
||||
if (!cfgs[sound]) return;
|
||||
//let cfgs =
|
||||
//if (!cfgs[sound]) return;
|
||||
|
||||
let path = `Sound/${cfgs[sound].AssetName}`
|
||||
logger.log("PlayEffect:", sound, path)
|
||||
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
|
||||
this._audoSource.playOneShot(res, volume)
|
||||
//let path = `Sound/${cfgs[sound].AssetName}`
|
||||
logger.log("PlayEffect:", sound);
|
||||
ResManager.I.getAudio(sound, (res: AudioClip) => {
|
||||
this._audoSource.playOneShot(res, volume);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**播放背景乐 */
|
||||
PlayMusic(sound, loop:boolean = true, volume:number=1.0) {
|
||||
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;
|
||||
//let cfgs = Resource.getConfig("Music")
|
||||
//if (!cfgs[sound]) return;
|
||||
|
||||
this.lastBgId = sound;
|
||||
|
||||
@@ -65,65 +68,66 @@ export default class AudioManager {
|
||||
return; //这个放在记录后面判断,防止开关打开时,没有记录
|
||||
}
|
||||
|
||||
this.StopMusic()
|
||||
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
|
||||
//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) => {
|
||||
logger.log(`下载远程背景乐: url= ${url}`);
|
||||
assetManager.loadRemote<AudioClip>(
|
||||
url,
|
||||
{ ext: ".mp3" },
|
||||
(err, res: AudioClip) => {
|
||||
if (err) {
|
||||
logger.log(err);
|
||||
return
|
||||
return;
|
||||
}
|
||||
logger.log(`播放远程背景乐: res= ${res}`)
|
||||
this.StopMusic()
|
||||
this._audoSource.clip = res
|
||||
this._audoSource.play()
|
||||
this._audoSource.volume = volume
|
||||
this._audoSource.loop = loop
|
||||
})
|
||||
|
||||
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
|
||||
if (this.curBgId != null) {
|
||||
this.lastBgId = this.curBgId;
|
||||
}
|
||||
this._audoSource.stop();
|
||||
this.curBgId = null;
|
||||
this.curBgId_confirm = null;
|
||||
}
|
||||
|
||||
// 重新播放背景乐
|
||||
ReplayMusic(){
|
||||
if (this.curBgId > -1)
|
||||
return
|
||||
if (this.lastBgId < 0)
|
||||
return
|
||||
ReplayMusic(): boolean {
|
||||
if (this.curBgId != null) return false;
|
||||
if (this.lastBgId == null) return false;
|
||||
|
||||
this.PlayMusic(this.lastBgId)
|
||||
this.PlayMusic(this.lastBgId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**暂停播放背景乐 */
|
||||
PauseMusic() {
|
||||
this._audoSource.pause()
|
||||
this._audoSource.pause();
|
||||
}
|
||||
|
||||
|
||||
/**继续播放背景乐 */
|
||||
ResumeMusic() {
|
||||
this._audoSource.play()
|
||||
this._audoSource.play();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
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;
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@ import { CommonConfig } from "../Config/CommonConfig";
|
||||
import AudioManager from "./AudioManager";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
@ccclass('PlayerDataManager')
|
||||
@ccclass("PlayerDataManager")
|
||||
export default class PlayerDataManager {
|
||||
private static _I: PlayerDataManager = null;
|
||||
public static get I(): PlayerDataManager {
|
||||
if (!PlayerDataManager._I) {
|
||||
PlayerDataManager._I = new PlayerDataManager();
|
||||
PlayerDataManager._I.init()
|
||||
PlayerDataManager._I.init();
|
||||
}
|
||||
return PlayerDataManager._I;
|
||||
}
|
||||
@@ -23,71 +23,84 @@ export default class PlayerDataManager {
|
||||
private guideMainFinished: 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
private init() {
|
||||
this.InitPlayerData();
|
||||
}
|
||||
public initEmpty(){
|
||||
|
||||
}
|
||||
|
||||
public initEmpty() {}
|
||||
|
||||
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}`)
|
||||
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}`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public SetMusicOn(bo: boolean) {
|
||||
if (this.isMusicOn == bo)
|
||||
return
|
||||
this.isMusicOn = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_MUSIC, bo)
|
||||
if (bo)
|
||||
AudioManager.I.ReplayMusic()
|
||||
else
|
||||
AudioManager.I.StopMusic()
|
||||
if (this.isMusicOn == bo) return;
|
||||
this.isMusicOn = bo;
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
if (!key || void 0 === data) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -307,28 +307,25 @@ export default class ResManager {
|
||||
}
|
||||
|
||||
/** 加载bundle中的音频文件*/
|
||||
getBundleAudio(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("Audio");
|
||||
if (bundle) {
|
||||
bundle.load(url, AudioClip, (err, res: AudioClip) => {
|
||||
getAudio(url: string, cb) {
|
||||
//let bundle = assetManager.getBundle("Audio");
|
||||
// if (bundle) {
|
||||
// bundle.load(url, AudioClip, (err, res: AudioClip) => {
|
||||
// if (err) {
|
||||
// logger.log(err);
|
||||
// return;
|
||||
// }
|
||||
// cb && cb(res);
|
||||
// });
|
||||
// } else {
|
||||
resources.load(url, AudioClip, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
logger.log(err);
|
||||
return;
|
||||
}
|
||||
cb && cb(res);
|
||||
});
|
||||
} else {
|
||||
assetManager.loadBundle(
|
||||
"Audio",
|
||||
(err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
logger.log(err);
|
||||
return;
|
||||
}
|
||||
this.getBundleAudio(url, cb);
|
||||
}
|
||||
);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
/** 加载bundle中的配置表*/
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
} from "cc";
|
||||
import { GButton } from "../../Main/Common/GButton";
|
||||
import ResManager from "../../Main/Manager/ResManager";
|
||||
import Resource from "../../Main/Config/Resource";
|
||||
import { SDKManager } from "../../Main/Channel/SDKManager";
|
||||
import HttpUnit from "../../Main/Common/HttpUnit";
|
||||
import GlobalValue from "../../Main/Common/GlobalValue";
|
||||
@@ -47,6 +46,8 @@ import { ViewManager } from "../../Main/Manager/ViewManager";
|
||||
import { MainScene } from "../MainScene";
|
||||
import { prodConfig } from "../../chat18x/config/env/prod";
|
||||
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;
|
||||
|
||||
@@ -109,6 +110,8 @@ export class PreloadUI extends Component {
|
||||
// 设备号
|
||||
DeviceIdService.I.init();
|
||||
|
||||
AudioManager.I.PlayMusic(Config18x.AudioConfig.MainBGM);
|
||||
|
||||
SDKManager.init();
|
||||
|
||||
this.preloadFiles();
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Node,
|
||||
Label,
|
||||
Sprite,
|
||||
Button,
|
||||
tween,
|
||||
Vec3,
|
||||
} from "cc";
|
||||
import Utils from "../../../Main/Common/Utils";
|
||||
import li_BaseView from "../../../Main/Common/li_BaseView";
|
||||
import { GButton } from "../../../Main/Common/GButton";
|
||||
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
||||
import { DataManager, DataId } from "../../data/DataManager";
|
||||
import { PlayerData } from "../../data/PlayerData";
|
||||
import { AccountData } from "../../data/AccountData";
|
||||
import { WalletData } from "../../data/WalletData";
|
||||
import LanguageUtils, {
|
||||
LanguageType,
|
||||
} from "../../../Main/Common/LanguageUtils";
|
||||
import AudioManager from "../../../Main/Manager/AudioManager";
|
||||
import {
|
||||
NavigationManager,
|
||||
PageTransitionType,
|
||||
|
||||
@@ -18,6 +18,7 @@ import LanguageUtils, {
|
||||
import AudioManager from "../../../Main/Manager/AudioManager";
|
||||
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
||||
import { NavigationManager } from "../../manager/NavigationManager";
|
||||
import { Config18x } from "../../../Main/Config/Config18x";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
interface LanguageButton {
|
||||
@@ -190,6 +191,7 @@ export class SettingPanel extends li_BaseView {
|
||||
switchMusic() {
|
||||
const currentState = PlayerDataManager.I.IsMusicOn;
|
||||
PlayerDataManager.I.SetMusicOn(!currentState);
|
||||
|
||||
this.updateAudioButtonStates();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user