优化若干代码

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,44 +1,44 @@
import { _decorator } from 'cc'
import { FishInfo } from './FishInfo'
export class FishConfig {
public static readonly config: ReadonlyArray<FishInfo> = [
new FishInfo(1, '蝴蝶鱼', 2, 2),
new FishInfo(2, '鲶鱼', 2, 1),
new FishInfo(3, '狮子鱼', 2, 2),
new FishInfo(4, '条纹鱼', 2, 2),
new FishInfo(5, '沙丁鱼', 2, 2),
new FishInfo(6, '石斑鱼', 2, 2),
new FishInfo(7, '河豚', 3, 1.2),
new FishInfo(8, '海螺', 3, 2),
new FishInfo(9, '接吻鱼', 3, 1.2),
new FishInfo(10, '海姆', 4, 1),
new FishInfo(11, '绿鳍鱼', 4, 1.2),
new FishInfo(12, '鲎', 4, 1.2),
new FishInfo(13, '魔鬼鱼', 5, 0.6),
new FishInfo(14, '小海龟', 5, 2),
new FishInfo(15, '锤头鲨', 6, 0.5),
new FishInfo(16, '金枪鱼', 6, 0.5),
new FishInfo(17, '大三元', 6, 0.5),
new FishInfo(18, '黄金鲎', 6, 1.2),
new FishInfo(19, '大四喜', 7, 0.5),
new FishInfo(20, '黄金锤头鲨', 7, 0.5),
new FishInfo(21, '金海姆', 7, 0.6),
new FishInfo(22, '五福临门', 8, 0.4),
new FishInfo(23, '金海龟', 8, 0.7),
new FishInfo(24, '金鲨', 8, 0.5),
new FishInfo(25, '蓝鲨', 8, 0.5),
new FishInfo(26, '美人鱼', 14, 0.4),
new FishInfo(27, '金龙', 14, 0.3),
new FishInfo(28, '章鱼', 10, 0.5),
new FishInfo(29, '电鳗鱼', 3, 0.8),
]
public static getFishInfoByType(fishType: number) {
for (let i = 0; i < this.config.length; i++) {
let fishInfo: FishInfo = this.config[i]
if (fishInfo.fishType == fishType) {
return fishInfo
}
}
}
public static readonly config: ReadonlyArray<FishInfo> = [
new FishInfo(1, '蝴蝶鱼', 2, 2),
new FishInfo(2, '鲶鱼', 2, 1),
new FishInfo(3, '狮子鱼', 2, 2),
new FishInfo(4, '条纹鱼', 2, 2),
new FishInfo(5, '沙丁鱼', 2, 2),
new FishInfo(6, '石斑鱼', 2, 2),
new FishInfo(7, '河豚', 3, 1.2),
new FishInfo(8, '海螺', 3, 2),
new FishInfo(9, '接吻鱼', 3, 1.2),
new FishInfo(10, '海姆', 4, 1),
new FishInfo(11, '绿鳍鱼', 4, 1.2),
new FishInfo(12, '鲎', 4, 1.2),
new FishInfo(13, '魔鬼鱼', 5, 0.6),
new FishInfo(14, '小海龟', 5, 2),
new FishInfo(15, '锤头鲨', 6, 0.5),
new FishInfo(16, '金枪鱼', 6, 0.5),
new FishInfo(17, '大三元', 6, 0.5),
new FishInfo(18, '黄金鲎', 6, 1.2),
new FishInfo(19, '大四喜', 7, 0.5),
new FishInfo(20, '黄金锤头鲨', 7, 0.5),
new FishInfo(21, '金海姆', 7, 0.6),
new FishInfo(22, '五福临门', 8, 0.4),
new FishInfo(23, '金海龟', 8, 0.7),
new FishInfo(24, '金鲨', 8, 0.5),
new FishInfo(25, '蓝鲨', 8, 0.5),
new FishInfo(26, '美人鱼', 14, 0.4),
new FishInfo(27, '金龙', 14, 0.3),
new FishInfo(28, '章鱼', 10, 0.5),
new FishInfo(29, '电鳗鱼', 3, 0.8)
]
public static getFishInfoByType(fishType: number) {
for (let i = 0; i < this.config.length; i++) {
let fishInfo: FishInfo = this.config[i]
if (fishInfo.fishType == fishType) {
return fishInfo
}
}
}
}

View File

@@ -1,18 +1,18 @@
import { _decorator } from 'cc'
export class FishInfo {
public fishType: number
public name: string
public blood: number
public wikiScale: number
constructor(
fishType: number,
name: string,
blood: number,
wikiScale: number
) {
this.fishType = fishType
this.name = name
this.blood = blood
this.wikiScale = wikiScale
}
public fishType: number
public name: string
public blood: number
public wikiScale: number
constructor(
fishType: number,
name: string,
blood: number,
wikiScale: number
) {
this.fishType = fishType
this.name = name
this.blood = blood
this.wikiScale = wikiScale
}
}

View File

@@ -1,11 +1,11 @@
import { _decorator } from 'cc'
import { FishMapInfo } from './FishMapInfo'
export class FishMap {
public mapId: number
public fishMapInfoList: Array<FishMapInfo>
constructor(mapId: number, list: Array<FishMapInfo>) {
this.mapId = mapId
this.fishMapInfoList = list
}
public mapId: number
public fishMapInfoList: Array<FishMapInfo>
constructor(mapId: number, list: Array<FishMapInfo>) {
this.mapId = mapId
this.fishMapInfoList = list
}
}

View File

@@ -1,21 +1,21 @@
import { _decorator } from 'cc'
export class FishMapInfo {
public fishType: number
public scale: number
public side: number //1: -1:
public x: number
public y: number
constructor(
fishType: number,
scale: number,
side: number,
x: number,
y: number
) {
this.fishType = fishType
this.scale = scale
this.side = side
this.x = x
this.y = y
}
public fishType: number
public scale: number
public side: number //1: -1:
public x: number
public y: number
constructor(
fishType: number,
scale: number,
side: number,
x: number,
y: number
) {
this.fishType = fishType
this.scale = scale
this.side = side
this.x = x
this.y = y
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,11 @@
import { _decorator, Vec2 } from 'cc'
import { Vec2 } from 'cc'
export class FishPathInfo {
public pathId: number
public path: Array<Vec2> = []
constructor(pathId: number, path: Array<Vec2>) {
this.pathId = pathId
this.path = path
}
public pathId: number
public path: Array<Vec2> = []
constructor(pathId: number, path: Array<Vec2>) {
this.pathId = pathId
this.path = path
}
}

View File

@@ -1,4 +1,3 @@
import { _decorator } from 'cc'
export class GameConfig {
public static GameName: string = 'FishSingle'
public static GameName: string = 'FishSingle'
}

View File

@@ -1,2 +1,2 @@
import { _decorator } from 'cc'
export default class GameEvent {}
export default class GameEvent {
}

View File

@@ -1,21 +1,16 @@
import {
_decorator,
Component,
Prefab,
NodePool,
Event,
Node,
Vec3,
Vec2,
EventTouch,
UITransform,
instantiate,
sys,
error,
_decorator,
Component,
EventTouch,
instantiate,
Node,
NodePool,
Prefab,
sys,
UITransform,
Vec2,
Vec3
} from 'cc'
const { ccclass, property } = _decorator
import { Logger } from '../../engine/utils/Logger'
import FishBulletBase from '../../../fish/script/FishBulletBase'
import MathUtils from '../../engine/utils/MathUtils'
import CannonManager from './CannonManager'
@@ -25,136 +20,140 @@ import GameMusicHelper from '../utils/GameMusicHelper'
import FishUI from '../../../fish/script/FishUI'
import CommonTips from '../../engine/uicomponent/CommonTips'
const { ccclass, property } = _decorator
@ccclass('BulletManager')
export default class BulletManager extends Component {
public static instance: BulletManager = null
@property({ type: [Prefab] })
private bulletPrefabList: Prefab[] = []
private bulletPool: Array<NodePool> = []
private bulletList: Array<FishBulletBase> = []
private bulletMoveSpeed: number = 30
private _vec3Cache
private _vec2Cache
private _fireTime: number = 0
private _fireTimeNew: number
onLoad() {
this._vec3Cache = new Vec3()
this._vec2Cache = new Vec2()
BulletManager.instance = this
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
// this.node.on(Node.EventType.TOUCH_MOVE, this.onShootBullet, this)
}
public static instance: BulletManager = null
@property({ type: [Prefab] })
private bulletPrefabList: Prefab[] | [] = []
private bulletPool: Array<NodePool> = []
private bulletList: Array<FishBulletBase> = []
private bulletMoveSpeed: number = 30
private _vec3Cache: Vec3
private _vec2Cache: Vec2
private _fireTime: number = 0
private _fireTimeNew: number
start() {}
onLoad() {
this._vec3Cache = new Vec3()
this._vec2Cache = new Vec2()
BulletManager.instance = this
this.node.on(Node.EventType.TOUCH_START, this.onShootBullet, this)
// this.node.on(Node.EventType.TOUCH_MOVE, this.onShootBullet, this)
}
update() {
this.checkMoveBullet()
}
start() {
}
private checkMoveBullet() {
for (let i = this.bulletList.length - 1; i >= 0; i--) {
let bullet: FishBulletBase = this.bulletList[i]
let isMoving: boolean = MoveHelper.moveNode(
bullet.node,
this.bulletMoveSpeed,
bullet.targetP.x,
bullet.targetP.y
)
if (!isMoving) {
bullet.node.getPosition(this._vec3Cache)
this._vec2Cache.x = this._vec3Cache.x
this._vec2Cache.y = this._vec3Cache.y
FishNetManager.instance.addFishNet(bullet.bulletType, this._vec2Cache)
this.bulletList.splice(i, 1)
this.destroyBullet(bullet)
}
}
}
update() {
this.checkMoveBullet()
}
private onShootBullet(event: EventTouch) {
//TOUCH_START 在Editor上连续触发2次导致发2次炮弹bug
if (sys.platform == 'EDITOR_PAGE') {
this._fireTimeNew = new Date().getTime()
if (this._fireTimeNew - this._fireTime < 100) {
return
}
this._fireTime = this._fireTimeNew
}
private checkMoveBullet() {
for (let i = this.bulletList.length - 1; i >= 0; i--) {
let bullet: FishBulletBase = this.bulletList[i]
let isMoving: boolean = MoveHelper.moveNode(
bullet.node,
this.bulletMoveSpeed,
bullet.targetP.x,
bullet.targetP.y
)
if (!isMoving) {
bullet.node.getPosition(this._vec3Cache)
this._vec2Cache.x = this._vec3Cache.x
this._vec2Cache.y = this._vec3Cache.y
FishNetManager.instance.addFishNet(bullet.bulletType, this._vec2Cache)
this.bulletList.splice(i, 1)
this.destroyBullet(bullet)
}
}
}
let tran = this.node.getComponent(UITransform)
let location = event.getUILocation()
this._vec3Cache.x = location.x
this._vec3Cache.y = location.y
this._vec3Cache.z = 0
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
let localP: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
FishUI.instance.playClickEffect(localP)
// 子弹发射
if (FishUI.instance.dz_score >= CannonManager.instance.cannonType) {
FishUI.instance.dz_score -= CannonManager.instance.cannonType
FishUI.instance.refreshScore()
this._vec3Cache = CannonManager.instance.getCannonPosition()
private onShootBullet(event: EventTouch) {
//TOUCH_START 在Editor上连续触发2次导致发2次炮弹bug
if (sys.platform == 'EDITOR_PAGE') {
this._fireTimeNew = new Date().getTime()
if (this._fireTimeNew - this._fireTime < 100) {
return
}
this._fireTime = this._fireTimeNew
}
let rad: number = MathUtils.p2pRad(
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
localP
)
let rot: number = MathUtils.radiansToDegrees(rad)
let bullet: FishBulletBase = this.createBullet(
CannonManager.instance.cannonType - 1
)
bullet.targetP = localP
this.node.addChild(bullet.node)
bullet.node.setPosition(CannonManager.instance.getCannonPosition())
this._vec3Cache.x = 1
this._vec3Cache.y = 1
this._vec3Cache.y = 1
Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, 2)
bullet.node.setScale(this._vec3Cache)
bullet.node.angle = rot
this.bulletList.push(bullet)
GameMusicHelper.playFire()
let tran = this.node.getComponent(UITransform)
let location = event.getUILocation()
this._vec3Cache.x = location.x
this._vec3Cache.y = location.y
this._vec3Cache.z = 0
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
let localP: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
FishUI.instance.playClickEffect(localP)
// 子弹发射
if (FishUI.instance.dz_score >= CannonManager.instance.cannonType) {
FishUI.instance.dz_score -= CannonManager.instance.cannonType
FishUI.instance.refreshScore()
this._vec3Cache = CannonManager.instance.getCannonPosition()
//旋转炮台
CannonManager.instance.rotateCannon(location)
} else {
CommonTips.showMsg('豆子不足!')
}
}
let rad: number = MathUtils.p2pRad(
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
localP
)
let rot: number = MathUtils.radiansToDegrees(rad)
let bullet: FishBulletBase = this.createBullet(
CannonManager.instance.cannonType - 1
)
bullet.targetP = localP
this.node.addChild(bullet.node)
bullet.node.setPosition(CannonManager.instance.getCannonPosition())
this._vec3Cache.x = 1
this._vec3Cache.y = 1
this._vec3Cache.y = 1
Vec3.multiplyScalar(this._vec3Cache, this._vec3Cache, 2)
bullet.node.setScale(this._vec3Cache)
bullet.node.angle = rot
this.bulletList.push(bullet)
GameMusicHelper.playFire()
private createBullet(bulletType: number) {
let bulletNode: Node
if (this.bulletPool[bulletType] && this.bulletPool[bulletType].size() > 0) {
bulletNode = this.bulletPool[bulletType].get()
} else {
bulletNode = instantiate(this.bulletPrefabList[bulletType])
}
bulletNode.getComponent(FishBulletBase).bulletType = bulletType
return bulletNode.getComponent(FishBulletBase)
}
//旋转炮台
CannonManager.instance.rotateCannon(location)
} else {
CommonTips.showMsg('豆子不足!')
}
}
public killBullet(bullet: FishBulletBase) {
let index: number = this.bulletList.indexOf(bullet)
if (index >= 0) {
this.bulletList.splice(index, 1)
this.destroyBullet(bullet)
}
}
private createBullet(bulletType: number) {
let bulletNode: Node
if (this.bulletPool[bulletType] && this.bulletPool[bulletType].size() > 0) {
bulletNode = this.bulletPool[bulletType].get()
} else {
bulletNode = instantiate(this.bulletPrefabList[bulletType])
}
bulletNode.getComponent(FishBulletBase).bulletType = bulletType
return bulletNode.getComponent(FishBulletBase)
}
private destroyBullet(bullet: FishBulletBase) {
//临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
if (sys.platform == 'EDITOR_PAGE') {
bullet.node.destroy()
return
}
public killBullet(bullet: FishBulletBase) {
let index: number = this.bulletList.indexOf(bullet)
if (index >= 0) {
this.bulletList.splice(index, 1)
this.destroyBullet(bullet)
}
}
if (!this.bulletPool[bullet.bulletType]) {
this.bulletPool[bullet.bulletType] = new NodePool()
}
this.bulletPool[bullet.bulletType].put(bullet.node)
}
private destroyBullet(bullet: FishBulletBase) {
//临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
if (sys.platform == 'EDITOR_PAGE') {
bullet.node.destroy()
return
}
onDestroy() {
BulletManager.instance = null
}
if (!this.bulletPool[bullet.bulletType]) {
this.bulletPool[bullet.bulletType] = new NodePool()
}
this.bulletPool[bullet.bulletType].put(bullet.node)
}
onDestroy() {
BulletManager.instance = null
}
}

View File

@@ -1,66 +1,58 @@
import {
_decorator,
Component,
Node,
SpriteFrame,
Event,
EventMouse,
Sprite,
Vec2,
UITransform,
Vec3,
} from 'cc'
const { ccclass, property } = _decorator
import { _decorator, Component, EventMouse, Node, Sprite, SpriteFrame, UITransform, Vec2, Vec3 } from 'cc'
import MathUtils from '../../engine/utils/MathUtils'
const { ccclass, property } = _decorator
@ccclass('CannonManager')
export default class CannonManager extends Component {
public static instance: CannonManager = null
@property({ type: Node })
private view: Node | null = null
@property({ type: [SpriteFrame] })
private cannonSpriteFrame: Array<SpriteFrame> = []
// 炮塔倍数
public cannonType: number = 1
private _vec3Cache
public static instance: CannonManager = null
@property({ type: Node })
private view: Node | null = null
@property({ type: [SpriteFrame] })
private cannonSpriteFrame: Array<SpriteFrame> | [] = []
// 炮塔倍数
public cannonType: number = 1
private _vec3Cache: Vec3
onLoad() {
this._vec3Cache = new Vec3()
CannonManager.instance = this
this.node.parent.on(Node.EventType.MOUSE_MOVE, this.onMeMove.bind(this))
this.refreshCannon()
}
private onMeMove(event: EventMouse) {
this.rotateCannon(event.getUILocation())
}
onLoad() {
this._vec3Cache = new Vec3()
CannonManager.instance = this
this.node.parent.on(Node.EventType.MOUSE_MOVE, this.onMeMove.bind(this))
this.refreshCannon()
}
public rotateCannon(uilocation: Vec2) {
let location = uilocation
this._vec3Cache.x = location.x
this._vec3Cache.y = location.y
this._vec3Cache.z = 0
let tran = this.node.getComponent(UITransform)
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
private onMeMove(event: EventMouse) {
this.rotateCannon(event.getUILocation())
}
let localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
this.view.getPosition(this._vec3Cache)
let rad: number = MathUtils.p2pRad(
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
localTouch
)
let rot: number = MathUtils.radiansToDegrees(rad)
this.view.angle = rot - 90
}
public rotateCannon(uilocation: Vec2) {
let location = uilocation
this._vec3Cache.x = location.x
this._vec3Cache.y = location.y
this._vec3Cache.z = 0
let tran = this.node.getComponent(UITransform)
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
public refreshCannon() {
this.view.getComponent(Sprite).spriteFrame =
this.cannonSpriteFrame[this.cannonType - 1]
}
public getCannonPosition() {
return this.view.getPosition()
}
onDestroy() {
CannonManager.instance = null
}
let localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
this.view.getPosition(this._vec3Cache)
let rad: number = MathUtils.p2pRad(
new Vec2(this._vec3Cache.x, this._vec3Cache.y),
localTouch
)
let rot: number = MathUtils.radiansToDegrees(rad)
this.view.angle = rot - 90
}
public refreshCannon() {
this.view.getComponent(Sprite).spriteFrame =
this.cannonSpriteFrame[this.cannonType - 1]
}
public getCannonPosition() {
return this.view.getPosition()
}
onDestroy() {
CannonManager.instance = null
}
}

View File

@@ -1,21 +1,6 @@
import {
_decorator,
Component,
Node,
Prefab,
NodePool,
game,
Vec3,
sys,
instantiate,
Animation,
Vec2,
} from 'cc'
const { ccclass, property } = _decorator
import { _decorator, Animation, Component, game, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
import RandomUtil from '../../engine/utils/RandomUtil'
import FishBase from '../../../fish/script/FishBase'
import { FishPathInfo } from '../config/FishPathInfo'
import { FishPathConfig } from '../config/FishPathConfig'
import FishMover from '../../../fish/script/FishMover'
import { Logger } from '../../engine/utils/Logger'
@@ -28,195 +13,198 @@ import { FishMapInfo } from '../config/FishMapInfo'
import FishUI from '../../../fish/script/FishUI'
import TimeHelper from '../utils/TimeHelper'
const { ccclass, property } = _decorator
@ccclass('FishManager')
export default class FishManager extends Component {
public static instance: FishManager = null
@property({ type: Node })
private fishContainer: Node | null = null
@property({ type: [Prefab] })
public fishPrefabList: Array<Prefab> = []
private fishPool: Array<NodePool> = []
private fishList: Array<FishBase> = []
private nextRandomFishTime: number = 0
private minRandomTime: number = 2 * (game.frameRate as number)
private maxRandomTime: number = 5 * (game.frameRate as number)
private isFishMap: boolean = false
private mapCount: number = 0
private minMapCount: number = 30 * (game.frameRate as number)
private maxMapCount: number = 60 * (game.frameRate as number)
// // private minMapCount: number = 2 * cc.game.getFrameRate();
// // private maxMapCount: number = 5 * cc.game.getFrameRate();
public static instance: FishManager = null
@property({ type: Node })
private fishContainer: Node | null = null
@property({ type: [Prefab] })
public fishPrefabList: Array<Prefab> = []
private fishPool: Array<NodePool> = []
private fishList: Array<FishBase> = []
private nextRandomFishTime: number = 0
private minRandomTime: number = 2 * (game.frameRate as number)
private maxRandomTime: number = 5 * (game.frameRate as number)
private isFishMap: boolean = false
private mapCount: number = 0
private minMapCount: number = 30 * (game.frameRate as number)
private maxMapCount: number = 60 * (game.frameRate as number)
// // private minMapCount: number = 2 * cc.game.getFrameRate();
// // private maxMapCount: number = 5 * cc.game.getFrameRate();
private _fishPosCache
onLoad() {
FishManager.instance = this
this._fishPosCache = new Vec3()
Logger.log(
'maxRandomTime=',
this.minRandomTime,
this.maxRandomTime,
game.frameRate
)
}
private _fishPosCache: Vec3
start() {
this.randomFish()
}
onLoad() {
FishManager.instance = this
this._fishPosCache = new Vec3()
Logger.log(
'maxRandomTime=',
this.minRandomTime,
this.maxRandomTime,
game.frameRate
)
}
update() {
this.checkRandomFish()
this.checkFishMoveEnd()
this.checkFishMap()
}
start() {
this.randomFish()
}
private checkFishMap() {
if (!this.isFishMap) {
if (this.mapCount > 0) {
this.mapCount--
if (this.mapCount <= 0) {
FishUI.instance.playWaveEffect()
}
}
}
}
update() {
this.checkRandomFish()
this.checkFishMoveEnd()
this.checkFishMap()
}
private checkRandomFish() {
if (!this.isFishMap) {
if (this.nextRandomFishTime > 0) {
this.nextRandomFishTime--
if (this.nextRandomFishTime == 0) {
this.randomFish()
}
}
}
}
private checkFishMap() {
if (!this.isFishMap) {
if (this.mapCount > 0) {
this.mapCount--
if (this.mapCount <= 0) {
FishUI.instance.playWaveEffect()
}
}
}
}
private checkFishMoveEnd() {
for (let i = this.fishList.length - 1; i >= 0; i--) {
let fish: FishBase = this.fishList[i]
if (this.isFishMap) {
if (!fish.isDead) {
fish.node.getPosition(this._fishPosCache)
this._fishPosCache.x -= 2
fish.node.setPosition(this._fishPosCache)
if (this._fishPosCache.x <= -screen.width / 2) {
//winSize.width
this.destroyFish(fish)
this.fishList.splice(i, 1)
this.checkEndFishMap()
}
}
} else if (!fish.getComponent(FishMover).isMoving) {
this.destroyFish(fish)
this.fishList.splice(i, 1)
}
}
}
private checkRandomFish() {
if (!this.isFishMap) {
if (this.nextRandomFishTime > 0) {
this.nextRandomFishTime--
if (this.nextRandomFishTime == 0) {
this.randomFish()
}
}
}
}
private checkEndFishMap() {
Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
if (this.isFishMap && this.fishList.length <= 0) {
this.isFishMap = false
this.randomFish()
}
}
private checkFishMoveEnd() {
for (let i = this.fishList.length - 1; i >= 0; i--) {
let fish: FishBase = this.fishList[i]
if (this.isFishMap) {
if (!fish.isDead) {
fish.node.getPosition(this._fishPosCache)
this._fishPosCache.x -= 2
fish.node.setPosition(this._fishPosCache)
if (this._fishPosCache.x <= -screen.width / 2) {
//winSize.width
this.destroyFish(fish)
this.fishList.splice(i, 1)
this.checkEndFishMap()
}
}
} else if (!fish.getComponent(FishMover).isMoving) {
this.destroyFish(fish)
this.fishList.splice(i, 1)
}
}
}
private randomFish() {
if (this.isFishMap) return
let randomNum: number = RandomUtil.nextInt(1, 10)
// let randomNum: number = RandomUtil.nextInt(1, 1);
for (let i = 0; i < randomNum; i++) {
let fishType: number = RandomUtil.nextInt(1, 29)
// let fishType: number = RandomUtil.nextInt(1, 1);
let fish: FishBase = this.createFishByType(fishType)
fish.fishPathInfo = FishPathConfig.randomPathInfo()
this._fishPosCache.z = 0
this._fishPosCache.x = fish.fishPathInfo.path[0].x
this._fishPosCache.y = fish.fishPathInfo.path[0].y
fish.node.setPosition(this._fishPosCache)
fish.getComponent(FishMover).bezierPList = fish.fishPathInfo.path
fish.getComponent(FishMover).startMove()
this.fishList.push(fish)
this.fishContainer.addChild(fish.node)
}
Logger.log('checkFishMoveEnd=randomFish=', this.fishList)
this.nextRandomFishTime = RandomUtil.nextInt(
this.minRandomTime,
this.maxRandomTime
)
if (this.mapCount <= 0) {
this.mapCount = RandomUtil.nextInt(this.minMapCount, this.maxMapCount)
}
}
private checkEndFishMap() {
Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
if (this.isFishMap && this.fishList.length <= 0) {
this.isFishMap = false
this.randomFish()
}
}
public createFishByType(fishType: number): FishBase {
let fishNode: Node
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
fishNode = this.fishPool[fishType - 1].get()
} else {
fishNode = instantiate(this.fishPrefabList[fishType - 1])
}
//fishNode.getComponent(Animation).play() //v3 当前帧 不能播放
TimeHelper.exeNextFrame(fishNode, () =>
fishNode.getComponent(Animation).play()
)
let fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
fishNode.getComponent(FishBase).fishInfo = fishInfo
fishNode.getComponent(FishBase).fishType = fishType
fishNode.getComponent(FishBase).blood = fishInfo.blood
fishNode.getComponent(FishBase).isDead = false
return fishNode.getComponent(FishBase)
}
private randomFish() {
if (this.isFishMap) return
let randomNum: number = RandomUtil.nextInt(1, 10)
// let randomNum: number = RandomUtil.nextInt(1, 1);
for (let i = 0; i < randomNum; i++) {
let fishType: number = RandomUtil.nextInt(1, 29)
// let fishType: number = RandomUtil.nextInt(1, 1);
let fish: FishBase = this.createFishByType(fishType)
fish.fishPathInfo = FishPathConfig.randomPathInfo()
this._fishPosCache.z = 0
this._fishPosCache.x = fish.fishPathInfo.path[0].x
this._fishPosCache.y = fish.fishPathInfo.path[0].y
fish.node.setPosition(this._fishPosCache)
fish.getComponent(FishMover).bezierPList = fish.fishPathInfo.path
fish.getComponent(FishMover).startMove()
this.fishList.push(fish)
this.fishContainer.addChild(fish.node)
}
Logger.log('checkFishMoveEnd=randomFish=', this.fishList)
this.nextRandomFishTime = RandomUtil.nextInt(
this.minRandomTime,
this.maxRandomTime
)
if (this.mapCount <= 0) {
this.mapCount = RandomUtil.nextInt(this.minMapCount, this.maxMapCount)
}
}
public killFish(fish: FishBase) {
let index: number = this.fishList.indexOf(fish)
if (index >= 0) {
// console.log("鱼挂了")
GameMusicHelper.playFishDead(fish.fishType)
fish.node.getPosition(this._fishPosCache)
let vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
ScoreManager.instance.addScore(fish.fishInfo.blood, vec2)
this.fishList.splice(index, 1)
this.destroyFish(fish)
this.checkEndFishMap()
}
}
public createFishByType(fishType: number): FishBase {
let fishNode: Node
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
fishNode = this.fishPool[fishType - 1].get()
} else {
fishNode = instantiate(this.fishPrefabList[fishType - 1])
}
//fishNode.getComponent(Animation).play() //v3 当前帧 不能播放
TimeHelper.exeNextFrame(fishNode, () =>
fishNode.getComponent(Animation).play()
)
let fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
fishNode.getComponent(FishBase).fishInfo = fishInfo
fishNode.getComponent(FishBase).fishType = fishType
fishNode.getComponent(FishBase).blood = fishInfo.blood
fishNode.getComponent(FishBase).isDead = false
return fishNode.getComponent(FishBase)
}
private destroyFish(fish: FishBase) {
if (!this.fishPool[fish.fishType - 1]) {
this.fishPool[fish.fishType - 1] = new NodePool()
}
this.fishPool[fish.fishType - 1].put(fish.node)
}
public killFish(fish: FishBase) {
let index: number = this.fishList.indexOf(fish)
if (index >= 0) {
// console.log("鱼挂了")
GameMusicHelper.playFishDead(fish.fishType)
fish.node.getPosition(this._fishPosCache)
let vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
ScoreManager.instance.addScore(fish.fishInfo.blood, vec2)
this.fishList.splice(index, 1)
this.destroyFish(fish)
this.checkEndFishMap()
}
}
public playFishMap() {
this.isFishMap = true
for (let i = this.fishList.length - 1; i >= 0; i--) {
let fish: FishBase = this.fishList[i]
this.destroyFish(fish)
this.fishList.splice(i, 1)
}
}
private destroyFish(fish: FishBase) {
if (!this.fishPool[fish.fishType - 1]) {
this.fishPool[fish.fishType - 1] = new NodePool()
}
this.fishPool[fish.fishType - 1].put(fish.node)
}
public startFishMap() {
// this.playFishMap();
// this.fishList = [];
public playFishMap() {
this.isFishMap = true
for (let i = this.fishList.length - 1; i >= 0; i--) {
let fish: FishBase = this.fishList[i]
this.destroyFish(fish)
this.fishList.splice(i, 1)
}
}
let map: FishMap = FishPathConfig.randomFishMap()
let fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
for (let i = 0; i < fishMapInfoList.length; i++) {
let fishMapInfo: FishMapInfo = fishMapInfoList[i]
let fish: FishBase = this.createFishByType(fishMapInfo.fishType)
fish.node.angle = 0
// fish.node.setScale(fishMapInfo.scale);
this.fishContainer.addChild(fish.node)
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
this.fishList.push(fish)
}
}
public startFishMap() {
// this.playFishMap();
// this.fishList = [];
onDestroy() {
FishManager.instance = null
}
let map: FishMap = FishPathConfig.randomFishMap()
let fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
for (let i = 0; i < fishMapInfoList.length; i++) {
let fishMapInfo: FishMapInfo = fishMapInfoList[i]
let fish: FishBase = this.createFishByType(fishMapInfo.fishType)
fish.node.angle = 0
// fish.node.setScale(fishMapInfo.scale);
this.fishContainer.addChild(fish.node)
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
this.fishList.push(fish)
}
}
onDestroy() {
FishManager.instance = null
}
}

View File

@@ -1,53 +1,45 @@
import {
_decorator,
Component,
Prefab,
NodePool,
Vec2,
instantiate,
Vec3,
Node,
} from 'cc'
const { ccclass, property } = _decorator
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
import FishNetBase from '../../../fish/script/FishNetBase'
const { ccclass, property } = _decorator
@ccclass('FishNetManager')
export default class FishNetManager extends Component {
public static instance: FishNetManager = null
@property({ type: [Prefab] })
private netPrefabList: Prefab[] = []
private fishNetPool: Array<NodePool> = []
onLoad() {
FishNetManager.instance = this
}
public static instance: FishNetManager = null
@property({ type: [Prefab] })
private netPrefabList: Prefab[] | [] = []
private fishNetPool: Array<NodePool> = []
public addFishNet(netType: number, p: Vec2) {
let fishNet: FishNetBase = this.createFishNet(netType)
this.node.addChild(fishNet.node)
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
fishNet.playMv()
}
onLoad() {
FishNetManager.instance = this
}
private createFishNet(netType: number) {
let fishNetNode: Node
if (this.fishNetPool[netType] && this.fishNetPool[netType].size() > 0) {
fishNetNode = this.fishNetPool[netType].get()
} else {
fishNetNode = instantiate(this.netPrefabList[netType])
}
fishNetNode.getComponent(FishNetBase).netType = netType
return fishNetNode.getComponent(FishNetBase)
}
public addFishNet(netType: number, p: Vec2) {
let fishNet: FishNetBase = this.createFishNet(netType)
this.node.addChild(fishNet.node)
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
fishNet.playMv()
}
public destroyFishNet(fishNet: FishNetBase) {
if (!this.fishNetPool[fishNet.netType]) {
this.fishNetPool[fishNet.netType] = new NodePool()
}
this.fishNetPool[fishNet.netType].put(fishNet.node)
}
private createFishNet(netType: number) {
let fishNetNode: Node
if (this.fishNetPool[netType] && this.fishNetPool[netType].size() > 0) {
fishNetNode = this.fishNetPool[netType].get()
} else {
fishNetNode = instantiate(this.netPrefabList[netType])
}
fishNetNode.getComponent(FishNetBase).netType = netType
return fishNetNode.getComponent(FishNetBase)
}
onDestroy() {
FishNetManager.instance = null
}
public destroyFishNet(fishNet: FishNetBase) {
if (!this.fishNetPool[fishNet.netType]) {
this.fishNetPool[fishNet.netType] = new NodePool()
}
this.fishNetPool[fishNet.netType].put(fishNet.node)
}
onDestroy() {
FishNetManager.instance = null
}
}

View File

@@ -1,57 +1,51 @@
import {
_decorator,
Component,
Prefab,
NodePool,
Vec2,
instantiate,
Node,
Vec3,
} from 'cc'
const { ccclass, property } = _decorator
import { _decorator, Component, instantiate, Node, NodePool, Prefab, Vec2, Vec3 } from 'cc'
import ScorePrefab from '../prefab/ScorePrefab'
import FishUI from '../../../fish/script/FishUI'
const { ccclass, property } = _decorator
@ccclass('ScoreManager')
export default class ScoreManager extends Component {
public static instance: ScoreManager = null
@property({ type: Prefab })
private scrorePrefab: Prefab | null = null
private scorePool: NodePool
onLoad() {
ScoreManager.instance = this
this.scorePool = new NodePool()
}
public static instance: ScoreManager = null
@property({ type: Prefab })
private scrorePrefab: Prefab | null = null
private scorePool: NodePool
public addScore(score: number, p: Vec2) {
let scorePrefab: ScorePrefab = this.createScore(score)
this.node.addChild(scorePrefab.node)
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
scorePrefab.init(score)
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
this.destroyScore(scorePrefab)
FishUI.instance.jf_score += score
FishUI.instance.refreshScore()
})
}
onLoad() {
ScoreManager.instance = this
this.scorePool = new NodePool()
}
private createScore(score: number): ScorePrefab {
let scoreNode: Node
if (this.scorePool && this.scorePool.size() > 0) {
scoreNode = this.scorePool.get()
} else {
scoreNode = instantiate(this.scrorePrefab)
}
return scoreNode.getComponent(ScorePrefab)
}
public addScore(score: number, p: Vec2) {
let scorePrefab: ScorePrefab = this.createScore(score)
this.node.addChild(scorePrefab.node)
scorePrefab.node.setPosition(new Vec3(p.x, p.y, 0))
scorePrefab.init(score)
scorePrefab.playMoveEffect(new Vec2(-472.398, -547.481), () => {
this.destroyScore(scorePrefab)
FishUI.instance.jf_score += score
FishUI.instance.refreshScore()
})
}
private destroyScore(scorePrefab: ScorePrefab) {
this.scorePool.put(scorePrefab.node)
}
private createScore(score: number): ScorePrefab {
let scoreNode: Node
if (this.scorePool && this.scorePool.size() > 0) {
scoreNode = this.scorePool.get()
} else {
scoreNode = instantiate(this.scrorePrefab)
}
return scoreNode.getComponent(ScorePrefab)
}
onDisable() {}
onDestroy() {
ScoreManager.instance = null
}
private destroyScore(scorePrefab: ScorePrefab) {
this.scorePool.put(scorePrefab.node)
}
onDisable() {
}
onDestroy() {
ScoreManager.instance = null
}
}

View File

@@ -1,9 +1,9 @@
import { _decorator, Component, Prefab, Node, instantiate } from 'cc'
const { ccclass, property } = _decorator
import { _decorator, Component, instantiate, Node, Prefab } from 'cc'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { GameConfig } from '../config/GameConfig'
const { ccclass, property } = _decorator
@ccclass('ResourcePrefab')
export default class ResourcePrefab extends Component {
private static prefab: Prefab | null = null

View File

@@ -1,4 +1,5 @@
import { _decorator, Component, Label, Vec2, tween, Vec3, Tween } from 'cc'
import { _decorator, Component, Label, tween, Tween, Vec2, Vec3 } from 'cc'
const { ccclass, property } = _decorator
@ccclass('ScorePrefab')

View File

@@ -1,41 +1,42 @@
import { _decorator, Component, Node, Material, instantiate, Prefab } from 'cc'
const { ccclass, property } = _decorator
import { _decorator, Component, instantiate, Material, Node, Prefab } from 'cc'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { GameConfig } from '../config/GameConfig'
const { ccclass, property } = _decorator
@ccclass('ShaderMaterialPrefab')
export default class ShaderMaterialPrefab extends Component {
public static instance: Node
public static instance: Node
@property({ type: Material })
public default: Material | null = null
@property({ type: Material })
public default: Material | null = null
@property({ type: Material })
public grayMaterial: Material | null = null
@property({ type: Material })
public oldPhoto: Material | null = null
@property({ type: Material })
public glowInner: Material | null = null
@property({ type: Material })
public mosaic: Material | null = null
@property({ type: Material })
public roundCornerCrop: Material | null = null
@property({ type: Material })
public flashLight: Material | null = null
@property({ type: Material })
public flag: Material | null = null
@property({ type: Material })
public gaussian: Material | null = null
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'game/prefab/ShaderMaterialPrefab',
(loadedResource: Prefab) => {
ShaderMaterialPrefab.instance = instantiate(loadedResource)
resolve()
}
)
})
}
@property({ type: Material })
public grayMaterial: Material | null = null
@property({ type: Material })
public oldPhoto: Material | null = null
@property({ type: Material })
public glowInner: Material | null = null
@property({ type: Material })
public mosaic: Material | null = null
@property({ type: Material })
public roundCornerCrop: Material | null = null
@property({ type: Material })
public flashLight: Material | null = null
@property({ type: Material })
public flag: Material | null = null
@property({ type: Material })
public gaussian: Material | null = null
public static preLoad(): Promise<void> {
return new Promise((resolve, reject) => {
PrefabLoader.loadPrefab(
GameConfig.GameName + '/' + 'game/prefab/ShaderMaterialPrefab',
(loadedResource: Prefab) => {
ShaderMaterialPrefab.instance = instantiate(loadedResource)
resolve()
}
)
})
}
}

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)
}
}

View File

@@ -1,13 +1,4 @@
import {
_decorator,
Node,
sys,
profiler,
DynamicAtlasManager,
PhysicsSystem2D,
} from 'cc'
const { ccclass, property } = _decorator
import { _decorator, DynamicAtlasManager, Node, PhysicsSystem2D, profiler, sys } from 'cc'
import MusicConfig from '../../engine/config/MusicConfig'
import CommonTips from '../../engine/uicomponent/CommonTips'
import Progress from '../../engine/uicomponent/Progress'
@@ -19,138 +10,141 @@ import ResourcePreload from '../utils/ResourcePreload'
import SceneBase from './SceneBase'
import SceneManager from './SceneManager'
const { ccclass, property } = _decorator
@ccclass('LoadingScene')
export default class LoadingScene extends SceneBase {
public static scriptName: string = 'LoadingScene'
@property({ type: Node })
private progressNode: Node | null = null
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()
}
}
public static scriptName: string = 'LoadingScene'
@property({ type: Node })
private progressNode: Node | null = null
private baseInit() {
profiler.hideStats() //showStats
//let collisionManager:cc.CollisionManager = director.getCollisionManager();
PhysicsSystem2D.instance.enable = true
async 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 {
await this.preLoadRes()
}
}
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
// EPhysics2DDrawFlags.Pair |
// EPhysics2DDrawFlags.CenterOfMass |
// EPhysics2DDrawFlags.Joint |
// EPhysics2DDrawFlags.Shape;
private baseInit() {
profiler.hideStats() //showStats
//let collisionManager:cc.CollisionManager = director.getCollisionManager();
PhysicsSystem2D.instance.enable = true
//if(collisionManager){
//collisionManager.enabled = true;
// collisionManager.enabledDebugDraw = true;
// collisionManager.enabledDrawBoundingBox = true;
//}
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
// EPhysics2DDrawFlags.Pair |
// EPhysics2DDrawFlags.CenterOfMass |
// EPhysics2DDrawFlags.Joint |
// EPhysics2DDrawFlags.Shape;
if (DynamicAtlasManager.instance) {
DynamicAtlasManager.instance.enabled = false
}
MusicConfig.init()
// cc.director.getCollisionManager().enabled=true;//这是一个全局属性,开启后就代表碰撞检测组件可以进行检测了
// cc.director.getCollisionManager().enabledDebugDraw = true; //绘制碰撞区域
}
//if(collisionManager){
//collisionManager.enabled = true;
// collisionManager.enabledDebugDraw = true;
// collisionManager.enabledDrawBoundingBox = true;
//}
private checkUpdate() {
Logger.log(this, 'checkUpdate====')
VersionManager.instance.checkUpdate(0)
}
if (DynamicAtlasManager.instance) {
DynamicAtlasManager.instance.enabled = false
}
MusicConfig.init()
// cc.director.getCollisionManager().enabled=true;//这是一个全局属性,开启后就代表碰撞检测组件可以进行检测了
// cc.director.getCollisionManager().enabledDebugDraw = true; //绘制碰撞区域
}
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 checkUpdate() {
Logger.log(this, 'checkUpdate====')
VersionManager.instance.checkUpdate(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 onNeedUpdate(event: HaoEvent, key: string) {
Logger.log(this, 'onNeedUpdate=====', key, VersionManager.Config_Key)
if (key == VersionManager.Config_Key[0]) {
VersionManager.instance.startUpdate(0)
}
}
private onUpdateFail(event, key: string) {
if (key == VersionManager.Config_Key[0]) {
Logger.warn(this, '热更新失败========')
CommonTips.showMsg('热更新失败')
ResourcePreload.instance.restartGame()
}
}
private onUpdateProgress(event: Function, loadedFiles: number, totalFiles: number, key: string) {
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 onUpdateFinish(event, key: string, needRestart: boolean) {
Logger.log(this, 'onUpdateFinish========')
if (key == VersionManager.Config_Key[0] && !needRestart) {
this.preLoadRes()
}
}
private onUpdateFail(event, key: string) {
if (key == VersionManager.Config_Key[0]) {
Logger.warn(this, '热更新失败========')
CommonTips.showMsg('热更新失败')
ResourcePreload.instance.restartGame()
}
}
private async preLoadRes() {
ResourcePreload.instance.preLoad(() => {
this.startGame()
}, this.progressNode.getComponent(Progress))
}
private onUpdateFinish(event, key: string, needRestart: boolean) {
Logger.log(this, 'onUpdateFinish========')
if (key == VersionManager.Config_Key[0] && !needRestart) {
this.preLoadRes()
}
}
private startGame() {
Logger.info(this, 'startGame')
SceneManager.instance.sceneSwitch('FishGameScene', true)
}
private async preLoadRes() {
ResourcePreload.instance.preLoad(() => {
this.startGame()
}, this.progressNode.getComponent(Progress))
}
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
)
}
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
)
}
}

View File

@@ -1,25 +1,31 @@
import { _decorator, Component } from 'cc'
const { ccclass, property } = _decorator
import AdapterHelper from '../../engine/utils/AdapterHelper'
import PrefabLoader from '../../engine/utils/PrefabLoader'
import { Logger } from '../../engine/utils/Logger'
import ResourcePrefab from '../prefab/ResourcePrefab'
const { ccclass, property } = _decorator
@ccclass('SceneBase')
export default class SceneBase extends Component {
public static scriptName: string = 'SceneBase'
onLoad() {
AdapterHelper.fixApdater()
this.onLoadMe()
}
onLoadMe() {}
start() {
this.onStartMe()
}
onStartMe() {}
onDestroy() {
this.onDestroyMe()
}
onDestroyMe() {}
public static scriptName: string = 'SceneBase'
onLoad() {
AdapterHelper.fixApdater()
this.onLoadMe()
}
onLoadMe() {
}
start() {
this.onStartMe()
}
onStartMe() {
}
onDestroy() {
this.onDestroyMe()
}
onDestroyMe() {
}
}

View File

@@ -1,4 +1,4 @@
import { director, SceneAsset, sys, _decorator } from 'cc'
import { director, SceneAsset, sys } from 'cc'
import { Logger } from '../../engine/utils/Logger'
import LoadingScenePrefab from '../../engine/uicomponent/LoadingScenePrefab'
import CommonTips from '../../engine/uicomponent/CommonTips'
@@ -6,67 +6,67 @@ import EventManager from '../../engine/utils/EventManager'
import CommonEvent from '../../engine/config/CommonEvent'
export default class SceneManager {
public static instance: SceneManager = new SceneManager()
public static instance: SceneManager = new SceneManager()
private loadingSceneName: string
private loadingSceneName: string
public currentSceneName: string
public currentSceneName: string
public initFullScreenPrefab(isShow: boolean = false) {
if (sys.isBrowser && !sys.isMobile) {
if (isShow) {
// FullscreenPrefab.show();
} else {
// FullscreenPrefab.close();
}
}
}
public initFullScreenPrefab(isShow: boolean = false) {
if (sys.isBrowser && !sys.isMobile) {
if (isShow) {
// FullscreenPrefab.show();
} else {
// FullscreenPrefab.close();
}
}
}
public 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) {
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))
}
}
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)
}
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)
}
public preloadScene(
sceneName: string,
onProgressCallback: any = null,
onLoadedCallback: any = null
) {
director.preloadScene(sceneName, onProgressCallback, onLoadedCallback)
}
}

View File

@@ -1,15 +1,18 @@
import { _decorator } from 'cc'
const { ccclass, property } = _decorator
import EventManager, { HaoEvent } from '../../engine/utils/EventManager'
import SceneBase from './SceneBase'
import SceneManager from './SceneManager'
const { ccclass, property } = _decorator
@ccclass('StartScene')
export default class StartScene extends SceneBase {
public static scriptName: string = 'StartScene'
onLoadMe() {}
update() {}
public static scriptName: string = 'StartScene'
onDestroyMe() {}
onLoadMe() {
}
update() {
}
onDestroyMe() {
}
}

View File

@@ -1,196 +1,200 @@
import { _decorator, Component, Vec2 } from 'cc'
const { ccclass, property } = _decorator
import { Logger } from '../../engine/utils/Logger'
export enum AstarGridType {
Hider = 0, //不能走
Normal = 1, //能走
End = 2, //终点
Hider = 0, //不能走
Normal = 1, //能走
End = 2, //终点
}
@ccclass('Astar')
export class AstarGrid {
public x: number = 0
public y: number = 0
public f: number = 0
public g: number = 0
public h: number = 0
public type: number = 0
public parent: AstarGrid = null
public x: number = 0
public y: number = 0
public f: number = 0
public g: number = 0
public h: number = 0
public type: number = 0
public parent: AstarGrid = null
}
export class Astar extends Component {
public mapW: number = 24 // 横向格子数量
public mapH: number = 13 // 纵向格子数量
public is8dir: boolean = false // 是否8方向寻路 //4方向:代表只能走上下左右 8方向:代表可以走上下左右,左上,右上,左下,右下
private openList: Array<AstarGrid> = []
private closeList: Array<AstarGrid> = []
private path: Array<AstarGrid> = []
private gridsList: Array<Array<AstarGrid>> = []
onLoad() {}
public mapW: number = 24 // 横向格子数量
public mapH: number = 13 // 纵向格子数量
public is8dir: boolean = false // 是否8方向寻路 //4方向:代表只能走上下左右 8方向:代表可以走上下左右,左上,右上,左下,右下
private openList: Array<AstarGrid> = []
private closeList: Array<AstarGrid> = []
private path: Array<AstarGrid> = []
private gridsList: Array<Array<AstarGrid>> = []
/**
* @param mapW 宽格子数
* @param mapH 高格子数
* @param is8dir 是8方向(上,下,左,右,左上,右上,左下,右下)寻路还是4方向(上,下,左,右)
*/
public init(mapW: number, mapH: number, is8dir: boolean = false) {
this.mapW = mapW
this.mapH = mapH
this.is8dir = is8dir
this.initMap()
}
onLoad() {
}
/**
* 初始化map的格子
*/
private initMap() {
this.openList = []
this.closeList = []
this.path = []
// 初始化格子二维数组
this.gridsList = new Array(this.mapW + 1)
for (let col = 0; col < this.gridsList.length; col++) {
this.gridsList[col] = new Array(this.mapH + 1)
}
for (let col = 0; col <= this.mapW; col++) {
for (let row = 0; row <= this.mapH; row++) {
this.addGrid(col, row, AstarGridType.Normal)
}
}
}
/**
* @param mapW 宽格子
* @param mapH 高格子数
* @param is8dir 是8方向(上,下,左,右,左上,右上,左下,右下)寻路还是4方向(上,下,左,右)
*/
public init(mapW: number, mapH: number, is8dir: boolean = false) {
this.mapW = mapW
this.mapH = mapH
this.is8dir = is8dir
this.initMap()
}
/**
* 创建一个格子到地图
* @param x
* @param y
* @param type
*/
private addGrid(x: number, y: number, type: number = AstarGridType.Hider) {
let grid = new AstarGrid()
grid.x = x
grid.y = y
grid.type = type
this.gridsList[x][y] = grid
}
/**
* 初始化map的格子
*/
private initMap() {
this.openList = []
this.closeList = []
this.path = []
// 初始化格子二维数组
this.gridsList = new Array(this.mapW + 1)
for (let col = 0; col < this.gridsList.length; col++) {
this.gridsList[col] = new Array(this.mapH + 1)
}
for (let col = 0; col <= this.mapW; col++) {
for (let row = 0; row <= this.mapH; row++) {
this.addGrid(col, row, AstarGridType.Normal)
}
}
}
/**
* 设置格子类型
* @param x
* @param y
* @param type
*/
public setGridType(x: number, y: number, type: number) {
let curGrid: AstarGrid = this.gridsList[x][y]
curGrid.type = type
}
/**
* 创建一个格子到地图
* @param x
* @param y
* @param type
*/
private addGrid(x: number, y: number, type: number = AstarGridType.Hider) {
let grid = new AstarGrid()
grid.x = x
grid.y = y
grid.type = type
this.gridsList[x][y] = grid
}
/**
* 开始搜索路径
* @param startPos
* @param endPos
*/
public findPath(startPos: Vec2, endPos: Vec2, callback: Function = null) {
let startGrid = this.gridsList[startPos.x][startPos.y]
this.openList.push(startGrid)
let curGrid: AstarGrid = this.openList[0]
while (this.openList.length > 0 && curGrid.type != AstarGridType.End) {
// 每次都取出f值最小的节点进行查找
curGrid = this.openList[0]
if (curGrid.type == AstarGridType.End) {
// Logger.log(this,"find path success.");
this.generatePath(curGrid)
if (callback) {
callback(this.path)
}
return
}
/**
* 设置格子类型
* @param x
* @param y
* @param type
*/
public setGridType(x: number, y: number, type: number) {
let curGrid: AstarGrid = this.gridsList[x][y]
curGrid.type = type
}
for (let i: number = -1; i <= 1; i++) {
for (let j: number = -1; j <= 1; j++) {
if (i != 0 || j != 0) {
let col = curGrid.x + i
let row = curGrid.y + j
if (
col >= 0 &&
row >= 0 &&
col <= this.mapW &&
row <= this.mapH &&
this.gridsList[col][row].type != AstarGridType.Hider &&
this.closeList.indexOf(this.gridsList[col][row]) < 0
) {
if (this.is8dir) {
// 8方向 斜向走动时要考虑相邻的是不是障碍物
if (
this.gridsList[col - i][row].type == AstarGridType.Hider ||
this.gridsList[col][row - j].type == AstarGridType.Hider
) {
continue
}
} else {
// 四方形行走
if (Math.abs(i) == Math.abs(j)) {
continue
}
}
// 计算g值
let g =
curGrid.g +
Math.floor(Math.sqrt(Math.pow(i * 10, 2)) + Math.pow(j * 10, 2))
if (
this.gridsList[col][row].g == 0 ||
this.gridsList[col][row].g > g
) {
this.gridsList[col][row].g = g
// 更新父节点
this.gridsList[col][row].parent = curGrid
}
// 计算h值 manhattan估算法
this.gridsList[col][row].h =
Math.abs(endPos.x - col) + Math.abs(endPos.y - row)
// 更新f值
this.gridsList[col][row].f =
this.gridsList[col][row].g + this.gridsList[col][row].h
// 如果不在开放列表里则添加到开放列表里
if (this.openList.indexOf(this.gridsList[col][row]) < 0) {
this.openList.push(this.gridsList[col][row])
}
// // 重新按照f值排序升序排列)
}
}
}
}
// 遍历完四周节点后把当前节点加入关闭列表
this.closeList.push(curGrid)
// 从开放列表把当前节点移除
this.openList.splice(this.openList.indexOf(curGrid), 1)
if (this.openList.length <= 0) {
// Logger.log(this,"find path failed.");
this.path = []
if (callback) {
callback(this.path)
}
break
}
// 重新按照f值排序升序排列)
this.openList.sort((x, y) => {
return x.f - y.f
})
}
}
/**
* 开始搜索路径
* @param startPos
* @param endPos
* @param callback
*/
public findPath(startPos: Vec2, endPos: Vec2, callback: Function = null) {
let startGrid = this.gridsList[startPos.x][startPos.y]
this.openList.push(startGrid)
let curGrid: AstarGrid = this.openList[0]
while (this.openList.length > 0 && curGrid.type != AstarGridType.End) {
// 每次都取出f值最小的节点进行查找
curGrid = this.openList[0]
if (curGrid.type == AstarGridType.End) {
// Logger.log(this,"find path success.");
this.generatePath(curGrid)
if (callback) {
callback(this.path)
}
return
}
/**
* 生成路径
* @param grid
*/
private generatePath(grid: AstarGrid) {
this.path.push(grid)
while (grid.parent) {
grid = grid.parent
this.path.push(grid)
}
return this.path
}
for (let i: number = -1; i <= 1; i++) {
for (let j: number = -1; j <= 1; j++) {
if (i != 0 || j != 0) {
let col = curGrid.x + i
let row = curGrid.y + j
if (
col >= 0 &&
row >= 0 &&
col <= this.mapW &&
row <= this.mapH &&
this.gridsList[col][row].type != AstarGridType.Hider &&
this.closeList.indexOf(this.gridsList[col][row]) < 0
) {
if (this.is8dir) {
// 8方向 斜向走动时要考虑相邻的是不是障碍物
if (
this.gridsList[col - i][row].type == AstarGridType.Hider ||
this.gridsList[col][row - j].type == AstarGridType.Hider
) {
continue
}
} else {
// 四方形行走
if (Math.abs(i) == Math.abs(j)) {
continue
}
}
// 计算g值
let g =
curGrid.g +
Math.floor(Math.sqrt(Math.pow(i * 10, 2)) + Math.pow(j * 10, 2))
if (
this.gridsList[col][row].g == 0 ||
this.gridsList[col][row].g > g
) {
this.gridsList[col][row].g = g
// 更新父节点
this.gridsList[col][row].parent = curGrid
}
// 计算h值 manhattan估算法
this.gridsList[col][row].h =
Math.abs(endPos.x - col) + Math.abs(endPos.y - row)
// 更新f值
this.gridsList[col][row].f =
this.gridsList[col][row].g + this.gridsList[col][row].h
// 如果不在开放列表里则添加到开放列表里
if (this.openList.indexOf(this.gridsList[col][row]) < 0) {
this.openList.push(this.gridsList[col][row])
}
// // 重新按照f值排序升序排列)
}
}
}
}
// 遍历完四周节点后把当前节点加入关闭列表
this.closeList.push(curGrid)
// 从开放列表把当前节点移除
this.openList.splice(this.openList.indexOf(curGrid), 1)
if (this.openList.length <= 0) {
// Logger.log(this,"find path failed.");
this.path = []
if (callback) {
callback(this.path)
}
break
}
// 重新按照f值排序升序排列)
this.openList.sort((x, y) => {
return x.f - y.f
})
}
}
onDestroy() {}
/**
* 生成路径
* @param grid
*/
private generatePath(grid: AstarGrid) {
this.path.push(grid)
while (grid.parent) {
grid = grid.parent
this.path.push(grid)
}
return this.path
}
onDestroy() {
}
}

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
}