优化若干代码

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,6 +1,4 @@
import { _decorator, Sprite, Prefab, Node, instantiate, Vec3, Tween } from 'cc'
const { ccclass, property } = _decorator
import { _decorator, instantiate, Node, Prefab, Sprite, Tween, Vec3 } from 'cc'
import SceneBase from './SceneBase'
import TextureMgr from '../../engine/uicomponent/TextureMgr'
import RandomUtil from '../../engine/utils/RandomUtil'
@@ -11,62 +9,65 @@ import { Logger } from '../../engine/utils/Logger'
import FishWiki from '../../../fish/script/FishWiki'
import GameMusicHelper from '../utils/GameMusicHelper'
const { ccclass, property } = _decorator
@ccclass('FishGameScene')
export default class FishGameScene extends SceneBase {
@property(Sprite)
private bg: Sprite | null = null
@property({ type: [Prefab] })
private fishPrefabList: Array<Prefab> = []
private showNode: Node | null = null
onLoadMe() {
GameMusicHelper.playBg()
FishPathConfig.init()
this.initBg()
// this.testPathPlay()
}
@property(Sprite)
private bg: Sprite | null = null
@property({ type: [Prefab] })
private fishPrefabList: Array<Prefab> | null = []
private showNode: Node | null = null
private initBg() {
let textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
this.bg.spriteFrame =
textureMgr.Spriteset[
RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)
]
}
onLoadMe() {
GameMusicHelper.playBg()
FishPathConfig.init()
this.initBg()
// this.testPathPlay()
}
private initShowNode() {
if (this.showNode) {
this.showNode.destroy()
this.showNode = null
}
let 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 initBg() {
let textureMgr: TextureMgr = this.bg.getComponent(TextureMgr)
this.bg.spriteFrame =
textureMgr.Spriteset[
RandomUtil.nextInt(0, textureMgr.Spriteset.length - 1)
]
}
private testPathPlay() {
this.initShowNode()
let pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
Logger.log('testPathPlay=pathInfo=', pathInfo)
let params = pathInfo.path
let 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 initShowNode() {
if (this.showNode) {
this.showNode.destroy()
this.showNode = null
}
let 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 onClickWiki() {
FishWiki.show()
}
private testPathPlay() {
this.initShowNode()
let pathInfo: FishPathInfo = FishPathConfig.getPathInfo(3)
Logger.log('testPathPlay=pathInfo=', pathInfo)
let params = pathInfo.path
let 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()
}
onDestroyMe() {
this.unscheduleAllCallbacks()
//this.node.stopAllActions();
Tween.stopAllByTarget(this.node)
}
private onClickWiki() {
FishWiki.show()
}
onDestroyMe() {
this.unscheduleAllCallbacks()
//this.node.stopAllActions();
Tween.stopAllByTarget(this.node)
}
}