优化若干代码

This commit is contained in:
2024-04-17 20:15:52 +08:00
parent 54580cc1b2
commit 58cc2e3b82
66 changed files with 5821 additions and 4019 deletions

View File

@@ -1,19 +1,18 @@
import { _decorator } from 'cc'
import SoundPrefab from '../../engine/uicomponent/SoundPrefab'
import MusicPrefab from '../../engine/uicomponent/MusicPrefab'
import RandomUtil from '../../engine/utils/RandomUtil'
export default class GameMusicHelper {
public static playBg() {
let randomIndex: number = RandomUtil.nextInt(1, 3)
MusicPrefab.play('background_' + randomIndex)
}
public static playBg() {
let randomIndex: number = RandomUtil.nextInt(1, 3)
MusicPrefab.play('background_' + randomIndex)
}
public static playFishDead(fishType: number) {
SoundPrefab.play('deadfish_' + fishType)
}
public static playFishDead(fishType: number) {
SoundPrefab.play('deadfish_' + fishType)
}
public static playFire() {
SoundPrefab.play('fire')
}
public static playFire() {
SoundPrefab.play('fire')
}
}

View File

@@ -1,64 +1,64 @@
import { error, game, _decorator } from 'cc'
import { error, game } from 'cc'
import DarkLayer from '../../engine/uicomponent/DarkLayer'
import LoadingPrefab from '../../engine/uicomponent/LoadingPrefab'
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
import MusicPrefab from '../../engine/uicomponent/MusicPrefab'
import Progress from '../../engine/uicomponent/Progress'
import SoundPrefab from '../../engine/uicomponent/SoundPrefab'
import { Logger } from '../../engine/utils/Logger'
import ResourcePrefab from '../prefab/ResourcePrefab'
import ShaderMaterialPrefab from '../prefab/ShaderMaterialPrefab'
export default class ResourcePreload {
public static instance: ResourcePreload = new ResourcePreload()
private isPreloaded: boolean = false
private totalNum: number = 6
private nowIndex: number = 0
private progress: Progress
public async preLoad(callback: Function, progress: Progress) {
if (this.isPreloaded) {
callback()
return
}
this.isPreloaded = true
this.progress = progress
if (this.progress) {
progress.updateProgress(this.nowIndex, this.totalNum)
}
await LoadingPrefab.preLoad() //1
this.finishOneItemLoad()
await DarkLayer.preLoad() //2
this.finishOneItemLoad()
await MusicPrefab.preLoad() //3
this.finishOneItemLoad()
await SoundPrefab.preLoad() //4
this.finishOneItemLoad()
await ResourcePrefab.preLoad() //5
this.finishOneItemLoad()
await ShaderMaterialPrefab.preLoad() //6
this.finishOneItemLoad() //
callback()
}
public static instance: ResourcePreload = new ResourcePreload()
private isPreloaded: boolean = false
private totalNum: number = 6
private nowIndex: number = 0
private progress: Progress
private finishOneItemLoad() {
this.nowIndex++
if (this.progress) {
this.progress.updateProgress(this.nowIndex, this.totalNum)
}
}
public async preLoad(callback: Function, progress: Progress) {
if (this.isPreloaded) {
callback()
return
}
this.isPreloaded = true
this.progress = progress
if (this.progress) {
progress.updateProgress(this.nowIndex, this.totalNum)
}
await LoadingPrefab.preLoad() //1
this.finishOneItemLoad()
await DarkLayer.preLoad() //2
this.finishOneItemLoad()
await MusicPrefab.preLoad() //3
this.finishOneItemLoad()
await SoundPrefab.preLoad() //4
this.finishOneItemLoad()
await ResourcePrefab.preLoad() //5
this.finishOneItemLoad()
await ShaderMaterialPrefab.preLoad() //6
this.finishOneItemLoad() //
callback()
}
public restartGame() {
this.isPreloaded = false
// GameSocket.getInstance().closeSocket(false);
LoadingScenePrefab.clear()
LoadingPrefab.clear()
error('需要获取游戏里所有的AudioSource停止音乐')
//audioEngine.stopAll();
private finishOneItemLoad() {
this.nowIndex++
if (this.progress) {
this.progress.updateProgress(this.nowIndex, this.totalNum)
}
}
// VersionManager.instance.releaseAll();
MusicPrefab.destory()
SoundPrefab.destory()
ResourcePrefab.clear()
game.restart()
}
public restartGame() {
this.isPreloaded = false
// GameSocket.getInstance().closeSocket(false);
LoadingScenePrefab.clear()
LoadingPrefab.clear()
error('需要获取游戏里所有的AudioSource停止音乐')
//audioEngine.stopAll();
// VersionManager.instance.releaseAll();
MusicPrefab.destory()
SoundPrefab.destory()
ResourcePrefab.clear()
game.restart()
}
}

View File

@@ -1,7 +1,7 @@
import { tween, Node } from 'cc'
import { Node, tween } from 'cc'
export default class TimeHelper {
public static exeNextFrame(node: Node, callback: Function) {
tween(node).delay(0.02).call(callback).start()
}
public static exeNextFrame(node: Node, callback: Function) {
tween(node).delay(0.02).call(callback).start()
}
}

View File

@@ -1,9 +1,10 @@
import { _decorator, Component, Node } from 'cc'
import { _decorator, Component } from 'cc'
const { ccclass, property } = _decorator
@ccclass('UIRoot')
export class UIRoot extends Component {
public static Instance
public static Instance: UIRoot
onLoad() {
UIRoot.Instance = this
}