i
This commit is contained in:
@@ -1,111 +1,111 @@
|
||||
import {
|
||||
Component,
|
||||
Game,
|
||||
Node,
|
||||
Prefab,
|
||||
Sprite,
|
||||
Tween,
|
||||
Vec3,
|
||||
_decorator,
|
||||
director,
|
||||
game,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import FishWiki from '../../../fish/script/FishWiki'
|
||||
import TextureMgr from '../../engine/uicomponent/TextureMgr'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
import WsManager from '../manager/WsManager'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishGameScene')
|
||||
export default class FishGameScene extends Component {
|
||||
@property(Sprite)
|
||||
private bg: Sprite | null = null
|
||||
|
||||
@property({ type: [Prefab] })
|
||||
private fishPrefabList: Array<Prefab> | null = []
|
||||
|
||||
private showNode: Node | null = null
|
||||
|
||||
onLoad() {
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
WsManager.instance.init()
|
||||
GameMusicHelper.playBg()
|
||||
WsManager.instance.on(400, this.showMsg, this)
|
||||
// FishPathConfig.init()
|
||||
// this.initBg()
|
||||
// this.testPathPlay()
|
||||
game.on(Game.EVENT_HIDE, this.onHide, this)
|
||||
game.on(Game.EVENT_SHOW, this.onAppShow, this)
|
||||
}
|
||||
|
||||
private initBg() {
|
||||
const textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
|
||||
this.bg.spriteFrame =
|
||||
textureMgr.Spriteset[RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)]
|
||||
}
|
||||
|
||||
private initShowNode() {
|
||||
if (this.showNode) {
|
||||
this.showNode.destroy()
|
||||
this.showNode = null
|
||||
}
|
||||
const fishType: number = 29
|
||||
if (fishType < 1 || fishType > 29) return
|
||||
|
||||
this.showNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
this.showNode.getComponent(FishMover).speed = 2
|
||||
this.showNode.getComponent(FishMover).node.setScale(new Vec3(2, 2, 1))
|
||||
this.node.addChild(this.showNode)
|
||||
}
|
||||
|
||||
private testPathPlay() {
|
||||
this.initShowNode()
|
||||
const pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
|
||||
Logger.log('testPathPlay=pathInfo=', pathInfo)
|
||||
const params = pathInfo.path
|
||||
const param0 = params[0]
|
||||
Logger.log('testPathPlay=11=', param0)
|
||||
this.showNode.setPosition(new Vec3(param0.x, param0.y, 0))
|
||||
this.showNode.getComponent(FishMover).bezierPList = params
|
||||
this.showNode.getComponent(FishMover).startMove()
|
||||
}
|
||||
|
||||
private onClickWiki() {
|
||||
FishWiki.show()
|
||||
}
|
||||
|
||||
private showMsg(res: any) {
|
||||
Logger.log('showMsg=res=', res)
|
||||
CommonTips.showMsg(res.msg)
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
this.unscheduleAllCallbacks()
|
||||
// this.node.stopAllActions();
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
|
||||
onHide() {
|
||||
director.pause()
|
||||
}
|
||||
|
||||
onAppShow() {
|
||||
director.resume()
|
||||
}
|
||||
}
|
||||
import {
|
||||
Component,
|
||||
Game,
|
||||
Node,
|
||||
Prefab,
|
||||
Sprite,
|
||||
Tween,
|
||||
Vec3,
|
||||
_decorator,
|
||||
director,
|
||||
game,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import FishWiki from '../../../fish/script/FishWiki'
|
||||
import TextureMgr from '../../engine/uicomponent/TextureMgr'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
import WsManager from '../manager/WsManager'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('FishGameScene')
|
||||
export default class FishGameScene extends Component {
|
||||
@property(Sprite)
|
||||
private bg: Sprite | null = null
|
||||
|
||||
@property({ type: [Prefab] })
|
||||
private fishPrefabList: Array<Prefab> | null = []
|
||||
|
||||
private showNode: Node | null = null
|
||||
|
||||
onLoad() {
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
WsManager.instance.init()
|
||||
GameMusicHelper.playBg()
|
||||
WsManager.instance.on(400, this.showMsg, this)
|
||||
// FishPathConfig.init()
|
||||
// this.initBg()
|
||||
// this.testPathPlay()
|
||||
game.on(Game.EVENT_HIDE, this.onHide, this)
|
||||
game.on(Game.EVENT_SHOW, this.onAppShow, this)
|
||||
}
|
||||
|
||||
private initBg() {
|
||||
const textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
|
||||
this.bg.spriteFrame =
|
||||
textureMgr.Spriteset[RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)]
|
||||
}
|
||||
|
||||
private initShowNode() {
|
||||
if (this.showNode) {
|
||||
this.showNode.destroy()
|
||||
this.showNode = null
|
||||
}
|
||||
const fishType: number = 29
|
||||
if (fishType < 1 || fishType > 29) return
|
||||
|
||||
this.showNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
this.showNode.getComponent(FishMover).speed = 2
|
||||
this.showNode.getComponent(FishMover).node.setScale(new Vec3(2, 2, 1))
|
||||
this.node.addChild(this.showNode)
|
||||
}
|
||||
|
||||
private testPathPlay() {
|
||||
this.initShowNode()
|
||||
const pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
|
||||
Logger.log('testPathPlay=pathInfo=', pathInfo)
|
||||
const params = pathInfo.path
|
||||
const param0 = params[0]
|
||||
Logger.log('testPathPlay=11=', param0)
|
||||
this.showNode.setPosition(new Vec3(param0.x, param0.y, 0))
|
||||
this.showNode.getComponent(FishMover).bezierPList = params
|
||||
this.showNode.getComponent(FishMover).startMove()
|
||||
}
|
||||
|
||||
private onClickWiki() {
|
||||
FishWiki.show()
|
||||
}
|
||||
|
||||
private showMsg(res: any) {
|
||||
Logger.log('showMsg=res=', res)
|
||||
CommonTips.showMsg(res.msg)
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
this.unscheduleAllCallbacks()
|
||||
// this.node.stopAllActions();
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
|
||||
onHide() {
|
||||
director.pause()
|
||||
}
|
||||
|
||||
onAppShow() {
|
||||
director.resume()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ebb8d437-f642-4a91-9a2c-6d9b8743d7d7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ebb8d437-f642-4a91-9a2c-6d9b8743d7d7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
import {
|
||||
_decorator,
|
||||
Node,
|
||||
sys,
|
||||
profiler,
|
||||
DynamicAtlasManager,
|
||||
PhysicsSystem2D,
|
||||
Component,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import MusicConfig from '../../engine/config/MusicConfig'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import Progress from '../../engine/uicomponent/Progress'
|
||||
import EventManager, { HaoEvent } from '../../engine/utils/EventManager'
|
||||
import HotUpdate from '../../engine/utils/HotUpdate'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import VersionManager from '../../engine/utils/VersionManager'
|
||||
import ResourcePreload from '../utils/ResourcePreload'
|
||||
import SceneManager from './SceneManager'
|
||||
import { FishConfig } from '../config/FishConfig'
|
||||
|
||||
@ccclass('LoadingScene')
|
||||
export default class LoadingScene extends Component {
|
||||
public static scriptName: string = 'LoadingScene'
|
||||
@property({ type: Node })
|
||||
private progressNode: Node | null = null
|
||||
|
||||
protected onLoad(): void {
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
this.baseInit()
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_NeedUpdate, this.onNeedUpdate, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_Progress, this.onUpdateProgress, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_Fail_Update, this.onUpdateFail, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_Finish_Update, this.onUpdateFinish, this)
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
this.onUpdateFinish,
|
||||
this,
|
||||
)
|
||||
if (sys.isNative && VersionManager.instance.isOpenHotUpdate) {
|
||||
this.checkUpdate()
|
||||
} else {
|
||||
this.preLoadRes()
|
||||
}
|
||||
}
|
||||
|
||||
private async baseInit() {
|
||||
try {
|
||||
await FishConfig.init()
|
||||
profiler.hideStats() //showStats
|
||||
//let collisionManager:cc.CollisionManager = director.getCollisionManager();
|
||||
PhysicsSystem2D.instance.enable = true
|
||||
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
// EPhysics2DDrawFlags.CenterOfMass |
|
||||
// EPhysics2DDrawFlags.Joint |
|
||||
// EPhysics2DDrawFlags.Shape;
|
||||
|
||||
//if(collisionManager){
|
||||
//collisionManager.enabled = true;
|
||||
// collisionManager.enabledDebugDraw = true;
|
||||
// collisionManager.enabledDrawBoundingBox = true;
|
||||
//}
|
||||
|
||||
if (DynamicAtlasManager.instance) {
|
||||
DynamicAtlasManager.instance.enabled = false
|
||||
}
|
||||
MusicConfig.init()
|
||||
// cc.director.getCollisionManager().enabled=true;//这是一个全局属性,开启后就代表碰撞检测组件可以进行检测了
|
||||
// cc.director.getCollisionManager().enabledDebugDraw = true; //绘制碰撞区域
|
||||
} catch (error) {
|
||||
Logger.error(this, error)
|
||||
}
|
||||
}
|
||||
|
||||
private checkUpdate() {
|
||||
Logger.log(this, 'checkUpdate====')
|
||||
VersionManager.instance.checkUpdate(0)
|
||||
}
|
||||
|
||||
private onNeedUpdate(event: HaoEvent, key: string) {
|
||||
Logger.log(this, 'onNeedUpdate=====', key, VersionManager.Config_Key)
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
VersionManager.instance.startUpdate(0)
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateProgress(event, loadedFiles, totalFiles, key) {
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
let msg: string = Math.min(100, (loadedFiles / totalFiles) * 100).toFixed(2) + '%'
|
||||
this.progressNode.getComponent(Progress).updateProgress(loadedFiles, totalFiles, msg)
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateFail(event, key: string) {
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
Logger.warn(this, '热更新失败========')
|
||||
CommonTips.showMsg('热更新失败')
|
||||
ResourcePreload.instance.restartGame()
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateFinish(event, key: string, needRestart: boolean) {
|
||||
Logger.log(this, 'onUpdateFinish========')
|
||||
if (key == VersionManager.Config_Key[0] && !needRestart) {
|
||||
this.preLoadRes()
|
||||
}
|
||||
}
|
||||
|
||||
private async preLoadRes() {
|
||||
ResourcePreload.instance.preLoad(() => {
|
||||
this.startGame()
|
||||
}, this.progressNode.getComponent(Progress))
|
||||
}
|
||||
|
||||
private startGame() {
|
||||
Logger.info(this, 'startGame')
|
||||
SceneManager.instance.sceneSwitch('FishGameScene', true)
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_NeedUpdate, this.onNeedUpdate)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_Progress, this.onUpdateProgress)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_Fail_Update, this.onUpdateFail)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_Finish_Update, this.onUpdateFinish)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_ALREADY_UP_TO_DATE, this.onUpdateFinish)
|
||||
}
|
||||
}
|
||||
import {
|
||||
_decorator,
|
||||
Node,
|
||||
sys,
|
||||
profiler,
|
||||
DynamicAtlasManager,
|
||||
PhysicsSystem2D,
|
||||
Component,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import MusicConfig from '../../engine/config/MusicConfig'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import Progress from '../../engine/uicomponent/Progress'
|
||||
import EventManager, { HaoEvent } from '../../engine/utils/EventManager'
|
||||
import HotUpdate from '../../engine/utils/HotUpdate'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import VersionManager from '../../engine/utils/VersionManager'
|
||||
import ResourcePreload from '../utils/ResourcePreload'
|
||||
import SceneManager from './SceneManager'
|
||||
import { FishConfig } from '../config/FishConfig'
|
||||
|
||||
@ccclass('LoadingScene')
|
||||
export default class LoadingScene extends Component {
|
||||
public static scriptName: string = 'LoadingScene'
|
||||
@property({ type: Node })
|
||||
private progressNode: Node | null = null
|
||||
|
||||
protected onLoad(): void {
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onLoadMe() {
|
||||
this.baseInit()
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_NeedUpdate, this.onNeedUpdate, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_Progress, this.onUpdateProgress, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_On_Fail_Update, this.onUpdateFail, this)
|
||||
EventManager.instance.addListener(HotUpdate.Event_Finish_Update, this.onUpdateFinish, this)
|
||||
EventManager.instance.addListener(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
this.onUpdateFinish,
|
||||
this,
|
||||
)
|
||||
if (sys.isNative && VersionManager.instance.isOpenHotUpdate) {
|
||||
this.checkUpdate()
|
||||
} else {
|
||||
this.preLoadRes()
|
||||
}
|
||||
}
|
||||
|
||||
private async baseInit() {
|
||||
try {
|
||||
await FishConfig.init()
|
||||
profiler.hideStats() //showStats
|
||||
//let collisionManager:cc.CollisionManager = director.getCollisionManager();
|
||||
PhysicsSystem2D.instance.enable = true
|
||||
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
// EPhysics2DDrawFlags.CenterOfMass |
|
||||
// EPhysics2DDrawFlags.Joint |
|
||||
// EPhysics2DDrawFlags.Shape;
|
||||
|
||||
//if(collisionManager){
|
||||
//collisionManager.enabled = true;
|
||||
// collisionManager.enabledDebugDraw = true;
|
||||
// collisionManager.enabledDrawBoundingBox = true;
|
||||
//}
|
||||
|
||||
if (DynamicAtlasManager.instance) {
|
||||
DynamicAtlasManager.instance.enabled = false
|
||||
}
|
||||
MusicConfig.init()
|
||||
// cc.director.getCollisionManager().enabled=true;//这是一个全局属性,开启后就代表碰撞检测组件可以进行检测了
|
||||
// cc.director.getCollisionManager().enabledDebugDraw = true; //绘制碰撞区域
|
||||
} catch (error) {
|
||||
Logger.error(this, error)
|
||||
}
|
||||
}
|
||||
|
||||
private checkUpdate() {
|
||||
Logger.log(this, 'checkUpdate====')
|
||||
VersionManager.instance.checkUpdate(0)
|
||||
}
|
||||
|
||||
private onNeedUpdate(event: HaoEvent, key: string) {
|
||||
Logger.log(this, 'onNeedUpdate=====', key, VersionManager.Config_Key)
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
VersionManager.instance.startUpdate(0)
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateProgress(event, loadedFiles, totalFiles, key) {
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
let msg: string = Math.min(100, (loadedFiles / totalFiles) * 100).toFixed(2) + '%'
|
||||
this.progressNode.getComponent(Progress).updateProgress(loadedFiles, totalFiles, msg)
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateFail(event, key: string) {
|
||||
if (key == VersionManager.Config_Key[0]) {
|
||||
Logger.warn(this, '热更新失败========')
|
||||
CommonTips.showMsg('热更新失败')
|
||||
ResourcePreload.instance.restartGame()
|
||||
}
|
||||
}
|
||||
|
||||
private onUpdateFinish(event, key: string, needRestart: boolean) {
|
||||
Logger.log(this, 'onUpdateFinish========')
|
||||
if (key == VersionManager.Config_Key[0] && !needRestart) {
|
||||
this.preLoadRes()
|
||||
}
|
||||
}
|
||||
|
||||
private async preLoadRes() {
|
||||
ResourcePreload.instance.preLoad(() => {
|
||||
this.startGame()
|
||||
}, this.progressNode.getComponent(Progress))
|
||||
}
|
||||
|
||||
private startGame() {
|
||||
Logger.info(this, 'startGame')
|
||||
SceneManager.instance.sceneSwitch('FishGameScene', true)
|
||||
}
|
||||
|
||||
onDestroyMe() {
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_NeedUpdate, this.onNeedUpdate)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_Progress, this.onUpdateProgress)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_Fail_Update, this.onUpdateFail)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_Finish_Update, this.onUpdateFinish)
|
||||
EventManager.instance.removeListener(HotUpdate.Event_On_ALREADY_UP_TO_DATE, this.onUpdateFinish)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ba786f67-34b5-4fa6-abc5-69a3ef70bfd3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ba786f67-34b5-4fa6-abc5-69a3ef70bfd3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
import { SceneAsset, director, sys } from 'cc'
|
||||
|
||||
import CommonEvent from '../../engine/config/CommonEvent'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
|
||||
import EventManager from '../../engine/utils/EventManager'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
|
||||
export default class SceneManager {
|
||||
public static instance: SceneManager = new SceneManager()
|
||||
|
||||
private loadingSceneName: string
|
||||
|
||||
public currentSceneName: string
|
||||
|
||||
public initFullScreenPrefab(isShow: boolean = false) {
|
||||
if (sys.isBrowser && !sys.isMobile) {
|
||||
if (isShow) {
|
||||
// FullscreenPrefab.show();
|
||||
} else {
|
||||
// FullscreenPrefab.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async sceneSwitch(name: string, showProgress: boolean = false) {
|
||||
if (this.loadingSceneName === name) return
|
||||
Logger.log(this, 'sceneSwitch==', name)
|
||||
if (sys.isBrowser) {
|
||||
// showProgress = true;
|
||||
}
|
||||
this.initFullScreenPrefab(false)
|
||||
this.loadingSceneName = name
|
||||
if (showProgress) {
|
||||
await LoadingScenePrefab.show()
|
||||
director.preloadScene(
|
||||
name,
|
||||
(completedCount: number, totalCount: number, item: any) => {
|
||||
LoadingScenePrefab.updateLoading(completedCount, totalCount)
|
||||
},
|
||||
(error: Error, asset: SceneAsset) => {
|
||||
if (error) {
|
||||
Logger.warn(this, 'preloadScene=error', error.message)
|
||||
CommonTips.showMsg('加载场景失败')
|
||||
} else {
|
||||
// director.getScene().destroy();//director.getScene().cleanup();
|
||||
director.loadScene(name, this.loadSceneOK.bind(this))
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
// director.getScene().destroy();//director.getScene().cleanup();
|
||||
director.loadScene(name, this.loadSceneOK.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
private loadSceneOK() {
|
||||
LoadingScenePrefab.close()
|
||||
this.initFullScreenPrefab(true)
|
||||
this.currentSceneName = this.loadingSceneName
|
||||
this.loadingSceneName = ''
|
||||
Logger.log(this, 'scene load ok=', this.currentSceneName)
|
||||
EventManager.instance.dispatchEvent(CommonEvent.Event_Scene_Switch)
|
||||
}
|
||||
|
||||
public preloadScene(
|
||||
sceneName: string,
|
||||
onProgressCallback: any = null,
|
||||
onLoadedCallback: any = null,
|
||||
) {
|
||||
director.preloadScene(sceneName, onProgressCallback, onLoadedCallback)
|
||||
}
|
||||
}
|
||||
import { SceneAsset, director, sys } from 'cc'
|
||||
|
||||
import CommonEvent from '../../engine/config/CommonEvent'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
|
||||
import EventManager from '../../engine/utils/EventManager'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
|
||||
export default class SceneManager {
|
||||
public static instance: SceneManager = new SceneManager()
|
||||
|
||||
private loadingSceneName: string
|
||||
|
||||
public currentSceneName: string
|
||||
|
||||
public initFullScreenPrefab(isShow: boolean = false) {
|
||||
if (sys.isBrowser && !sys.isMobile) {
|
||||
if (isShow) {
|
||||
// FullscreenPrefab.show();
|
||||
} else {
|
||||
// FullscreenPrefab.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async sceneSwitch(name: string, showProgress: boolean = false) {
|
||||
if (this.loadingSceneName === name) return
|
||||
Logger.log(this, 'sceneSwitch==', name)
|
||||
if (sys.isBrowser) {
|
||||
// showProgress = true;
|
||||
}
|
||||
this.initFullScreenPrefab(false)
|
||||
this.loadingSceneName = name
|
||||
if (showProgress) {
|
||||
await LoadingScenePrefab.show()
|
||||
director.preloadScene(
|
||||
name,
|
||||
(completedCount: number, totalCount: number, item: any) => {
|
||||
LoadingScenePrefab.updateLoading(completedCount, totalCount)
|
||||
},
|
||||
(error: Error, asset: SceneAsset) => {
|
||||
if (error) {
|
||||
Logger.warn(this, 'preloadScene=error', error.message)
|
||||
CommonTips.showMsg('加载场景失败')
|
||||
} else {
|
||||
// director.getScene().destroy();//director.getScene().cleanup();
|
||||
director.loadScene(name, this.loadSceneOK.bind(this))
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
// director.getScene().destroy();//director.getScene().cleanup();
|
||||
director.loadScene(name, this.loadSceneOK.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
private loadSceneOK() {
|
||||
LoadingScenePrefab.close()
|
||||
this.initFullScreenPrefab(true)
|
||||
this.currentSceneName = this.loadingSceneName
|
||||
this.loadingSceneName = ''
|
||||
Logger.log(this, 'scene load ok=', this.currentSceneName)
|
||||
EventManager.instance.dispatchEvent(CommonEvent.Event_Scene_Switch)
|
||||
}
|
||||
|
||||
public preloadScene(
|
||||
sceneName: string,
|
||||
onProgressCallback: any = null,
|
||||
onLoadedCallback: any = null,
|
||||
) {
|
||||
director.preloadScene(sceneName, onProgressCallback, onLoadedCallback)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b636d5b8-723e-4576-861b-5cfc3151e46a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b636d5b8-723e-4576-861b-5cfc3151e46a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user