init
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
import { _decorator, Node, AudioClip, AudioSource, director, assetManager } from "cc";
|
||||
import PlayerDataManager from "./PlayerDataManager";
|
||||
import ResManager from "./ResManager";
|
||||
import Resource from "../Config/Resource";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//音频管理器
|
||||
@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 static _I: AudioManager = null;
|
||||
public static get I(): AudioManager {
|
||||
if (!AudioManager._I) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**播放音效 */
|
||||
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}`
|
||||
console.log("PlayEffect:", sound, path)
|
||||
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
|
||||
this._audoSource.playOneShot(res, volume)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**播放背景乐 */
|
||||
PlayMusic(sound, 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}`
|
||||
console.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) {
|
||||
console.log(`下载远程背景乐: url= ${url}`)
|
||||
assetManager.loadRemote<AudioClip>(url, { ext: '.mp3'}, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
console.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()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "06da91f8-e0f7-4750-a5c3-4ecfb135e827",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,572 @@
|
||||
import { _decorator, Node, v2 } from "cc";
|
||||
import { I_LevelConfig, I_LevelStepData, I_NpcTalkBack, I_TalkRecordInfo, I_ZhengCangConfig } from "../Config/CommonConfig";
|
||||
import SocketUnit from "../Common/SocketUnit";
|
||||
import Utils from "../Common/Utils";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import HttpUnit from "../Common/HttpUnit";
|
||||
import { SDKManager } from "../Channel/SDKManager";
|
||||
import { VideoRoleType } from "../Common/GlobalValue";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
/**聊天状态 */
|
||||
export enum E_TalkStatusType {
|
||||
succ = 0, //成功
|
||||
talking = 1, //对话中
|
||||
fail = 2, //失败
|
||||
noCount = 3, //次数不足
|
||||
}
|
||||
|
||||
|
||||
/**对话阶段 */
|
||||
export enum E_TalkStage {
|
||||
/**开场白 */
|
||||
prologue,
|
||||
/**我的对话 */
|
||||
myTalk,
|
||||
/**等待NPC回复 */
|
||||
waitNpcTalk,
|
||||
/**NPC对话 */
|
||||
npcTalk,
|
||||
/**NPC固定话术 */
|
||||
npcFixedTalk,
|
||||
/**更新对话状态 */
|
||||
upTalkStatus,
|
||||
}
|
||||
|
||||
|
||||
//游戏管理器
|
||||
@ccclass('GameManager')
|
||||
export default class GameManager {
|
||||
|
||||
private static _I: GameManager = null;
|
||||
public static get I(): GameManager {
|
||||
if (!GameManager._I) {
|
||||
GameManager._I = new GameManager();
|
||||
GameManager._I.init();
|
||||
}
|
||||
return GameManager._I;
|
||||
}
|
||||
|
||||
private init(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region长连接相关
|
||||
private _socket: SocketUnit = null;
|
||||
/**连接长连接 */
|
||||
public connetSorcket(record_id:string){
|
||||
this.disconnectSocket();
|
||||
this._socket = new SocketUnit();
|
||||
// this._socket.connect(`ws://47.119.190.199:20190/game/ai/response/${record_id}`);
|
||||
let socketUrl = `${HttpUnit.SocketHost}${record_id}`
|
||||
this._socket.connect(socketUrl);
|
||||
this._socket.onDataReceived((data: any) => {
|
||||
let resData = JSON.parse(data.data)
|
||||
if (GameManager.curStage != E_TalkStage.waitNpcTalk) return
|
||||
if (resData.isFinished) {
|
||||
console.log("npc回复:", resData)
|
||||
GameManager.CurNpcTalkData = resData
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_NpcTalkBack, resData || {})
|
||||
}
|
||||
})
|
||||
}
|
||||
/**断开长连接 */
|
||||
public disconnectSocket(){
|
||||
if (this._socket){
|
||||
this._socket.disconnect();
|
||||
}
|
||||
this._socket = null;
|
||||
}
|
||||
/**获取npc回复 */
|
||||
public getNpcTalkBack(data: any){
|
||||
if (this._socket){
|
||||
let str = JSON.stringify(data)
|
||||
this._socket.sendData(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region关卡配置
|
||||
private static _levelCfgArray: I_LevelConfig[] = [];
|
||||
private static _levelCfgMap: {[key: string]: I_LevelConfig} = {};
|
||||
private static _zhencangMap: {[key: string]: I_ZhengCangConfig} = {};
|
||||
/**设置关卡配置数据 */
|
||||
public static SetLevelCfg(levelCfg: any[]) {
|
||||
GameManager._levelCfgArray = levelCfg;
|
||||
let info:any = null;
|
||||
let umRecords = [] //友盟解锁关卡记录
|
||||
let recordLvs = HttpUnit.GetLevelRecord(); //友盟已记录的关卡
|
||||
for (let i = 0; i < levelCfg.length; i++) {
|
||||
info = levelCfg[i];
|
||||
GameManager._levelCfgMap[info.id] = info;
|
||||
//判断是否已记录
|
||||
if (info.is_unlock) {
|
||||
if (recordLvs.indexOf(info.id) == -1){
|
||||
umRecords.push(info.id)
|
||||
}
|
||||
}
|
||||
//私家珍藏配置
|
||||
if (info.photoAwards) {
|
||||
for (let j = 0; j < info.photoAwards.length; j++) {
|
||||
let photoAwards = info.photoAwards[j];
|
||||
photoAwards.levelId = info.id;
|
||||
GameManager._zhencangMap[photoAwards.id+""] = photoAwards;
|
||||
}
|
||||
}
|
||||
}
|
||||
//友盟记录关卡
|
||||
if (umRecords.length > 0 && SDKManager.umaSwt()){
|
||||
let umr = umRecords.join(',')
|
||||
HttpUnit.ins.sendLevelRecord({level_ids:umr}, (_data)=>{
|
||||
console.log('友盟记录关卡',_data)
|
||||
let userId = HttpUnit.GetID()
|
||||
let curDate = Utils.GetNowFormatDay()
|
||||
for (let i = 0; i < umRecords.length; i++) {
|
||||
let lvId = umRecords[i]
|
||||
let _cfg = GameManager._levelCfgMap[lvId]
|
||||
SDKManager.umaEvent(SDKManager.Uma_Event_LvUnlock, {
|
||||
lvId: lvId,
|
||||
userId: userId,
|
||||
time: curDate,
|
||||
type: _cfg.unlock_type
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/**设置关卡星级 */
|
||||
public static SetLevelStar(levelId: string, star: number) {
|
||||
let cfg = GameManager._levelCfgMap[levelId];
|
||||
if (cfg) {
|
||||
cfg.star = star;
|
||||
}
|
||||
}
|
||||
|
||||
/**获取关卡配置 */
|
||||
public static getLevelCfg(levelId: string): I_LevelConfig {
|
||||
return GameManager._levelCfgMap[levelId];
|
||||
}
|
||||
/**获取关卡配置列表 */
|
||||
public static getLevelCfgList(): I_LevelConfig[] {
|
||||
return GameManager._levelCfgArray;
|
||||
}
|
||||
|
||||
/**获取npc表情图片 */
|
||||
public static GetNpcEmoPic(emoStr: string): any {
|
||||
let rolePath = ""
|
||||
let emoName = ""
|
||||
let videoType = VideoRoleType.None
|
||||
let lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId);
|
||||
if (emoStr == "" || emoStr == null) {
|
||||
rolePath = `role/${lvCfg.characterFullLengthPortrait}` //循环,图片没有待机,用default,视频用待机
|
||||
emoName = lvCfg.characterStandbyPortrait
|
||||
videoType = VideoRoleType.Idle
|
||||
|
||||
}else if (emoStr.includes("害羞")) {
|
||||
rolePath = `emo_1/${lvCfg.characterShyPortrait}`
|
||||
emoName = lvCfg.characterShyPortrait
|
||||
videoType = VideoRoleType.emo
|
||||
} else if (emoStr.includes("开心")) {
|
||||
rolePath = `emo_2/${lvCfg.characterHappyPortrait}`
|
||||
emoName = lvCfg.characterHappyPortrait
|
||||
videoType = VideoRoleType.emo
|
||||
} else if (emoStr.includes("厌恶")) {
|
||||
rolePath = `emo_3/${lvCfg.characterHatePortrait}`
|
||||
emoName = lvCfg.characterHatePortrait
|
||||
videoType = VideoRoleType.emo
|
||||
} else {
|
||||
rolePath = `role/${lvCfg.characterFullLengthPortrait}` //默认表情
|
||||
emoName = lvCfg.characterFullLengthPortrait
|
||||
videoType = VideoRoleType.emo
|
||||
}
|
||||
return {rolePath:rolePath, emoName:emoName, videoType:videoType};
|
||||
}
|
||||
|
||||
|
||||
//regionAI语音开关
|
||||
private static _AIVoiceSwt: boolean = false;
|
||||
/**设置是否显示AI语音 */
|
||||
public static set AIVoiceSwt(value: boolean) {
|
||||
GameManager._AIVoiceSwt = value;
|
||||
}
|
||||
/**获取是否显示AI语音 */
|
||||
public static get AIVoiceSwt(): boolean {
|
||||
return GameManager._AIVoiceSwt;
|
||||
}
|
||||
|
||||
|
||||
//region当前关卡ID
|
||||
private static _curLevelId: string = "";
|
||||
/**设置当前关卡ID */
|
||||
public static set CurLevelId(value: string) {
|
||||
GameManager._curLevelId = value;
|
||||
}
|
||||
/**获取当前关卡ID */
|
||||
public static get CurLevelId(): string {
|
||||
return GameManager._curLevelId;
|
||||
}
|
||||
|
||||
|
||||
//region流程id
|
||||
private static _recordId: string = "";
|
||||
/**设置当前关卡流程ID */
|
||||
public static set RecordId(value: string) {
|
||||
GameManager._recordId = value;
|
||||
}
|
||||
/**获取当前关卡流程ID */
|
||||
public static get RecordId(): string {
|
||||
return GameManager._recordId;
|
||||
}
|
||||
|
||||
|
||||
//region当前步骤数据
|
||||
private static _curLevelData: I_LevelStepData = null;
|
||||
/**设置当前步骤数据 */
|
||||
public static set CurLevelData(value: I_LevelStepData) {
|
||||
GameManager._curLevelData = value;
|
||||
}
|
||||
/**获取当前步骤数据 */
|
||||
public static get CurLevelData(): I_LevelStepData {
|
||||
return GameManager._curLevelData;
|
||||
}
|
||||
|
||||
|
||||
//region NPC回复数据
|
||||
private static _curNpcTalkData: I_NpcTalkBack = null;
|
||||
private static _npcTalkDataAry: I_NpcTalkBack[] = [];
|
||||
/**设置当前NPC回复数据 */
|
||||
public static set CurNpcTalkData(value: I_NpcTalkBack) {
|
||||
GameManager._curNpcTalkData = value;
|
||||
GameManager._npcTalkDataAry.push(value);
|
||||
}
|
||||
/**获取当前NPC回复数据 */
|
||||
public static get CurNpcTalkData(): I_NpcTalkBack {
|
||||
return GameManager._curNpcTalkData;
|
||||
}
|
||||
/**移除最后一条NPC回复数据 */
|
||||
public static removeLastNpcTalkData() {
|
||||
if (GameManager._npcTalkDataAry.length > 0) {
|
||||
let talkData = GameManager._npcTalkDataAry.pop();
|
||||
//心动次数也要减
|
||||
if (talkData.judgement == 0) {
|
||||
if (GameManager.xindongCishu > 0) {
|
||||
GameManager.xindongCishu = GameManager.xindongCishu - 1
|
||||
}
|
||||
}
|
||||
if (talkData.aiScore >= 90) {
|
||||
if (GameManager.jidongCishu > 0) {
|
||||
GameManager.jidongCishu = GameManager.jidongCishu - 1
|
||||
}
|
||||
}
|
||||
if (talkData.aiScore >= 100) {
|
||||
if (GameManager.gandongCishu > 0) {
|
||||
GameManager.gandongCishu = GameManager.gandongCishu - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GameManager._npcTalkDataAry.length == 0) {
|
||||
GameManager._curNpcTalkData = null;
|
||||
} else {
|
||||
GameManager._curNpcTalkData = GameManager._npcTalkDataAry[GameManager._npcTalkDataAry.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region 当前NPC话术文本
|
||||
private static _curNpcFixedTalkText: string = "";
|
||||
/**设置当前NPC话术文本 */
|
||||
public static set CurNpcFixedTalkText(value: string) {
|
||||
GameManager._curNpcFixedTalkText = value;
|
||||
}
|
||||
/**获取当前NPC话术文本 */
|
||||
public static get CurNpcFixedTalkText(): string {
|
||||
return GameManager._curNpcFixedTalkText;
|
||||
}
|
||||
|
||||
|
||||
//region关卡步骤评分
|
||||
private static stepScoreList: number[] = [];
|
||||
/**设置关卡步骤评分 */
|
||||
public static AddStepScore(score: number) {
|
||||
GameManager.stepScoreList.push(score);
|
||||
}
|
||||
/**移除最后一步骤评分 */
|
||||
public static RemoveLastSetpScore() {
|
||||
let cellLen = GameManager.stepScoreList.length;
|
||||
if (cellLen > 0) {
|
||||
GameManager.stepScoreList.pop();
|
||||
}
|
||||
}
|
||||
/**清空关卡步骤评分 */
|
||||
public static ClearStepScore() {
|
||||
GameManager.stepScoreList = [];
|
||||
}
|
||||
/**获取最新得分 */
|
||||
public static getCurStepScore(): number {
|
||||
if (GameManager.stepScoreList.length == 0) return 0;
|
||||
return GameManager.stepScoreList[GameManager.stepScoreList.length - 1];
|
||||
}
|
||||
/**获取关卡当前评分
|
||||
* @returns [总分,平均分]
|
||||
*/
|
||||
public static getGameScore(): [number,number] {
|
||||
let totalScore = 0;
|
||||
let totalStep = 0;
|
||||
GameManager.stepScoreList.forEach((score) => {
|
||||
totalScore += score;
|
||||
totalStep++;
|
||||
})
|
||||
let scoreRate = totalStep > 0 ? Math.floor(totalScore / totalStep) : 0;
|
||||
return [totalScore, scoreRate];
|
||||
}
|
||||
|
||||
|
||||
//region对话记录
|
||||
private static talkRecordList: I_TalkRecordInfo[] = [];
|
||||
/**添加对话记录 */
|
||||
public static AddTalkRecord(record: I_TalkRecordInfo) {
|
||||
GameManager.talkRecordList.push(record);
|
||||
}
|
||||
/**移除最后一条对话记录 */
|
||||
public static RemoveLastRoundTalkRecord() {
|
||||
let cellLen = GameManager.talkRecordList.length;
|
||||
if (cellLen > 1) {
|
||||
for (let i=cellLen-1; i>=0; i--) {
|
||||
let talkCell = GameManager.talkRecordList.pop();
|
||||
if (talkCell.isMe) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**清空对话记录 */
|
||||
public static ClearTalkRecord() {
|
||||
GameManager.talkRecordList = [];
|
||||
}
|
||||
/**获取对话记录 */
|
||||
public static get TalkRecordList(): I_TalkRecordInfo[] {
|
||||
return GameManager.talkRecordList;
|
||||
}
|
||||
|
||||
|
||||
//region 当前对话阶段
|
||||
private static _curStage: E_TalkStage = E_TalkStage.prologue;
|
||||
/**获取当前对话阶段 */
|
||||
public static get curStage(): E_TalkStage {
|
||||
return GameManager._curStage;
|
||||
}
|
||||
/**设置当前对话阶段 */
|
||||
public static TurnToStage(value: E_TalkStage, force: boolean = false) {
|
||||
if (GameManager._curStage == value && !force) return;
|
||||
GameManager._curStage = value;
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_TalkStageUp, {})
|
||||
}
|
||||
|
||||
|
||||
//region 已用对话轮次
|
||||
private static _srouceCnt: number = 0;
|
||||
/**获取已用对话轮次 */
|
||||
public static get srouceCnt(): number {
|
||||
return GameManager._srouceCnt;
|
||||
}
|
||||
/**设置已用对话轮次 */
|
||||
public static set srouceCnt(value: number) {
|
||||
GameManager._srouceCnt = value;
|
||||
}
|
||||
|
||||
//region 心动次数 70分
|
||||
private static _xindongCishu: number = 0;
|
||||
/**获取心动次数 */
|
||||
public static get xindongCishu(): number {
|
||||
return GameManager._xindongCishu;
|
||||
}
|
||||
/**设置心动次数 */
|
||||
public static set xindongCishu(value: number) {
|
||||
GameManager._xindongCishu = value;
|
||||
}
|
||||
|
||||
//region 激动次数 90分
|
||||
private static _jidongCishu: number = 0;
|
||||
/**获取心动次数 */
|
||||
public static get jidongCishu(): number {
|
||||
return GameManager._jidongCishu;
|
||||
}
|
||||
/**设置心动次数 */
|
||||
public static set jidongCishu(value: number) {
|
||||
GameManager._jidongCishu = value;
|
||||
}
|
||||
|
||||
//region 感动次数 100分
|
||||
private static _gandongCishu: number = 0;
|
||||
/**获取心动次数 */
|
||||
public static get gandongCishu(): number {
|
||||
return GameManager._gandongCishu;
|
||||
}
|
||||
/**设置心动次数 */
|
||||
public static set gandongCishu(value: number) {
|
||||
GameManager._gandongCishu = value;
|
||||
}
|
||||
|
||||
//region npc固定话术喜欢次数
|
||||
private static _npcFixTalkCountXihuan: number = 0;
|
||||
/**获取npc固定话术喜欢次数 */
|
||||
public static get npcFixTalkCountXihuan(): number {
|
||||
return GameManager._npcFixTalkCountXihuan;
|
||||
}
|
||||
/**设置npc固定话术喜欢次数 */
|
||||
public static set npcFixTalkCountXihuan(value: number) {
|
||||
GameManager._npcFixTalkCountXihuan = value;
|
||||
}
|
||||
|
||||
//region npc固定话术讨厌次数
|
||||
private static _npcFixTalkCountTaoyan: number = 0;
|
||||
/**获取npc固定话术讨厌次数 */
|
||||
public static get npcFixTalkCountTaoyan(): number {
|
||||
return GameManager._npcFixTalkCountTaoyan;
|
||||
}
|
||||
/**设置npc固定话术讨厌次数 */
|
||||
public static set npcFixTalkCountTaoyan(value: number) {
|
||||
GameManager._npcFixTalkCountTaoyan = value;
|
||||
}
|
||||
|
||||
|
||||
//region 结束关卡
|
||||
/**结束关卡 */
|
||||
public static EndGame() {
|
||||
GameManager.I.disconnectSocket();
|
||||
GameManager.ClearStepScore()
|
||||
GameManager.ClearTalkRecord()
|
||||
GameManager.CurLevelId = ""
|
||||
GameManager.RecordId = ""
|
||||
GameManager.CurLevelData = null
|
||||
GameManager.CurNpcTalkData = null
|
||||
GameManager._npcTalkDataAry = []
|
||||
GameManager.srouceCnt = 0
|
||||
GameManager.xindongCishu = 0
|
||||
GameManager.jidongCishu = 0
|
||||
GameManager.gandongCishu = 0
|
||||
GameManager.npcFixTalkCountXihuan = 0
|
||||
GameManager.npcFixTalkCountTaoyan = 0
|
||||
GameManager._curStage = E_TalkStage.prologue
|
||||
}
|
||||
|
||||
|
||||
//region 重新开始关卡
|
||||
/**重新开始关卡 */
|
||||
public static RestartGame() {
|
||||
if (GameManager.CurLevelId == "") {
|
||||
return
|
||||
}
|
||||
GameManager._restartGameStep1()
|
||||
}
|
||||
//重开步骤1 刷新用户数据
|
||||
private static _restartGameStep1() {
|
||||
HttpUnit.ins.getUserData((userData) => {
|
||||
GameManager._restartGameStep2()
|
||||
})
|
||||
}
|
||||
//重开步骤2 刷新关卡数据
|
||||
private static _restartGameStep2() {
|
||||
HttpUnit.ins.getLevelList((levelList) => {
|
||||
if (levelList) {
|
||||
GameManager.SetLevelCfg(levelList)
|
||||
GameManager._restartGameStep3()
|
||||
}
|
||||
})
|
||||
}
|
||||
//重开步骤3 判断条件
|
||||
private static _restartGameStep3() {
|
||||
if (HttpUnit.GetXiangqinTickets() <= 0) {
|
||||
SubManager.ShowPrompt("今日相亲次数已用完");
|
||||
return;
|
||||
}
|
||||
let level_id = GameManager.CurLevelId
|
||||
HttpUnit.ins.levelStart({level_id:level_id}, (data) => {
|
||||
GameManager.EndGame()
|
||||
GameManager.CurLevelId = level_id
|
||||
GameManager.CurLevelData = data.level
|
||||
GameManager.RecordId = data.record_id
|
||||
GameManager.I.connetSorcket(data.record_id) //连接socket
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_ResartGame, {})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region 可领取的私家珍藏列表
|
||||
private static _zhencangCanget: any[] = []
|
||||
/**可领取的私家珍藏列表 */
|
||||
static get zhencangCanget() {
|
||||
return this._zhencangCanget
|
||||
}
|
||||
/**刷新可领取的私家珍藏列表 */
|
||||
static refreshZhencangCanget() {
|
||||
HttpUnit.ins.getZhencangList({limit:10, page:1, type:0}, (data) => {
|
||||
if (data) {
|
||||
this._zhencangCanget = data.data || []
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_ZhencangUp, {})
|
||||
}
|
||||
})
|
||||
}
|
||||
/**解锁一个私家珍藏id */
|
||||
static UnlockZhencang(record_id:string, levelId: string) {
|
||||
console.log("解锁私家珍藏:", record_id, levelId)
|
||||
HttpUnit.ins.getZhencangList({limit:999, page:1, type:1}, (data) => {
|
||||
if (data){
|
||||
this._doUnlockZhencang(data.data, record_id, levelId)
|
||||
}
|
||||
})
|
||||
}
|
||||
//解锁私家珍藏 zclist:已解锁列表 record_id:本次聊天id levelId:关卡id
|
||||
private static _doUnlockZhencang(zclist:any, record_id:string, levelId: string) {
|
||||
zclist = zclist || []
|
||||
|
||||
let cangetList = GameManager.zhencangCanget
|
||||
let lvCfg = this.getLevelCfg(levelId)
|
||||
let lockAry:any[] = [] //未解锁的私家珍藏列表
|
||||
for (let i=0; i<lvCfg.photoAwards.length; i++) {
|
||||
let item = lvCfg.photoAwards[i]
|
||||
let ishave = false //是否已解锁
|
||||
//先看可领取列表里有没有
|
||||
if (!ishave) {
|
||||
for (let j=0; j<cangetList.length; j++) {
|
||||
let zc = cangetList[j]
|
||||
if (zc.img == item.id) {
|
||||
ishave = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
//再看已解锁列表里有没有
|
||||
if (!ishave) {
|
||||
for (let j=0; j<zclist.length; j++) {
|
||||
let zc = zclist[j]
|
||||
if (zc.img == item.id) {
|
||||
ishave = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ishave) {
|
||||
lockAry.push(item)
|
||||
}
|
||||
}
|
||||
if (lockAry.length > 0) {
|
||||
let randIdx = Utils.getRandomInt(0, lockAry.length-1)
|
||||
let item = lockAry[randIdx]
|
||||
HttpUnit.ins.sendZhencangId({record_id:record_id, level_id:levelId, img:item.id}, (_data) => {
|
||||
if (_data) {
|
||||
console.log("获得珍藏卡:", item)
|
||||
GameManager.refreshZhencangCanget()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/**获取珍藏配置信息 */
|
||||
public static getZhencangCfg(zcId: string) {
|
||||
return GameManager._zhencangMap[zcId+""];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d43c28d8-5808-43a8-8b84-1f0bbf7f5fa4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
|
||||
//物理系统管理器
|
||||
//通过编辑器主菜单中的 项目 -> 项目设置 -> 功能裁剪 切换物理模块的使用。轻量 Builtin 物理系统和强大的 Box2D 物理系统
|
||||
@ccclass('PhysicsManager')
|
||||
export default class PhysicsManager {
|
||||
|
||||
private static _I: PhysicsManager = null;
|
||||
public static get I(): PhysicsManager {
|
||||
if (!PhysicsManager._I) {
|
||||
PhysicsManager._I = new PhysicsManager();
|
||||
PhysicsManager._I.init();
|
||||
}
|
||||
return PhysicsManager._I;
|
||||
}
|
||||
|
||||
private init(){
|
||||
// const system = PhysicsSystem2D.instance;
|
||||
// system.fixedTimeStep = 1/30;// 物理步长,默认 fixedTimeStep 是 1/60
|
||||
// system.velocityIterations = 8;// 每次更新物理系统处理速度的迭代次数,默认为 10
|
||||
// system.positionIterations = 8;// 每次更新物理系统处理位置的迭代次数,默认为 10
|
||||
|
||||
// this.setPhysicsEnable(false)
|
||||
}
|
||||
|
||||
|
||||
//设置是否开启物理系统
|
||||
public setPhysicsEnable(swt: boolean) {
|
||||
PhysicsSystem2D.instance.enable = swt; //是否启用物理系统
|
||||
}
|
||||
|
||||
//设置物理调试信息是否显示
|
||||
public setDrawFalgEnable(swt: boolean) {
|
||||
if (swt) {
|
||||
this.setPhysicsEnable(true);
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape | EPhysics2DDrawFlags.Joint
|
||||
} else {
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
//设置重力方向
|
||||
public setPhysicsGravity(dir: Vec2) {
|
||||
PhysicsSystem2D.instance.gravity = v2(dir.x * PHYSICS_2D_PTM_RATIO, dir.y * PHYSICS_2D_PTM_RATIO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "76c070bf-f7c6-41ca-9d75-83f35bb97ab8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { _decorator, sys } from "cc";
|
||||
import Utils from "../Common/Utils";
|
||||
import { CommonConfig } from "../Config/CommonConfig";
|
||||
import AudioManager from "./AudioManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@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()
|
||||
}
|
||||
return PlayerDataManager._I;
|
||||
}
|
||||
|
||||
private isShakeOn: boolean = true; //震动
|
||||
private isMusicOn: boolean = true; //音乐
|
||||
private isSoundOn: boolean = true; //音效
|
||||
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;}
|
||||
|
||||
|
||||
private init(){
|
||||
this.InitPlayerData();
|
||||
}
|
||||
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)
|
||||
console.log("InitPlayerData", `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()
|
||||
}
|
||||
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "54a36d09-f9e0-4044-b065-7237b4a5aa85",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
import { _decorator, AssetManager, assetManager, Component, Node, director, Prefab, resources, Sprite, SpriteFrame, Texture2D, v2, SpriteAtlas, ImageAsset, instantiate, AudioClip, Asset, JsonAsset, Material } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ResManager')
|
||||
export default class ResManager {
|
||||
private static _I: ResManager = null;
|
||||
public static get I(): ResManager {
|
||||
if (!ResManager._I) {
|
||||
ResManager._I = new ResManager();
|
||||
}
|
||||
return ResManager._I;
|
||||
}
|
||||
|
||||
|
||||
/**切换场景 */
|
||||
enterScene(i_sceneName: string) {
|
||||
director.loadScene(i_sceneName, () => { });
|
||||
}
|
||||
|
||||
|
||||
/** 场景-跳转到主界面场景*/
|
||||
goMainScene() {
|
||||
this.enterScene('MainScene');
|
||||
}
|
||||
|
||||
/** 场景-跳转到游戏场景*/
|
||||
goGameScene() {
|
||||
this.enterScene('GameScene');
|
||||
}
|
||||
|
||||
/** 场景-跳转到自定义场景*/
|
||||
goCustomScene(sceneName:string) {
|
||||
this.enterScene(sceneName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// /**加载bundle */
|
||||
// loadBundle(bundleName, cb?) {
|
||||
// let bundle = assetManager.getBundle(bundleName)
|
||||
// if (bundle) { cb && cb(bundle); return; }
|
||||
// assetManager.loadBundle(bundleName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
// if (!err) {
|
||||
// cb && cb(_bundle);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
/**移除bundle */
|
||||
removeBundle(bundleName) {
|
||||
let bundle = assetManager.getBundle(bundleName);
|
||||
if (bundle) {
|
||||
bundle.releaseAll();
|
||||
assetManager.removeBundle(bundle);
|
||||
}
|
||||
}
|
||||
/**预加载bundle中的PB*/
|
||||
preLoadSubpackagePrefab(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("PB");
|
||||
if (bundle){
|
||||
bundle.preload(url, Prefab, (err, res) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb();
|
||||
});
|
||||
} else {
|
||||
assetManager.loadBundle("PB", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.preLoadSubpackagePrefab(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**预加载bundle中的文件*/
|
||||
preLoadSubpackageFile(url: string, pkgName: string, ftype, succCB, failCB) {
|
||||
let bundle = assetManager.getBundle(pkgName);
|
||||
if (bundle){
|
||||
bundle.preload(url, ftype, (err, res) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
failCB && failCB(err);
|
||||
return
|
||||
}
|
||||
succCB && succCB();
|
||||
});
|
||||
} else {
|
||||
assetManager.loadBundle(pkgName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
failCB && failCB(err);
|
||||
return
|
||||
}
|
||||
this.preLoadSubpackageFile(url, pkgName, ftype, succCB, failCB);
|
||||
});
|
||||
}
|
||||
}
|
||||
/** 加载bundle中的PB*/
|
||||
loadSubpackagePrefab(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("PB");
|
||||
if (bundle){
|
||||
bundle.load(url, Prefab, (err, res: Prefab) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
let cc_N = instantiate(res);
|
||||
cb && cb(cc_N);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("PB", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.loadSubpackagePrefab(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**获取pb节点 */
|
||||
getPrefab(path: string, cb: Function, target: Node) {
|
||||
this.loadSubpackagePrefab(path, (pb: Prefab) => {
|
||||
if (target && !target.isValid) {
|
||||
pb.destroy()
|
||||
return;
|
||||
}
|
||||
pb['path'] = path;
|
||||
cb && cb(pb);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/** 加载bundle中的PB*/
|
||||
loadSubpackage3DModel(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("Model3D");
|
||||
if (bundle){
|
||||
bundle.load(url, Prefab, (err, res: Prefab) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
let cc_N = instantiate(res);
|
||||
cb && cb(cc_N);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Model3D", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.loadSubpackage3DModel(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 改变图片--bundle资源 sprite-frame类型的图片*/
|
||||
changeBundleSpriteFrame(spt: Sprite, url: string, packageName: string, cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
let spttemp:any = spt
|
||||
spttemp.frameUrl = url
|
||||
let bundle = assetManager.getBundle(packageName);
|
||||
if (bundle){
|
||||
bundle.load(url + "/spriteFrame", SpriteFrame, (err, res: SpriteFrame) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
if (spttemp.frameUrl != url) {
|
||||
return;
|
||||
}
|
||||
spt.spriteFrame = res;
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle(packageName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.changeBundleSpriteFrame(spt, url, packageName, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
/** 改变图片--bundle资源 texture类型的图片*/
|
||||
changeBundleTexture(spt: Sprite, url: string, packageName: string, cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
let bundle = assetManager.getBundle(packageName);
|
||||
if (bundle){
|
||||
bundle.load(url + "/texture", Texture2D, (err, res: Texture2D) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
let spriteFrame = new SpriteFrame()
|
||||
spriteFrame.texture = res
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle(packageName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.changeBundleTexture(spt, url, packageName, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 加载bundle中的音频文件*/
|
||||
getBundleAudio(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("Audio");
|
||||
if (bundle){
|
||||
bundle.load(url, AudioClip, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Audio", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.getBundleAudio(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 加载bundle中的配置表*/
|
||||
loadSubpackageDataTable(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("DataTable");
|
||||
if (bundle){
|
||||
bundle.load(url, JsonAsset, (err, res: JsonAsset) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("DataTable", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.loadSubpackagePrefab(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//region 加载远程音频
|
||||
/** 加载远程资源*/
|
||||
loadRemoteAudio(url: string, cb: Function = null) {
|
||||
assetManager.loadRemote<AudioClip>(url, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
/** 加载远程资源*/
|
||||
// private loadRemoteRes1(url1: string, suffix: string = 'png', cb) {
|
||||
// let tempStrArr: Array<string> = url1.split(".");
|
||||
// let aimStr = url1;
|
||||
// if (tempStrArr.length > 1) {
|
||||
// aimStr = tempStrArr[0];
|
||||
// }
|
||||
// let url: string = `http://tk3h5.hgwl710.com/Fish/DEV/TS/Res/`;
|
||||
// url += aimStr + '.' + suffix;
|
||||
// if (url1.includes("://")) { url = url1 }
|
||||
// assetManager.loadRemote<ImageAsset>(url, { cacheEnabled: true }, (err, res: ImageAsset) => {
|
||||
// if (!err) {
|
||||
// const spriteFrame = new SpriteFrame();
|
||||
// const texture = new Texture2D();
|
||||
// texture.image = res;
|
||||
// spriteFrame.texture = texture;
|
||||
// cb && cb(spriteFrame);
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
//region 加载远程图片
|
||||
/**
|
||||
* 获取远程图片资源并设置
|
||||
* @param spt 要设置的节点
|
||||
* @param url url地址
|
||||
* @param suffix 图片后缀名
|
||||
* @param cb 回调函数
|
||||
*/
|
||||
changeRemoteSpriteFrame(spt: Sprite, url: string, suffix: string = 'png', cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
assetManager.loadRemote<ImageAsset>(url, {ext: '.'+suffix}, (err, res: ImageAsset) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const spriteFrame = new SpriteFrame();
|
||||
const texture = new Texture2D();
|
||||
texture.image = res;
|
||||
spriteFrame.texture = texture;
|
||||
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** 加载resources里的PB path:不带后缀*/
|
||||
private loadResourcePrefab(path: string, cb) {
|
||||
resources.load(path, Prefab, (err, res: Prefab) => {
|
||||
if (!err) {
|
||||
cb && cb(res);
|
||||
} else {
|
||||
// loader.rlease(path);
|
||||
}
|
||||
})
|
||||
}
|
||||
/** 加载resources里的图片*/
|
||||
private loadResourceRes(path: string, cb) {
|
||||
resources.load(path, ImageAsset, (err, res: ImageAsset) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
/** 加载resources里图集里的图片*/
|
||||
// 加载 SpriteAtlas(图集),并且获取其中的一个 SpriteFrame
|
||||
// 注意 atlas 资源文件(plist)通常会和一个同名的图片文件(png)放在一个目录下, 所以需要在第二个参数指定资源类型
|
||||
private loadResourceAtlas(sptName: string, path: string, cb) {
|
||||
resources.load(path, SpriteAtlas, (err, res: SpriteAtlas) => {
|
||||
const frame = res.getSpriteFrame(sptName);
|
||||
if (!err) {
|
||||
cb && cb(frame);
|
||||
} else {
|
||||
// loader.release(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
/** 改变图片--resources里sprite-frame类型的图片*/
|
||||
changeResourceSpriteFrame(spt: Sprite, path: string, cb: Function = null) {
|
||||
if (!spt || !path) return;
|
||||
resources.load(path + "/spriteFrame", SpriteFrame, (err, res: SpriteFrame) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
spt.spriteFrame = res;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
/** 改变图片--resources里texture类型的图片*/
|
||||
changeResourceTexture(spt: Sprite, path: string, cb: Function = null) {
|
||||
if (!spt || !path) return;
|
||||
resources.load(path + "/texture", Texture2D, (err, res: Texture2D) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
let spriteFrame = new SpriteFrame()
|
||||
spriteFrame.texture = res
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//设置图片置灰
|
||||
SetGray(spt: Sprite, isGray: boolean) {
|
||||
//cc.assetManager.builtins.getBuiltin("material", "builtin-" + name)
|
||||
if (isGray) {
|
||||
let bundle = assetManager.getBundle("Materials");
|
||||
if (bundle){
|
||||
bundle.load("ui_sprite_gray", Material, (err, res: Material) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
// spt.setSharedMaterial(res, 0)
|
||||
spt.customMaterial = res
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Materials", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.SetGray(spt, isGray);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// spt.setSharedMaterial(null, 0)
|
||||
spt.customMaterial = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**设置图片模糊*/
|
||||
SetBlur(spt: Sprite, isBule: boolean) {
|
||||
if (isBule) {
|
||||
let bundle = assetManager.getBundle("Materials");
|
||||
if (bundle){
|
||||
bundle.load("mohu", Material, (err, res: Material) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
// spt.setSharedMaterial(res, 0)
|
||||
spt.customMaterial = res
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Materials", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.SetBlur(spt, isBule);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// spt.setSharedMaterial(null, 0)
|
||||
spt.customMaterial = null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2ec035aa-2267-461c-a381-5e10ec6df354",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
import { _decorator, Node, Camera, Component, director, game, instantiate, Prefab, RenderTexture, view, resources, macro } from "cc";
|
||||
import Utils from "../Common/Utils";
|
||||
import GameRootUI from "../Common/GameRootUI";
|
||||
import ResManager from "./ResManager";
|
||||
import { CommonConfig } from "../Config/CommonConfig";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ViewManager')
|
||||
export class ViewManager extends Component {
|
||||
private static _I: ViewManager = null;
|
||||
public static get I(): ViewManager {
|
||||
if (!ViewManager._I) {
|
||||
ViewManager._I = new ViewManager();
|
||||
}
|
||||
return ViewManager._I;
|
||||
}
|
||||
|
||||
private m_viewList = [];
|
||||
private m_viewListData = {};
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private openIdx = 0;
|
||||
private openViewByPrefab(err, i_prefab: Prefab | Node, i_openInfo, callBack = null, path, type: string = '') {
|
||||
if (err) {
|
||||
Utils.Log('打开界面时加载资源出错:' + err, path);
|
||||
return;
|
||||
}
|
||||
let t_node:any = instantiate(i_prefab);
|
||||
if (!t_node.isValid) return;
|
||||
|
||||
//界面已打开
|
||||
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
let t_view: Node = this.m_viewList[i];
|
||||
if (t_view) {
|
||||
if (t_view.isValid && t_node.name == t_view.name) {
|
||||
t_node.setSiblingIndex(999)
|
||||
Utils.Log('已经打开的相同的界面:' + t_node.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//截屏纹理
|
||||
if (i_openInfo && i_openInfo.blueBg===true){
|
||||
i_openInfo.screenShotTex = this.getScreenShot()
|
||||
}
|
||||
|
||||
let viewSP = t_node.getComponent(t_node.name);
|
||||
if (!viewSP) {
|
||||
for (let index = 0; index < t_node['_components'].length; index++) {
|
||||
const element = t_node['_components'][index];
|
||||
if (element.isScriptComponent) {
|
||||
viewSP = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.m_viewList.push(t_node);
|
||||
this.m_viewListData[t_node.name] = { path: path, data: i_openInfo, sort: this.openIdx++, name: t_node.name, uuid: t_node["_prefab"]['asset']['_uuid'] };
|
||||
viewSP && viewSP.openUIData && viewSP.openUIData(i_openInfo);
|
||||
callBack && callBack(t_node, i_openInfo);
|
||||
if (type == '') {
|
||||
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_ui1, this.m_viewList.length)
|
||||
} else if (type == 'top') {
|
||||
// t_node.sType = "top"
|
||||
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_top)
|
||||
} else if (type == 'tips') {
|
||||
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_tips)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//检查是否有相同的View
|
||||
private checkSameView(i_node: Node, path){
|
||||
// let t_com = i_node.getComponent('li_BaseView');
|
||||
// if (t_com) {
|
||||
// if (t_com.name == 'li_BaseView') return true;
|
||||
// for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
// let t_view: Node = this.m_viewList[i];
|
||||
// if (t_view) {
|
||||
// if (t_view.isValid && t_com.node.name == t_view.name) {
|
||||
// i_node.setSiblingIndex(999)
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// i_node['path'] = path;
|
||||
// this.m_viewList.push(i_node);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取截屏纹理
|
||||
private getScreenShot():RenderTexture {
|
||||
// let texture = new RenderTexture();
|
||||
// let winSize = view.getViewportRect()
|
||||
// let winSize1 = view.getVisibleSize()
|
||||
// texture.reset({
|
||||
// width: winSize.width,
|
||||
// height: winSize.height,
|
||||
// });
|
||||
|
||||
// let camera = director.getScene().getComponentInChildren(Camera);
|
||||
// let oldTargetTexture = camera.targetTexture
|
||||
// camera.targetTexture = texture;
|
||||
// camera.render();
|
||||
// camera.targetTexture = oldTargetTexture
|
||||
|
||||
// return texture
|
||||
return null
|
||||
}
|
||||
|
||||
private getViewIndex(i_view: Node) {
|
||||
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
let t_view = this.m_viewList[i];
|
||||
if (t_view == i_view) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**打开resources窗体 */
|
||||
openMainView(i_prefab: string | Prefab, i_openData?, callBack = null, type: string = '') {
|
||||
if (i_prefab instanceof Prefab) {
|
||||
this.openViewByPrefab(null, i_prefab, i_openData, callBack, i_prefab, type);
|
||||
} else {
|
||||
resources.load(i_prefab, (err, $prefab: Prefab) => {
|
||||
this.openViewByPrefab(err, $prefab, i_openData, callBack, i_prefab, type);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**打开bundle窗体 */
|
||||
openBundlesView(i_prefab: string | Prefab, i_openData?, callBack = null, type: string = '') {
|
||||
if (i_prefab instanceof Prefab) {
|
||||
this.openViewByPrefab(null, i_prefab, i_openData, callBack, i_prefab, type);
|
||||
} else {
|
||||
console.log("打开界面:", i_prefab);
|
||||
ResManager.I.getPrefab(i_prefab, (pb: Node) => {
|
||||
this.openViewByPrefab(null, pb, i_openData, callBack, i_prefab, type);
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**关闭窗体 */
|
||||
closeView(i_view: Node) {
|
||||
let closeUIName = null
|
||||
let t_index = this.getViewIndex(i_view);
|
||||
if (t_index > -1) {
|
||||
let t_view = this.m_viewList[t_index];
|
||||
if (t_view) {
|
||||
closeUIName = t_view.name
|
||||
delete this.m_viewListData[t_view.name];
|
||||
t_view.destroy();
|
||||
t_view.removeFromParent();
|
||||
|
||||
}
|
||||
this.m_viewList.splice(t_index, 1); //删除列表元素 参数1是指定位置,参数2是删除元素个数
|
||||
}
|
||||
else {
|
||||
if (!this.m_viewList.length) {
|
||||
i_view.destroy();
|
||||
}
|
||||
Utils.Log('试图关闭一个队列中不存在的界面:', i_view.name);
|
||||
}
|
||||
}
|
||||
|
||||
/**关闭所有窗体 */
|
||||
closeAllView(isR = false) {
|
||||
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
let t_view = this.m_viewList[i];
|
||||
if (t_view) {
|
||||
delete this.m_viewListData[t_view.name];
|
||||
t_view.destroy();
|
||||
t_view.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
this.m_viewList = [];
|
||||
this.m_viewListData = {};
|
||||
this.openIdx = 0;
|
||||
|
||||
}
|
||||
|
||||
//是否在主界面,没有打开任何其他界面。主界面是在打开场景时直接创建的,不走这里的打开接口
|
||||
isNotOpenAnyUI() {
|
||||
if (this.m_viewList && this.m_viewList.length > 0) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4c93d9e1-7465-4d94-a057-1f1c02a066ef",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user