优化若干代码
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"image": {
|
||||
"type": "sprite-frame"
|
||||
"type": "texture"
|
||||
}
|
||||
}
|
||||
|
||||
5
.editorconfig
Normal file
5
.editorconfig
Normal file
@@ -0,0 +1,5 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
11
.eslintignore
Normal file
11
.eslintignore
Normal file
@@ -0,0 +1,11 @@
|
||||
.creator
|
||||
.idea
|
||||
.vscode
|
||||
.git
|
||||
.DS_Store
|
||||
/node_modules
|
||||
/build
|
||||
/temp
|
||||
/library
|
||||
/profiles
|
||||
/settings
|
||||
11
.prettierignore
Normal file
11
.prettierignore
Normal file
@@ -0,0 +1,11 @@
|
||||
.creator
|
||||
.idea
|
||||
.vscode
|
||||
.git
|
||||
.DS_Store
|
||||
/node_modules
|
||||
/build
|
||||
/temp
|
||||
/library
|
||||
/profiles
|
||||
/settings
|
||||
6
.prettierrc.json
Normal file
6
.prettierrc.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"printWidth": 100,
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
@@ -1,162 +1,164 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
CCInteger,
|
||||
CCFloat,
|
||||
Vec2,
|
||||
Animation,
|
||||
Vec3,
|
||||
_decorator,
|
||||
Component,
|
||||
CCInteger,
|
||||
CCFloat,
|
||||
Vec2,
|
||||
Animation,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
const {ccclass, property} = _decorator
|
||||
|
||||
import FishBase from './FishBase'
|
||||
import MathUtils from '../../script/engine/utils/MathUtils'
|
||||
import { Logger } from '../../script/engine/utils/Logger'
|
||||
import {Logger} from '../../script/engine/utils/Logger'
|
||||
import TimeHelper from '../../script/game/utils/TimeHelper'
|
||||
|
||||
@ccclass('FishMover')
|
||||
export default class FishMover extends Component {
|
||||
// //鱼类型
|
||||
@property({ type: CCInteger })
|
||||
public fishType: number = 1
|
||||
// //鱼移动速度
|
||||
@property({ type: CCFloat })
|
||||
public speed: number = 3
|
||||
// //下个位置移动点
|
||||
private targetMoveIndex: number = 0
|
||||
// //鱼移动位置
|
||||
public movePList: Array<Vec2> = []
|
||||
// //贝萨尔曲线
|
||||
public bezierPList: Array<Vec2> = []
|
||||
public isMoving: boolean = false
|
||||
private minSpeed: number = 0.1
|
||||
private moveCount: number = 1
|
||||
private totalTimes: number = 60 * 2
|
||||
private _vec3Cahce: Vec3 = new Vec3()
|
||||
public startMove() {
|
||||
this.targetMoveIndex = 0
|
||||
this.isMoving = true
|
||||
//this.node.getComponent(Animation).play()//v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(this.node, () =>
|
||||
this.node.getComponent(Animation).play()
|
||||
)
|
||||
}
|
||||
//鱼类型
|
||||
@property({type: CCInteger})
|
||||
public fishType: number = 1
|
||||
//鱼移动速度
|
||||
@property({type: CCFloat})
|
||||
public speed: number = 3
|
||||
//下个位置移动点
|
||||
private targetMoveIndex: number = 0
|
||||
//鱼移动位置
|
||||
public movePList: Array<Vec2> = []
|
||||
//贝萨尔曲线
|
||||
public bezierPList: Array<Vec2> = []
|
||||
public isMoving: boolean = false
|
||||
private minSpeed: number = 0.1
|
||||
private moveCount: number = 1
|
||||
private totalTimes: number = 60 * 2
|
||||
private _vec3Cahce: Vec3 = new Vec3()
|
||||
|
||||
update(dt) {
|
||||
// this.moveFish();
|
||||
this.checkMoveBezier()
|
||||
}
|
||||
public startMove() {
|
||||
this.targetMoveIndex = 0
|
||||
this.isMoving = true
|
||||
//this.node.getComponent(Animation).play()//v3 当前帧 不能播放
|
||||
TimeHelper.exeNextFrame(this.node, () =>
|
||||
this.node.getComponent(Animation).play()
|
||||
)
|
||||
}
|
||||
|
||||
private checkMoveBezier() {
|
||||
if (this.isMoving && !this.getComponent(FishBase).isDead) {
|
||||
this.moveCount++
|
||||
if (this.moveCount >= this.totalTimes) {
|
||||
this.moveCount = this.totalTimes
|
||||
}
|
||||
this.moveBezier()
|
||||
}
|
||||
}
|
||||
update(dt) {
|
||||
// this.moveFish();
|
||||
this.checkMoveBezier()
|
||||
}
|
||||
|
||||
public moveBezier() {
|
||||
// [warn] [[-632,-230],[-444,-117],[-264,-242]]
|
||||
// let p0: cc.Vec2 = cc.v2(-632, -230)
|
||||
// let p1: cc.Vec2 = cc.v2(-444, -117)
|
||||
// let p2: cc.Vec2 = cc.v2(-264, -242)
|
||||
if (this.bezierPList.length > this.targetMoveIndex + 2) {
|
||||
let p0: Vec2 = this.bezierPList[this.targetMoveIndex]
|
||||
let p1: Vec2 = this.bezierPList[this.targetMoveIndex + 1]
|
||||
let p2: Vec2 = this.bezierPList[this.targetMoveIndex + 2]
|
||||
let t: number = this.moveCount / this.totalTimes
|
||||
let mx: number =
|
||||
Math.pow(1 - t, 2) * p0.x +
|
||||
2 * t * (1 - t) * p1.x +
|
||||
Math.pow(t, 2) * p2.x
|
||||
let my: number =
|
||||
Math.pow(1 - t, 2) * p0.y +
|
||||
2 * t * (1 - t) * p1.y +
|
||||
Math.pow(t, 2) * p2.y
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cahce.x, this._vec3Cahce.y),
|
||||
new Vec2(mx, my)
|
||||
)
|
||||
let rot111: number = MathUtils.radiansToDegrees(rad)
|
||||
let rot: number = MathUtils.rotation2Fish(rot111)
|
||||
if (this.fishType == 7 || this.fishType == 27 || this.fishType == 29) {
|
||||
if (rot > 90 || rot < -90) {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x > 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
} else {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x < 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
this.fishType == 9 ||
|
||||
this.fishType == 10 ||
|
||||
this.fishType == 21 ||
|
||||
this.fishType == 28
|
||||
) {
|
||||
} else {
|
||||
// this.node.rotation = rot; //过时
|
||||
this.node.angle = -rot
|
||||
}
|
||||
// Logger.log("moveBezier====", rad, rot111, this.fishType, rot)
|
||||
let moveTimes: number = Math.round(this.speed / this.minSpeed)
|
||||
for (let i = 0; i < moveTimes; i++) {
|
||||
let speedX: number = this.minSpeed * Math.cos(rad)
|
||||
let speedY: number = this.minSpeed * Math.sin(rad)
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
this._vec3Cahce.x += speedX
|
||||
this._vec3Cahce.y += speedY
|
||||
this.node.setPosition(this._vec3Cahce)
|
||||
if (
|
||||
MathUtils.distance(this._vec3Cahce.x, this._vec3Cahce.y, mx, my) <=
|
||||
this.minSpeed
|
||||
) {
|
||||
this.node.setPosition(mx, my)
|
||||
break
|
||||
}
|
||||
if (
|
||||
MathUtils.distance(
|
||||
this._vec3Cahce.x,
|
||||
this._vec3Cahce.y,
|
||||
p2.x,
|
||||
p2.y
|
||||
) <=
|
||||
this.minSpeed * 2
|
||||
) {
|
||||
this.node.setPosition(p2.x, p2.y)
|
||||
this.targetMoveIndex += 2
|
||||
this.moveCount = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.isMoving = false
|
||||
}
|
||||
}
|
||||
private checkMoveBezier() {
|
||||
if (this.isMoving && !this.getComponent(FishBase).isDead) {
|
||||
this.moveCount++
|
||||
if (this.moveCount >= this.totalTimes) {
|
||||
this.moveCount = this.totalTimes
|
||||
}
|
||||
this.moveBezier()
|
||||
}
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
this.isMoving = false
|
||||
}
|
||||
public moveBezier() {
|
||||
// [warn] [[-632,-230],[-444,-117],[-264,-242]]
|
||||
// let p0: cc.Vec2 = cc.v2(-632, -230)
|
||||
// let p1: cc.Vec2 = cc.v2(-444, -117)
|
||||
// let p2: cc.Vec2 = cc.v2(-264, -242)
|
||||
if (this.bezierPList.length > this.targetMoveIndex + 2) {
|
||||
let p0: Vec2 = this.bezierPList[this.targetMoveIndex]
|
||||
let p1: Vec2 = this.bezierPList[this.targetMoveIndex + 1]
|
||||
let p2: Vec2 = this.bezierPList[this.targetMoveIndex + 2]
|
||||
let t: number = this.moveCount / this.totalTimes
|
||||
let mx: number =
|
||||
Math.pow(1 - t, 2) * p0.x +
|
||||
2 * t * (1 - t) * p1.x +
|
||||
Math.pow(t, 2) * p2.x
|
||||
let my: number =
|
||||
Math.pow(1 - t, 2) * p0.y +
|
||||
2 * t * (1 - t) * p1.y +
|
||||
Math.pow(t, 2) * p2.y
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
let rad: number = MathUtils.p2pRad(
|
||||
new Vec2(this._vec3Cahce.x, this._vec3Cahce.y),
|
||||
new Vec2(mx, my)
|
||||
)
|
||||
let rot111: number = MathUtils.radiansToDegrees(rad)
|
||||
let rot: number = MathUtils.rotation2Fish(rot111)
|
||||
if (this.fishType == 7 || this.fishType == 27 || this.fishType == 29) {
|
||||
if (rot > 90 || rot < -90) {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x > 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
} else {
|
||||
this.node.getScale(this._vec3Cahce)
|
||||
if (this._vec3Cahce.x < 0) {
|
||||
this._vec3Cahce.x = -1 * this._vec3Cahce.x
|
||||
this.node.setScale(this._vec3Cahce)
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
this.fishType == 9 ||
|
||||
this.fishType == 10 ||
|
||||
this.fishType == 21 ||
|
||||
this.fishType == 28
|
||||
) {
|
||||
} else {
|
||||
// this.node.rotation = rot; //过时
|
||||
this.node.angle = -rot
|
||||
}
|
||||
// Logger.log("moveBezier====", rad, rot111, this.fishType, rot)
|
||||
let moveTimes: number = Math.round(this.speed / this.minSpeed)
|
||||
for (let i = 0; i < moveTimes; i++) {
|
||||
let speedX: number = this.minSpeed * Math.cos(rad)
|
||||
let speedY: number = this.minSpeed * Math.sin(rad)
|
||||
this.node.getPosition(this._vec3Cahce)
|
||||
this._vec3Cahce.x += speedX
|
||||
this._vec3Cahce.y += speedY
|
||||
this.node.setPosition(this._vec3Cahce)
|
||||
if (
|
||||
MathUtils.distance(this._vec3Cahce.x, this._vec3Cahce.y, mx, my) <=
|
||||
this.minSpeed
|
||||
) {
|
||||
this.node.setPosition(mx, my)
|
||||
break
|
||||
}
|
||||
if (
|
||||
MathUtils.distance(
|
||||
this._vec3Cahce.x,
|
||||
this._vec3Cahce.y,
|
||||
p2.x,
|
||||
p2.y
|
||||
) <=
|
||||
this.minSpeed * 2
|
||||
) {
|
||||
this.node.setPosition(p2.x, p2.y)
|
||||
this.targetMoveIndex += 2
|
||||
this.moveCount = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.isMoving = false
|
||||
}
|
||||
}
|
||||
|
||||
public exportBezierConfig() {
|
||||
Logger.warn('exportBezierConfig=')
|
||||
let tempConfig: Array<Array<number>> = []
|
||||
for (let i = 0; i < this.bezierPList.length; i++) {
|
||||
tempConfig[i] = []
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].x))
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].y))
|
||||
}
|
||||
Logger.warn('fishtype', this.fishType)
|
||||
Logger.warn('speed', this.speed)
|
||||
Logger.warn('scale', this.node.scale)
|
||||
Logger.warn(JSON.stringify(tempConfig))
|
||||
}
|
||||
onDisable() {
|
||||
this.isMoving = false
|
||||
}
|
||||
|
||||
public exportBezierConfig() {
|
||||
Logger.warn('exportBezierConfig=')
|
||||
let tempConfig: Array<Array<number>> = []
|
||||
for (let i = 0; i < this.bezierPList.length; i++) {
|
||||
tempConfig[i] = []
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].x))
|
||||
tempConfig[i].push(Math.floor(this.bezierPList[i].y))
|
||||
}
|
||||
Logger.warn('fishtype', this.fishType)
|
||||
Logger.warn('speed', this.speed)
|
||||
Logger.warn('scale', this.node.scale)
|
||||
Logger.warn(JSON.stringify(tempConfig))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CommonEvent')
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { _decorator } from 'cc'
|
||||
import DateUtil from '../utils/DateUtil'
|
||||
import NetConfig from './NetConfig'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { _decorator, AudioClip } from 'cc'
|
||||
import { AudioClip } from 'cc'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
|
||||
export default class MusicConfig {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { _decorator } from 'cc'
|
||||
export default class NetConfig {
|
||||
public static hotupdateUrl: string = 'http://localhost:33/hotupdate'
|
||||
}
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Label,
|
||||
Node,
|
||||
tween,
|
||||
Vec3,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Label, Node, tween, Vec3 } from 'cc'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CommonTips')
|
||||
export default class CommonTips extends Component {
|
||||
public static TipsZorderIndex: number = 999
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { _decorator, Component, Prefab, Widget, instantiate, Node } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Node, Prefab, Widget } from 'cc'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('DarkLayer')
|
||||
export default class DarkLayer extends Component {
|
||||
private static prefab: Prefab
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { _decorator, Component, Node, Widget, director } from 'cc'
|
||||
const { ccclass } = _decorator
|
||||
|
||||
import { _decorator, Component, Node, Widget } from 'cc'
|
||||
import DarkLayer from './DarkLayer'
|
||||
import { UIRoot } from '../../game/utils/UIRoot'
|
||||
|
||||
const { ccclass } = _decorator
|
||||
|
||||
@ccclass('DialogBase')
|
||||
export default class DialogBase extends Component {
|
||||
private static LocalZOrder: number = 5
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Node,
|
||||
Prefab,
|
||||
instantiate,
|
||||
math,
|
||||
Quat,
|
||||
Vec3,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Node, Prefab, Quat, Vec3 } from 'cc'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingPrefab')
|
||||
export default class LoadingPrefab extends Component {
|
||||
public static instance: Node
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { _decorator, Component, Node, Prefab, instantiate } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, Component, instantiate, Node, Prefab } from 'cc'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import Progress from './Progress'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingScenePrefab')
|
||||
export default class LoadingScenePrefab extends Component {
|
||||
public static instance: Node
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
AssetManager,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
instantiate,
|
||||
Prefab,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, AssetManager, AudioClip, AudioSource, Component, instantiate, Prefab } from 'cc'
|
||||
import { Logger } from '../utils/Logger'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import LocalStorage from '../utils/LocalStorage'
|
||||
import MusicConfig from '../config/MusicConfig'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
/**
|
||||
* 背景音乐
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { _decorator, Component, Label, ProgressBar } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { Logger } from '../utils/Logger'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('Progress')
|
||||
export default class Progress extends Component {
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
import {
|
||||
_decorator,
|
||||
Component,
|
||||
Prefab,
|
||||
NodePool,
|
||||
Node,
|
||||
instantiate,
|
||||
AssetManager,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
} from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, AssetManager, AudioClip, AudioSource, Component, instantiate, Node, NodePool, Prefab } from 'cc'
|
||||
import { Logger } from '../utils/Logger'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
import LocalStorage from '../utils/LocalStorage'
|
||||
@@ -18,6 +6,9 @@ import EventManager from '../utils/EventManager'
|
||||
import CommonEvent from '../config/CommonEvent'
|
||||
import MusicConfig from '../config/MusicConfig'
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
// /**
|
||||
// * 音效
|
||||
// * Ios暂时有bug,弃用
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { _decorator, Component, SpriteFrame } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('TextureMgr')
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
import { Canvas, error, log, ResolutionPolicy, sys, view, _decorator } from 'cc'
|
||||
import { _decorator, Canvas, error, log, view } from 'cc'
|
||||
import DialogBase from '../uicomponent/DialogBase'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { Logger } from './Logger'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('AdapterHelper')
|
||||
export default class AdapterHelper {
|
||||
public static winSizeWidth: number
|
||||
public static winSizeHeiht: number
|
||||
public static fixApdater() {
|
||||
log('v3.6没找到接口修改 fitHeight、fitWidth, 先在项目里写死fitHeight=true')
|
||||
return
|
||||
let framesize = view.getFrameSize()
|
||||
if (!this.winSizeWidth) {
|
||||
this.winSizeWidth = screen.width
|
||||
this.winSizeHeiht = screen.height
|
||||
}
|
||||
let designsize = view.getDesignResolutionSize()
|
||||
let canvas: Canvas = DialogBase.GetRootCanvas().getComponent(Canvas)
|
||||
public static winSizeWidth: number
|
||||
public static winSizeHeiht: number
|
||||
|
||||
let ratio: number = framesize.height / framesize.width
|
||||
let designRatio: number = designsize.height / designsize.width
|
||||
if (ratio > designRatio) {
|
||||
//canvas.fitHeight = false;
|
||||
//canvas.fitWidth = true;
|
||||
error(
|
||||
'v3.6没找到接口修改 fitHeight、fitWidth, 先在项目里写死fitHeight=true'
|
||||
)
|
||||
} else {
|
||||
//canvas.fitHeight = true;
|
||||
//canvas.fitWidth = false;
|
||||
error(
|
||||
'v3.6没找到接口修改 fitHeight、fitWidth, 先在项目里写死fitHeight=true'
|
||||
)
|
||||
}
|
||||
}
|
||||
public static fixApdater() {
|
||||
log('v3.6没找到接口修改 fitHeight、fitWidth, 先在项目里写死fitHeight=true')
|
||||
return
|
||||
let framesize = view.getFrameSize()
|
||||
if (!this.winSizeWidth) {
|
||||
this.winSizeWidth = screen.width
|
||||
this.winSizeHeiht = screen.height
|
||||
}
|
||||
let designsize = view.getDesignResolutionSize()
|
||||
let canvas: Canvas = DialogBase.GetRootCanvas().getComponent(Canvas)
|
||||
|
||||
let ratio: number = framesize.height / framesize.width
|
||||
let designRatio: number = designsize.height / designsize.width
|
||||
if (ratio > designRatio) {
|
||||
//canvas.fitHeight = false;
|
||||
//canvas.fitWidth = true;
|
||||
error(
|
||||
'v3.6没找到接口修改 fitHeight、fitWidth, 先在项目里写死fitHeight=true'
|
||||
)
|
||||
} else {
|
||||
//canvas.fitHeight = true;
|
||||
//canvas.fitWidth = false;
|
||||
error(
|
||||
'v3.6没找到接口修改 fitHeight、fitWidth, 先在项目里写死fitHeight=true'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,48 @@
|
||||
import { _decorator } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { Logger } from './Logger'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('BitUtil')
|
||||
export default class BitUtil {
|
||||
//index是二进制从右到左
|
||||
public static isBitSet(value: number, index: number): boolean {
|
||||
let str: string = value.toString(2)
|
||||
if (parseInt(str[str.length - 1 - index]) == 1) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
//index是二进制从右到左
|
||||
public static isBitSet(value: number, index: number): boolean {
|
||||
let str: string = value.toString(2)
|
||||
return parseInt(str[str.length - 1 - index]) == 1
|
||||
}
|
||||
|
||||
//从右到左计算
|
||||
public static setBitValue(value: number, index: number): number {
|
||||
let newValue: number = value
|
||||
let str: string = value.toString(2)
|
||||
let newStr: string = ''
|
||||
let maxIndex = Math.max(str.length - 1, index)
|
||||
for (let i = 0; i <= maxIndex; i++) {
|
||||
if (index == i) {
|
||||
newStr = '1' + newStr
|
||||
} else {
|
||||
if (str[i] == undefined) {
|
||||
newStr = '0' + newStr
|
||||
} else {
|
||||
newStr = str[i] + newStr
|
||||
}
|
||||
}
|
||||
}
|
||||
newValue = parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
//从右到左计算
|
||||
public static setBitValue(value: number, index: number): number {
|
||||
let newValue: number = value
|
||||
let str: string = value.toString(2)
|
||||
let newStr: string = ''
|
||||
let maxIndex = Math.max(str.length - 1, index)
|
||||
for (let i = 0; i <= maxIndex; i++) {
|
||||
if (index == i) {
|
||||
newStr = '1' + newStr
|
||||
} else {
|
||||
if (str[i] == undefined) {
|
||||
newStr = '0' + newStr
|
||||
} else {
|
||||
newStr = str[i] + newStr
|
||||
}
|
||||
}
|
||||
}
|
||||
newValue = parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
|
||||
public static clearBitValue(value: number, index: number) {
|
||||
let newValue: number = value
|
||||
let str: string = value.toString(2)
|
||||
let newStr: string = ''
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
if (index == str.length - 1 - i) {
|
||||
newStr = '0' + newStr
|
||||
} else {
|
||||
newStr = str[i] + newStr
|
||||
}
|
||||
}
|
||||
newValue = parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
public static clearBitValue(value: number, index: number) {
|
||||
let newValue: number = value
|
||||
let str: string = value.toString(2)
|
||||
let newStr: string = ''
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
if (index == str.length - 1 - i) {
|
||||
newStr = '0' + newStr
|
||||
} else {
|
||||
newStr = str[i] + newStr
|
||||
}
|
||||
}
|
||||
newValue = parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { _decorator, Color } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ColorHelper')
|
||||
export default class ColorHelper {
|
||||
public static getColor(hexStr: string): Color {
|
||||
let color: Color = Color.BLACK
|
||||
return color.fromHEX(hexStr)
|
||||
}
|
||||
public static getColor(hexStr: string): Color {
|
||||
let color: Color = Color.BLACK
|
||||
return color.fromHEX(hexStr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,139 +1,136 @@
|
||||
import { _decorator } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
|
||||
export default class DateUtil {
|
||||
public static formatNumStr(num: number) {
|
||||
let str = '' + num
|
||||
if (num < 10) {
|
||||
str = '0' + num
|
||||
}
|
||||
return str
|
||||
}
|
||||
public static formatNumStr(num: number) {
|
||||
let str = '' + num
|
||||
if (num < 10) {
|
||||
str = '0' + num
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
public static formateYearMonthDayStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
|
||||
)
|
||||
}
|
||||
public static formateYearMonthDayStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
|
||||
)
|
||||
}
|
||||
|
||||
public static formateMonthDayStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return date.getMonth() + 1 + '月' + date.getDate() + '日'
|
||||
}
|
||||
public static formateMonthDayStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return date.getMonth() + 1 + '月' + date.getDate() + '日'
|
||||
}
|
||||
|
||||
// timestamp:1453094034000 2018-1-31 19:53:44
|
||||
//根据时间戳返回 2018-1-31 19:53:44
|
||||
public static formatDateStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
' ' +
|
||||
this.formatNumStr(date.getHours()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getMinutes()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getSeconds())
|
||||
)
|
||||
}
|
||||
// timestamp:1453094034000 2018-1-31 19:53:44
|
||||
//根据时间戳返回 2018-1-31 19:53:44
|
||||
public static formatDateStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
' ' +
|
||||
this.formatNumStr(date.getHours()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getMinutes()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getSeconds())
|
||||
)
|
||||
}
|
||||
|
||||
// timestamp:1453094034000 2018-1-31-19-53-44
|
||||
//根据时间戳返回 2018-1-31-19-53-44
|
||||
public static formatDateStr2(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
'-' +
|
||||
this.formatNumStr(date.getHours()) +
|
||||
'-' +
|
||||
this.formatNumStr(date.getMinutes()) +
|
||||
'-' +
|
||||
this.formatNumStr(date.getSeconds())
|
||||
)
|
||||
}
|
||||
// timestamp:1453094034000 2018-1-31-19-53-44
|
||||
//根据时间戳返回 2018-1-31-19-53-44
|
||||
public static formatDateStr2(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
'-' +
|
||||
this.formatNumStr(date.getHours()) +
|
||||
'-' +
|
||||
this.formatNumStr(date.getMinutes()) +
|
||||
'-' +
|
||||
this.formatNumStr(date.getSeconds())
|
||||
)
|
||||
}
|
||||
|
||||
// timestamp:1453094034000 2018-1-31
|
||||
//根据时间戳返回 2018-1-31
|
||||
public static formatDateStr3(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
|
||||
)
|
||||
}
|
||||
// timestamp:1453094034000 2018-1-31
|
||||
//根据时间戳返回 2018-1-31
|
||||
public static formatDateStr3(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
|
||||
)
|
||||
}
|
||||
|
||||
// timestamp:1453094034000
|
||||
//根据时间戳返回 19:53
|
||||
public static formatHourMinStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
this.formatNumStr(date.getHours()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getMinutes())
|
||||
)
|
||||
}
|
||||
// timestamp:1453094034000
|
||||
//根据时间戳返回 19:53
|
||||
public static formatHourMinStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
this.formatNumStr(date.getHours()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getMinutes())
|
||||
)
|
||||
}
|
||||
|
||||
// timestamp:1453094034000
|
||||
//根据时间戳返回 19:53:11
|
||||
public static formatHourMinSecondStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
this.formatNumStr(date.getHours()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getMinutes()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getSeconds())
|
||||
)
|
||||
}
|
||||
// timestamp:1453094034000
|
||||
//根据时间戳返回 19:53:11
|
||||
public static formatHourMinSecondStr(timestamp: number) {
|
||||
let date: Date = new Date(timestamp)
|
||||
return (
|
||||
this.formatNumStr(date.getHours()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getMinutes()) +
|
||||
':' +
|
||||
this.formatNumStr(date.getSeconds())
|
||||
)
|
||||
}
|
||||
|
||||
public static now(): number {
|
||||
let date: Date = new Date()
|
||||
return date.getTime()
|
||||
}
|
||||
public static now(): number {
|
||||
let date: Date = new Date()
|
||||
return date.getTime()
|
||||
}
|
||||
|
||||
public static betweenTime(startTime: number, endTime: number) {
|
||||
let date: Date = new Date()
|
||||
if (date.getTime() >= startTime && date.getTime() <= endTime) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
public static betweenTime(startTime: number, endTime: number) {
|
||||
let date: Date = new Date()
|
||||
if (date.getTime() >= startTime && date.getTime() <= endTime) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//根据时间戳返回 1天19:53:11
|
||||
public static formatLeftTime(timestamp: number) {
|
||||
let result: string = ''
|
||||
let day: number = Math.floor(timestamp / (1000 * 60 * 60 * 24))
|
||||
let hour: number = Math.floor(timestamp / (1000 * 60 * 60)) % 24
|
||||
let min: number = Math.floor(timestamp / (1000 * 60)) % 60
|
||||
let second: number = Math.floor(timestamp / 1000) % 60
|
||||
result =
|
||||
day +
|
||||
'天' +
|
||||
this.formatNumStr(hour) +
|
||||
':' +
|
||||
this.formatNumStr(min) +
|
||||
':' +
|
||||
this.formatNumStr(second)
|
||||
return result
|
||||
}
|
||||
//根据时间戳返回 1天19:53:11
|
||||
public static formatLeftTime(timestamp: number) {
|
||||
let result: string = ''
|
||||
let day: number = Math.floor(timestamp / (1000 * 60 * 60 * 24))
|
||||
let hour: number = Math.floor(timestamp / (1000 * 60 * 60)) % 24
|
||||
let min: number = Math.floor(timestamp / (1000 * 60)) % 60
|
||||
let second: number = Math.floor(timestamp / 1000) % 60
|
||||
result =
|
||||
day +
|
||||
'天' +
|
||||
this.formatNumStr(hour) +
|
||||
':' +
|
||||
this.formatNumStr(min) +
|
||||
':' +
|
||||
this.formatNumStr(second)
|
||||
return result
|
||||
}
|
||||
|
||||
public static isToday(dateTime: number): boolean {
|
||||
let nowDate: Date = new Date()
|
||||
let checkDate: Date = new Date(dateTime)
|
||||
if (
|
||||
checkDate.getFullYear() == nowDate.getFullYear() &&
|
||||
checkDate.getMonth() == nowDate.getMonth() &&
|
||||
checkDate.getDate() == nowDate.getDate()
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
public static isToday(dateTime: number): boolean {
|
||||
let nowDate: Date = new Date()
|
||||
let checkDate: Date = new Date(dateTime)
|
||||
if (
|
||||
checkDate.getFullYear() == nowDate.getFullYear() &&
|
||||
checkDate.getMonth() == nowDate.getMonth() &&
|
||||
checkDate.getDate() == nowDate.getDate()
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,131 +1,132 @@
|
||||
import { _decorator, Node, Color, Button, Component, Slider } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
import { Button, Color, Component, Node, Slider } from 'cc'
|
||||
import ColorHelper from './ColorHelper'
|
||||
|
||||
export class HaoEvent {
|
||||
public callback: Function
|
||||
public caller: any
|
||||
public isStop: boolean
|
||||
constructor(callback: Function, caller: any) {
|
||||
this.callback = callback
|
||||
this.caller = caller
|
||||
this.isStop = false
|
||||
}
|
||||
public callback: Function
|
||||
public caller: any
|
||||
public isStop: boolean
|
||||
|
||||
constructor(callback: Function, caller: any) {
|
||||
this.callback = callback
|
||||
this.caller = caller
|
||||
this.isStop = false
|
||||
}
|
||||
}
|
||||
|
||||
export default class EventManager {
|
||||
public static instance: EventManager = new EventManager()
|
||||
public static instance: EventManager = new EventManager()
|
||||
|
||||
private callbackList = {}
|
||||
private callbackList = {}
|
||||
|
||||
public constructor() {}
|
||||
public constructor() {
|
||||
}
|
||||
|
||||
//注册事件
|
||||
public addListener(eventName: string, callback: Function, caller: any) {
|
||||
if (this.callbackList[eventName]) {
|
||||
let eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
//不同元件才放入,相同元件覆蓋
|
||||
let add: boolean = true
|
||||
for (let i = 0; i < eventList.length; i++) {
|
||||
let event: HaoEvent = eventList[i]
|
||||
if (caller === event.caller) {
|
||||
add = false
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
eventList.push(new HaoEvent(callback, caller))
|
||||
this.callbackList[eventName] = eventList
|
||||
}
|
||||
} else {
|
||||
// this.callbackList[eventName] = [[callback, caller]];
|
||||
this.callbackList[eventName] = [new HaoEvent(callback, caller)]
|
||||
}
|
||||
}
|
||||
//注册事件
|
||||
public addListener(eventName: string, callback: Function, caller: any) {
|
||||
if (this.callbackList[eventName]) {
|
||||
let eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
//不同元件才放入,相同元件覆蓋
|
||||
let add: boolean = true
|
||||
for (let i = 0; i < eventList.length; i++) {
|
||||
let event: HaoEvent = eventList[i]
|
||||
if (caller === event.caller) {
|
||||
add = false
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
eventList.push(new HaoEvent(callback, caller))
|
||||
this.callbackList[eventName] = eventList
|
||||
}
|
||||
} else {
|
||||
// this.callbackList[eventName] = [[callback, caller]];
|
||||
this.callbackList[eventName] = [new HaoEvent(callback, caller)]
|
||||
}
|
||||
}
|
||||
|
||||
public removeListener(eventName: string, callback: Function) {
|
||||
if (this.callbackList[eventName]) {
|
||||
for (let i = this.callbackList[eventName].length - 1; i >= 0; i--) {
|
||||
let event: HaoEvent = this.callbackList[eventName][i]
|
||||
if (event.callback == callback) {
|
||||
this.callbackList[eventName].splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public removeListener(eventName: string, callback: Function) {
|
||||
if (this.callbackList[eventName]) {
|
||||
for (let i = this.callbackList[eventName].length - 1; i >= 0; i--) {
|
||||
let event: HaoEvent = this.callbackList[eventName][i]
|
||||
if (event.callback == callback) {
|
||||
this.callbackList[eventName].splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispatchEvent(eventName, parameter?: any, ...restOfName: any[]) {
|
||||
let eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
if (eventList) {
|
||||
for (let i = eventList.length - 1; i >= 0; i--) {
|
||||
let event: HaoEvent = eventList[i]
|
||||
event.callback.call(event.caller, event, parameter, ...restOfName)
|
||||
if (event.isStop) {
|
||||
break
|
||||
}
|
||||
}
|
||||
for (let i = eventList.length - 1; i >= 0; i--) {
|
||||
let event: HaoEvent = eventList[i]
|
||||
event.isStop = false
|
||||
}
|
||||
}
|
||||
}
|
||||
public dispatchEvent(eventName, parameter?: any, ...restOfName: any[]) {
|
||||
let eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
if (eventList) {
|
||||
for (let i = eventList.length - 1; i >= 0; i--) {
|
||||
let event: HaoEvent = eventList[i]
|
||||
event.callback.call(event.caller, event, parameter, ...restOfName)
|
||||
if (event.isStop) {
|
||||
break
|
||||
}
|
||||
}
|
||||
for (let i = eventList.length - 1; i >= 0; i--) {
|
||||
let event: HaoEvent = eventList[i]
|
||||
event.isStop = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public addBtnEvent(
|
||||
parentNode: Node,
|
||||
objectNode: Node,
|
||||
scriptName: string,
|
||||
eventName: string,
|
||||
data: any = null
|
||||
) {
|
||||
var btn: Button = objectNode.addComponent(Button)
|
||||
var clickEventHandler = new Component.EventHandler()
|
||||
clickEventHandler.target = parentNode //这个 node 节点是你的事件处理代码组件所属的节点
|
||||
clickEventHandler.component = scriptName //这个是代码文件名
|
||||
clickEventHandler.handler = eventName
|
||||
clickEventHandler.customEventData = data
|
||||
btn.clickEvents.push(clickEventHandler)
|
||||
this.addBtnEffect(objectNode)
|
||||
}
|
||||
public addBtnEvent(
|
||||
parentNode: Node,
|
||||
objectNode: Node,
|
||||
scriptName: string,
|
||||
eventName: string,
|
||||
data: any = null
|
||||
) {
|
||||
var btn: Button = objectNode.addComponent(Button)
|
||||
var clickEventHandler = new Component.EventHandler()
|
||||
clickEventHandler.target = parentNode //这个 node 节点是你的事件处理代码组件所属的节点
|
||||
clickEventHandler.component = scriptName //这个是代码文件名
|
||||
clickEventHandler.handler = eventName
|
||||
clickEventHandler.customEventData = data
|
||||
btn.clickEvents.push(clickEventHandler)
|
||||
this.addBtnEffect(objectNode)
|
||||
}
|
||||
|
||||
public removeBtnEvent(objectNode: Node) {
|
||||
objectNode.removeComponent(Button)
|
||||
}
|
||||
public removeBtnEvent(objectNode: Node) {
|
||||
objectNode.removeComponent(Button)
|
||||
}
|
||||
|
||||
public removeBtnEffect(objectNode: Node) {
|
||||
var b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.NONE
|
||||
}
|
||||
public removeBtnEffect(objectNode: Node) {
|
||||
var b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.NONE
|
||||
}
|
||||
|
||||
public addBtnEffect(objectNode: Node, scale: number = 1.1) {
|
||||
var b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.SCALE
|
||||
b.zoomScale = scale
|
||||
}
|
||||
public addBtnEffect(objectNode: Node, scale: number = 1.1) {
|
||||
var b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.SCALE
|
||||
b.zoomScale = scale
|
||||
}
|
||||
|
||||
public addBtnEffect_color(
|
||||
objectNode: Node,
|
||||
normalC: Color = ColorHelper.getColor('#FFFFFF'),
|
||||
pressC: Color = ColorHelper.getColor('#C0C0C0')
|
||||
) {
|
||||
var b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.COLOR
|
||||
b.normalColor = normalC
|
||||
b.pressedColor = pressC
|
||||
}
|
||||
public addBtnEffect_color(
|
||||
objectNode: Node,
|
||||
normalC: Color = ColorHelper.getColor('#FFFFFF'),
|
||||
pressC: Color = ColorHelper.getColor('#C0C0C0')
|
||||
) {
|
||||
var b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.COLOR
|
||||
b.normalColor = normalC
|
||||
b.pressedColor = pressC
|
||||
}
|
||||
|
||||
public addSliderEvent(
|
||||
parentNode: Node,
|
||||
objectNode: Node,
|
||||
EventName: string,
|
||||
data: any
|
||||
) {
|
||||
var b = objectNode.getComponent(Slider)
|
||||
var clickEventHandler = new Component.EventHandler()
|
||||
clickEventHandler.target = parentNode //这个 node 节点是你的事件处理代码组件所属的节点
|
||||
clickEventHandler.component = parentNode.name //这个是代码文件名
|
||||
clickEventHandler.handler = EventName
|
||||
clickEventHandler.customEventData = data
|
||||
b.slideEvents.push(clickEventHandler)
|
||||
}
|
||||
public addSliderEvent(
|
||||
parentNode: Node,
|
||||
objectNode: Node,
|
||||
EventName: string,
|
||||
data: any
|
||||
) {
|
||||
var b = objectNode.getComponent(Slider)
|
||||
var clickEventHandler = new Component.EventHandler()
|
||||
clickEventHandler.target = parentNode //这个 node 节点是你的事件处理代码组件所属的节点
|
||||
clickEventHandler.component = parentNode.name //这个是代码文件名
|
||||
clickEventHandler.handler = EventName
|
||||
clickEventHandler.customEventData = data
|
||||
b.slideEvents.push(clickEventHandler)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { _decorator } from 'cc'
|
||||
export default class Grid {
|
||||
public row: number
|
||||
public col: number
|
||||
constructor(row: number, col) {
|
||||
this.row = row
|
||||
this.col = col
|
||||
}
|
||||
public row: number
|
||||
public col: number
|
||||
|
||||
public static init(row: number, col: number) {
|
||||
return new Grid(row, col)
|
||||
}
|
||||
constructor(row: number, col: number) {
|
||||
this.row = row
|
||||
this.col = col
|
||||
}
|
||||
|
||||
public static init(row: number, col: number) {
|
||||
return new Grid(row, col)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
import { _decorator } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
|
||||
export default class HaoEncrypt {
|
||||
public static encode(str: string) {
|
||||
let result: string = ''
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
//遍历字符串
|
||||
let code: number = str.charCodeAt(i) // //逐个提取每个字符,并获取Unicode编码值
|
||||
if (i % 2 == 0) {
|
||||
code += 2
|
||||
} else {
|
||||
code += 1
|
||||
}
|
||||
result += String.fromCharCode(code)
|
||||
}
|
||||
return result
|
||||
}
|
||||
public static encode(str: string) {
|
||||
let result: string = ''
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
//遍历字符串
|
||||
let code: number = str.charCodeAt(i) // //逐个提取每个字符,并获取Unicode编码值
|
||||
if (i % 2 == 0) {
|
||||
code += 2
|
||||
} else {
|
||||
code += 1
|
||||
}
|
||||
result += String.fromCharCode(code)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public static decode(str: string) {
|
||||
let result: string = ''
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
//遍历字符串
|
||||
let code: number = str.charCodeAt(i) // //逐个提取每个字符,并获取Unicode编码值
|
||||
if (i % 2 == 0) {
|
||||
code -= 2
|
||||
} else {
|
||||
code -= 1
|
||||
}
|
||||
result += String.fromCharCode(code)
|
||||
}
|
||||
return result
|
||||
}
|
||||
public static decode(str: string) {
|
||||
let result: string = ''
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
//遍历字符串
|
||||
let code: number = str.charCodeAt(i) // //逐个提取每个字符,并获取Unicode编码值
|
||||
if (i % 2 == 0) {
|
||||
code -= 2
|
||||
} else {
|
||||
code -= 1
|
||||
}
|
||||
result += String.fromCharCode(code)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { sys, _decorator, native, System } from 'cc'
|
||||
import { native, sys } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
import EventManager from './EventManager'
|
||||
import VersionManager from './VersionManager'
|
||||
@@ -7,326 +7,315 @@ import ResourcePreload from '../../game/utils/ResourcePreload'
|
||||
import CommonTips from '../uicomponent/CommonTips'
|
||||
|
||||
export default class HotUpdate {
|
||||
public static Event_CheckUpdate: string = 'Event_CheckUpdate'
|
||||
public static Event_On_Progress: string = 'HotUpdate_Event_On_Progress'
|
||||
public static Event_On_NeedUpdate: string = 'HotUpdate_Event_On_NeedUpdate'
|
||||
public static Event_Finish_Update: string = 'HotUpdate_Event_Finish'
|
||||
public static Event_On_ALREADY_UP_TO_DATE: string =
|
||||
'HotUpdate_Event_On_ALREADY_UP_TO_DATE'
|
||||
public static Event_On_Fail_Update: string = 'HotUpdate_Event_On_Fail_Update'
|
||||
private _am: any
|
||||
private _checkListener
|
||||
private storagePath: string
|
||||
private manifestUrl: string
|
||||
private localBigVersion: number
|
||||
private remoteBigVersion: number
|
||||
public needUpdate: boolean = false
|
||||
public isUpdating: boolean
|
||||
public isFinishUpdate: boolean
|
||||
public isCheck: boolean
|
||||
private key: string
|
||||
private hotupdateIndex: number
|
||||
constructor() {}
|
||||
public init(
|
||||
index: number,
|
||||
key: string = 'Code-remote-asset',
|
||||
manifestUrl: string
|
||||
) {
|
||||
if (sys.isNative) {
|
||||
this.hotupdateIndex = index
|
||||
this.key = key
|
||||
this.manifestUrl = manifestUrl
|
||||
if (false) {
|
||||
//暂时不想修 fileUtils 这个报错
|
||||
//暂时注释
|
||||
// this.storagePath = jsb.fileUtils.getWritablePath() + key;
|
||||
// if (!jsb.fileUtils.isDirectoryExist(this.storagePath)) {
|
||||
// jsb.fileUtils.createDirectory(this.storagePath)
|
||||
// }
|
||||
} else {
|
||||
this.storagePath = '获取this.storagePath报错了'
|
||||
}
|
||||
public static Event_CheckUpdate: string = 'Event_CheckUpdate'
|
||||
public static Event_On_Progress: string = 'HotUpdate_Event_On_Progress'
|
||||
public static Event_On_NeedUpdate: string = 'HotUpdate_Event_On_NeedUpdate'
|
||||
public static Event_Finish_Update: string = 'HotUpdate_Event_Finish'
|
||||
public static Event_On_ALREADY_UP_TO_DATE: string =
|
||||
'HotUpdate_Event_On_ALREADY_UP_TO_DATE'
|
||||
public static Event_On_Fail_Update: string = 'HotUpdate_Event_On_Fail_Update'
|
||||
private _am: any
|
||||
private _checkListener: null
|
||||
private storagePath: string
|
||||
private manifestUrl: string
|
||||
private localBigVersion: number
|
||||
private remoteBigVersion: number
|
||||
public needUpdate: boolean = false
|
||||
public isUpdating: boolean
|
||||
public isFinishUpdate: boolean
|
||||
public isCheck: boolean
|
||||
private key: string
|
||||
private hotupdateIndex: number
|
||||
|
||||
Logger.log(this, 'init removeDirectory=', this.storagePath + '_temp')
|
||||
}
|
||||
this.needUpdate = false
|
||||
this.isUpdating = false
|
||||
this.isFinishUpdate = false
|
||||
this.isCheck = false
|
||||
}
|
||||
constructor() {
|
||||
}
|
||||
|
||||
private jumpToPack() {
|
||||
let url: string
|
||||
if (sys.isNative) {
|
||||
if (sys.os == sys.OS.ANDROID) {
|
||||
url = VersionManager.instance.apkStoreUrl
|
||||
} else if (sys.os == sys.OS.IOS) {
|
||||
url = VersionManager.instance.iosStoreUrl
|
||||
}
|
||||
}
|
||||
Logger.info(
|
||||
this,
|
||||
'jumpToPack==androidurl===',
|
||||
VersionManager.instance.apkStoreUrl
|
||||
)
|
||||
Logger.info(
|
||||
this,
|
||||
'jumpToPack==iosStoreUrl===',
|
||||
VersionManager.instance.iosStoreUrl
|
||||
)
|
||||
Logger.info(this, 'jumpToPack=====', url)
|
||||
sys.openURL(url)
|
||||
// cc.game.end();
|
||||
}
|
||||
public init(
|
||||
index: number,
|
||||
key: string = 'Code-remote-asset',
|
||||
manifestUrl: string
|
||||
) {
|
||||
if (sys.isNative) {
|
||||
this.hotupdateIndex = index
|
||||
this.key = key
|
||||
this.manifestUrl = manifestUrl
|
||||
this.storagePath = '获取this.storagePath报错了'
|
||||
|
||||
//显示强制更新,即更细包面板
|
||||
private showPackUpdateDialog() {
|
||||
CommonTips.showMsg(
|
||||
'有新的版本需要更新,下载后请先卸载,以前的版本,再安装!'
|
||||
)
|
||||
this.jumpToPack()
|
||||
this.showPackUpdateDialog()
|
||||
}
|
||||
Logger.log(this, 'init removeDirectory=', this.storagePath + '_temp')
|
||||
}
|
||||
this.needUpdate = false
|
||||
this.isUpdating = false
|
||||
this.isFinishUpdate = false
|
||||
this.isCheck = false
|
||||
}
|
||||
|
||||
private checkCb(event) {
|
||||
Logger.log(this, 'checkCb Code: =================' + event.getEventCode())
|
||||
switch (event.getEventCode()) {
|
||||
case native.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
|
||||
Logger.info(this, 'No local manifest file found, hot update skipped.')
|
||||
this.failUpdate()
|
||||
break
|
||||
case native.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
|
||||
case native.EventAssetsManager.ERROR_PARSE_MANIFEST:
|
||||
Logger.info(this, 'Fail to download manifest file, hot update skipped.')
|
||||
this.failUpdate()
|
||||
break
|
||||
case native.EventAssetsManager.ALREADY_UP_TO_DATE:
|
||||
Logger.info(this, 'Already up to date with the latest remote version.')
|
||||
this.alreadyUpToDate()
|
||||
break
|
||||
case native.EventAssetsManager.NEW_VERSION_FOUND:
|
||||
Logger.info(
|
||||
this,
|
||||
'new version found, please try to update.',
|
||||
this.localBigVersion,
|
||||
this.remoteBigVersion
|
||||
)
|
||||
if (
|
||||
this.key == VersionManager.Config_Key[0] &&
|
||||
this.localBigVersion < this.remoteBigVersion
|
||||
) {
|
||||
//更新大版本
|
||||
Logger.info(
|
||||
this,
|
||||
'new version found, please try to update======packupdate=',
|
||||
this.localBigVersion,
|
||||
this.remoteBigVersion
|
||||
)
|
||||
this.showPackUpdateDialog()
|
||||
} else {
|
||||
Logger.info(
|
||||
this,
|
||||
'new version found, please try to update======hotupdate=',
|
||||
this.localBigVersion,
|
||||
this.remoteBigVersion
|
||||
)
|
||||
// this._am.update();
|
||||
this.needUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_NeedUpdate,
|
||||
this.key
|
||||
)
|
||||
}
|
||||
break
|
||||
case native.EventAssetsManager.UPDATE_PROGRESSION:
|
||||
// var currentPercent = event.getPercent();
|
||||
// var totalPercent = event.getPercentByFile();
|
||||
// var fileprocess = event.getDownloadedFiles() + ' / ' + event.getTotalFiles();
|
||||
// var byteprocess = event.getDownloadedBytes() + ' / ' + event.getTotalBytes();
|
||||
Logger.info(
|
||||
this,
|
||||
'UPDATE_PROGRESSION2222==========',
|
||||
this.key,
|
||||
event.getDownloadedBytes(),
|
||||
event.getTotalBytes()
|
||||
)
|
||||
if (event.getTotalBytes() > 0) {
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_Progress,
|
||||
event.getDownloadedBytes(),
|
||||
event.getTotalBytes(),
|
||||
this.key
|
||||
)
|
||||
}
|
||||
break
|
||||
case native.EventAssetsManager.UPDATE_FINISHED:
|
||||
Logger.info(this, 'UPDATE_FINISHED==============')
|
||||
this.finishUpdate(true)
|
||||
break
|
||||
case native.EventAssetsManager.UPDATE_FAILED:
|
||||
Logger.warn(this, 'Update failed==========', event.getMessage())
|
||||
this.failUpdate()
|
||||
break
|
||||
case native.EventAssetsManager.ERROR_UPDATING:
|
||||
let fullFilePath: string = this.storagePath + '/' + event.getAssetId()
|
||||
let tempFilePath: string =
|
||||
this.storagePath + '_temp/' + event.getAssetId()
|
||||
Logger.warn(this, 'fullFilePath====', fullFilePath)
|
||||
Logger.warn(this, 'tempFilePath====', tempFilePath)
|
||||
// jsb.fileUtils.removeFile(tempFilePath);
|
||||
Logger.warn(
|
||||
this,
|
||||
'ERROR_UPDATING=============',
|
||||
event.getAssetId(),
|
||||
event.getMessage()
|
||||
)
|
||||
this.failUpdate()
|
||||
break
|
||||
default:
|
||||
// this.failUpdate();
|
||||
return
|
||||
}
|
||||
}
|
||||
private jumpToPack() {
|
||||
let url: string
|
||||
if (sys.isNative) {
|
||||
if (sys.os == sys.OS.ANDROID) {
|
||||
url = VersionManager.instance.apkStoreUrl
|
||||
} else if (sys.os == sys.OS.IOS) {
|
||||
url = VersionManager.instance.iosStoreUrl
|
||||
}
|
||||
}
|
||||
Logger.info(
|
||||
this,
|
||||
'jumpToPack==androidurl===',
|
||||
VersionManager.instance.apkStoreUrl
|
||||
)
|
||||
Logger.info(
|
||||
this,
|
||||
'jumpToPack==iosStoreUrl===',
|
||||
VersionManager.instance.iosStoreUrl
|
||||
)
|
||||
Logger.info(this, 'jumpToPack=====', url)
|
||||
sys.openURL(url)
|
||||
// cc.game.end();
|
||||
}
|
||||
|
||||
public checkUpdate() {
|
||||
if (this.isUpdating || this.isCheck) {
|
||||
Logger.log(this, 'Checking or updating ...')
|
||||
return
|
||||
}
|
||||
let hotupdateUrlKey: string =
|
||||
VersionManager.Config_Url_Key[this.hotupdateIndex]
|
||||
Logger.log(this, 'checkoutUpdate=====', this.manifestUrl, hotupdateUrlKey)
|
||||
if (!this._am) {
|
||||
this._am = new native.AssetsManager(
|
||||
'',
|
||||
this.storagePath,
|
||||
this.versionCompareHandle.bind(this)
|
||||
)
|
||||
}
|
||||
// this._am.setMaxConcurrentTask(1);
|
||||
let manifestStr: string = ManifestConfig.getManifestStr(hotupdateUrlKey)
|
||||
Logger.log(this, 'checkUpdate=======manifestStr=======', manifestStr)
|
||||
let manifest = new native.Manifest(manifestStr, this.storagePath)
|
||||
this._am.setVerifyCallback(function (filePath, asset) {
|
||||
return true
|
||||
// var md5 = calculateMD5(filePath);
|
||||
// if (md5 === asset.md5)
|
||||
// return true;
|
||||
// else
|
||||
// return false;
|
||||
})
|
||||
this._am.setEventCallback(this.checkCb.bind(this))
|
||||
// 设置事件回调
|
||||
this.isCheck = true
|
||||
this._am.loadLocalManifest(manifest, this.storagePath)
|
||||
this._am.checkUpdate()
|
||||
}
|
||||
//显示强制更新,即更细包面板
|
||||
private showPackUpdateDialog() {
|
||||
CommonTips.showMsg(
|
||||
'有新的版本需要更新,下载后请先卸载,以前的版本,再安装!'
|
||||
)
|
||||
this.jumpToPack()
|
||||
this.showPackUpdateDialog()
|
||||
}
|
||||
|
||||
/**
|
||||
* @param versionA 本地版本 1.0.0
|
||||
* @param versionB 服务器版本 1.0.1
|
||||
* @param return -1需要更新 不用更新
|
||||
*/
|
||||
private versionCompareHandle(versionA, versionB) {
|
||||
var vA = versionA.split('.')
|
||||
var vB = versionB.split('.')
|
||||
Logger.log(
|
||||
this,
|
||||
'versionCompareHandle======',
|
||||
this.key,
|
||||
VersionManager.Config_Key[0]
|
||||
)
|
||||
if (this.key == VersionManager.Config_Key[0]) {
|
||||
Logger.log(this, 'versionCompareHandle22===', versionA, versionB)
|
||||
VersionManager.instance.nowVersion = versionA
|
||||
VersionManager.instance.targetVersion = versionB
|
||||
}
|
||||
this.localBigVersion = parseInt(vA[0])
|
||||
this.remoteBigVersion = parseInt(vB[0])
|
||||
for (var i = 0; i < vA.length; ++i) {
|
||||
var a = parseInt(vA[i])
|
||||
var b = parseInt(vB[i] || 0)
|
||||
if (a === b) {
|
||||
continue
|
||||
} else {
|
||||
return a - b
|
||||
}
|
||||
}
|
||||
if (vB.length > vA.length) {
|
||||
return -1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
private checkCb(event: any) {
|
||||
Logger.log(this, 'checkCb Code: =================' + event.getEventCode())
|
||||
switch (event.getEventCode()) {
|
||||
case native.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
|
||||
Logger.info(this, 'No local manifest file found, hot update skipped.')
|
||||
this.failUpdate()
|
||||
break
|
||||
case native.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
|
||||
case native.EventAssetsManager.ERROR_PARSE_MANIFEST:
|
||||
Logger.info(this, 'Fail to download manifest file, hot update skipped.')
|
||||
this.failUpdate()
|
||||
break
|
||||
case native.EventAssetsManager.ALREADY_UP_TO_DATE:
|
||||
Logger.info(this, 'Already up to date with the latest remote version.')
|
||||
this.alreadyUpToDate()
|
||||
break
|
||||
case native.EventAssetsManager.NEW_VERSION_FOUND:
|
||||
Logger.info(
|
||||
this,
|
||||
'new version found, please try to update.',
|
||||
this.localBigVersion,
|
||||
this.remoteBigVersion
|
||||
)
|
||||
if (
|
||||
this.key == VersionManager.Config_Key[0] &&
|
||||
this.localBigVersion < this.remoteBigVersion
|
||||
) {
|
||||
//更新大版本
|
||||
Logger.info(
|
||||
this,
|
||||
'new version found, please try to update======packupdate=',
|
||||
this.localBigVersion,
|
||||
this.remoteBigVersion
|
||||
)
|
||||
this.showPackUpdateDialog()
|
||||
} else {
|
||||
Logger.info(
|
||||
this,
|
||||
'new version found, please try to update======hotupdate=',
|
||||
this.localBigVersion,
|
||||
this.remoteBigVersion
|
||||
)
|
||||
// this._am.update();
|
||||
this.needUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_NeedUpdate,
|
||||
this.key
|
||||
)
|
||||
}
|
||||
break
|
||||
case native.EventAssetsManager.UPDATE_PROGRESSION:
|
||||
// var currentPercent = event.getPercent();
|
||||
// var totalPercent = event.getPercentByFile();
|
||||
// var fileprocess = event.getDownloadedFiles() + ' / ' + event.getTotalFiles();
|
||||
// var byteprocess = event.getDownloadedBytes() + ' / ' + event.getTotalBytes();
|
||||
Logger.info(
|
||||
this,
|
||||
'UPDATE_PROGRESSION2222==========',
|
||||
this.key,
|
||||
event.getDownloadedBytes(),
|
||||
event.getTotalBytes()
|
||||
)
|
||||
if (event.getTotalBytes() > 0) {
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_Progress,
|
||||
event.getDownloadedBytes(),
|
||||
event.getTotalBytes(),
|
||||
this.key
|
||||
)
|
||||
}
|
||||
break
|
||||
case native.EventAssetsManager.UPDATE_FINISHED:
|
||||
Logger.info(this, 'UPDATE_FINISHED==============')
|
||||
this.finishUpdate(true)
|
||||
break
|
||||
case native.EventAssetsManager.UPDATE_FAILED:
|
||||
Logger.warn(this, 'Update failed==========', event.getMessage())
|
||||
this.failUpdate()
|
||||
break
|
||||
case native.EventAssetsManager.ERROR_UPDATING:
|
||||
let fullFilePath: string = this.storagePath + '/' + event.getAssetId()
|
||||
let tempFilePath: string =
|
||||
this.storagePath + '_temp/' + event.getAssetId()
|
||||
Logger.warn(this, 'fullFilePath====', fullFilePath)
|
||||
Logger.warn(this, 'tempFilePath====', tempFilePath)
|
||||
// jsb.fileUtils.removeFile(tempFilePath);
|
||||
Logger.warn(
|
||||
this,
|
||||
'ERROR_UPDATING=============',
|
||||
event.getAssetId(),
|
||||
event.getMessage()
|
||||
)
|
||||
this.failUpdate()
|
||||
break
|
||||
default:
|
||||
// this.failUpdate();
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
public startUpdate() {
|
||||
if (this.isUpdating) return
|
||||
let localManifest = this._am.getLocalManifest()
|
||||
let remoteManifest = this._am.getRemoteManifest()
|
||||
Logger.log(this, 'startUpdate111===', localManifest.getVersionFileUrl())
|
||||
Logger.log(this, 'startUpdate2222===', localManifest.getManifestFileUrl())
|
||||
Logger.log(this, 'startUpdate3333===', remoteManifest.getVersionFileUrl())
|
||||
Logger.log(this, 'startUpdate4444===', remoteManifest.getManifestFileUrl())
|
||||
this.isUpdating = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_Progress,
|
||||
0,
|
||||
100,
|
||||
this.key
|
||||
)
|
||||
this._am.update()
|
||||
}
|
||||
public checkUpdate() {
|
||||
if (this.isUpdating || this.isCheck) {
|
||||
Logger.log(this, 'Checking or updating ...')
|
||||
return
|
||||
}
|
||||
let hotupdateUrlKey: string =
|
||||
VersionManager.Config_Url_Key[this.hotupdateIndex]
|
||||
Logger.log(this, 'checkoutUpdate=====', this.manifestUrl, hotupdateUrlKey)
|
||||
if (!this._am) {
|
||||
this._am = new native.AssetsManager(
|
||||
'',
|
||||
this.storagePath,
|
||||
this.versionCompareHandle.bind(this)
|
||||
)
|
||||
}
|
||||
// this._am.setMaxConcurrentTask(1);
|
||||
let manifestStr: string = ManifestConfig.getManifestStr(hotupdateUrlKey)
|
||||
Logger.log(this, 'checkUpdate=======manifestStr=======', manifestStr)
|
||||
let manifest = new native.Manifest(manifestStr, this.storagePath)
|
||||
this._am.setVerifyCallback(function(filePath, asset) {
|
||||
return true
|
||||
// var md5 = calculateMD5(filePath);
|
||||
// if (md5 === asset.md5)
|
||||
// return true;
|
||||
// else
|
||||
// return false;
|
||||
})
|
||||
this._am.setEventCallback(this.checkCb.bind(this))
|
||||
// 设置事件回调
|
||||
this.isCheck = true
|
||||
this._am.loadLocalManifest(manifest, this.storagePath)
|
||||
this._am.checkUpdate()
|
||||
}
|
||||
|
||||
public disposeUpdate() {
|
||||
if (this._am) {
|
||||
this._am.setVerifyCallback(null)
|
||||
this._am.setEventCallback(null)
|
||||
}
|
||||
this._am = null
|
||||
this._checkListener = null
|
||||
this.isUpdating = false
|
||||
this.needUpdate = false
|
||||
}
|
||||
/**
|
||||
* @param versionA 本地版本 1.0.0
|
||||
* @param versionB 服务器版本 1.0.1
|
||||
*/
|
||||
private versionCompareHandle(versionA: string, versionB: string) {
|
||||
const vA = versionA.split('.')
|
||||
const vB = versionB.split('.')
|
||||
Logger.log(
|
||||
this,
|
||||
'versionCompareHandle======',
|
||||
this.key,
|
||||
VersionManager.Config_Key[0]
|
||||
)
|
||||
if (this.key == VersionManager.Config_Key[0]) {
|
||||
Logger.log(this, 'versionCompareHandle22===', versionA, versionB)
|
||||
VersionManager.instance.nowVersion = versionA
|
||||
VersionManager.instance.targetVersion = versionB
|
||||
}
|
||||
this.localBigVersion = parseInt(vA[0])
|
||||
this.remoteBigVersion = parseInt(vB[0])
|
||||
for (let i = 0; i < vA.length; ++i) {
|
||||
const a = parseInt(vA[i])
|
||||
const b = parseInt(vB[i] || '0')
|
||||
if (a !== b) return a - b
|
||||
}
|
||||
if (vB.length > vA.length) {
|
||||
return -1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
private failUpdate() {
|
||||
this.disposeUpdate()
|
||||
this.isCheck = false
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_Fail_Update,
|
||||
this.key
|
||||
)
|
||||
}
|
||||
public startUpdate() {
|
||||
if (this.isUpdating) return
|
||||
let localManifest = this._am.getLocalManifest()
|
||||
let remoteManifest = this._am.getRemoteManifest()
|
||||
Logger.log(this, 'startUpdate111===', localManifest.getVersionFileUrl())
|
||||
Logger.log(this, 'startUpdate2222===', localManifest.getManifestFileUrl())
|
||||
Logger.log(this, 'startUpdate3333===', remoteManifest.getVersionFileUrl())
|
||||
Logger.log(this, 'startUpdate4444===', remoteManifest.getManifestFileUrl())
|
||||
this.isUpdating = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_Progress,
|
||||
0,
|
||||
100,
|
||||
this.key
|
||||
)
|
||||
this._am.update()
|
||||
}
|
||||
|
||||
private alreadyUpToDate() {
|
||||
this.disposeUpdate()
|
||||
this.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
this.key
|
||||
)
|
||||
}
|
||||
public disposeUpdate() {
|
||||
if (this._am) {
|
||||
this._am.setVerifyCallback(null)
|
||||
this._am.setEventCallback(null)
|
||||
}
|
||||
this._am = null
|
||||
this._checkListener = null
|
||||
this.isUpdating = false
|
||||
this.needUpdate = false
|
||||
}
|
||||
|
||||
private finishUpdate(needRestart: boolean) {
|
||||
Logger.info(this, '更新完成=====', needRestart)
|
||||
this.disposeUpdate()
|
||||
this.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_Finish_Update,
|
||||
this.key,
|
||||
needRestart
|
||||
)
|
||||
if (false && needRestart) {
|
||||
//暂时不想修 fileUtils 这个报错
|
||||
var searchPaths = '' //jsb.fileUtils.getSearchPaths();暂时注释
|
||||
Logger.info(this, '更新完成====searchPaths======', searchPaths)
|
||||
sys.localStorage.setItem(
|
||||
'HotUpdateSearchPaths',
|
||||
JSON.stringify(searchPaths)
|
||||
)
|
||||
//jsb.fileUtils.setSearchPaths(searchPaths);暂时注释
|
||||
if (this.key == VersionManager.Config_Key[0]) {
|
||||
ResourcePreload.instance.restartGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
private failUpdate() {
|
||||
this.disposeUpdate()
|
||||
this.isCheck = false
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_Fail_Update,
|
||||
this.key
|
||||
)
|
||||
}
|
||||
|
||||
private alreadyUpToDate() {
|
||||
this.disposeUpdate()
|
||||
this.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
this.key
|
||||
)
|
||||
}
|
||||
|
||||
private finishUpdate(needRestart: boolean) {
|
||||
Logger.info(this, '更新完成=====', needRestart)
|
||||
this.disposeUpdate()
|
||||
this.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_Finish_Update,
|
||||
this.key,
|
||||
needRestart
|
||||
)
|
||||
if (false && needRestart) {
|
||||
//暂时不想修 fileUtils 这个报错
|
||||
var searchPaths = '' //jsb.fileUtils.getSearchPaths();暂时注释
|
||||
Logger.info(this, '更新完成====searchPaths======', searchPaths)
|
||||
sys.localStorage.setItem(
|
||||
'HotUpdateSearchPaths',
|
||||
JSON.stringify(searchPaths)
|
||||
)
|
||||
//jsb.fileUtils.setSearchPaths(searchPaths);暂时注释
|
||||
if (this.key == VersionManager.Config_Key[0]) {
|
||||
ResourcePreload.instance.restartGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,160 +1,160 @@
|
||||
import { _decorator } from 'cc'
|
||||
const { ccclass } = _decorator
|
||||
|
||||
import LoadingPrefab from '../uicomponent/LoadingPrefab'
|
||||
import VersionManager from './VersionManager'
|
||||
import { Logger } from './Logger'
|
||||
|
||||
const { ccclass } = _decorator
|
||||
|
||||
@ccclass('HttpClient')
|
||||
export default class HttpClient {
|
||||
public static instance: HttpClient //= new HttpClient();
|
||||
public static instance: HttpClient //= new HttpClient();
|
||||
|
||||
//example
|
||||
// HttpClient.instance.request("http://localhost:8080/haohttp/test", ()=>{
|
||||
// console.log("http 请求 end=============");
|
||||
// }, {"nickName":"jhao", "hh":1, "id":9527});
|
||||
//example
|
||||
// HttpClient.instance.request("http://localhost:8080/haohttp/test", ()=>{
|
||||
// console.log("http 请求 end=============");
|
||||
// }, {"nickName":"jhao", "hh":1, "id":9527});
|
||||
|
||||
private methodType: string = 'GET'
|
||||
private methodType: string = 'GET'
|
||||
|
||||
private responseType: XMLHttpRequestResponseType = 'json'
|
||||
private responseType: XMLHttpRequestResponseType = 'json'
|
||||
|
||||
private xhr: XMLHttpRequest
|
||||
private xhr: XMLHttpRequest
|
||||
|
||||
// --GET or POST
|
||||
public setMethod(method: string = 'GET') {
|
||||
this.methodType = method
|
||||
}
|
||||
// --GET or POST
|
||||
public setMethod(method: string = 'GET') {
|
||||
this.methodType = method
|
||||
}
|
||||
|
||||
public setParams(paramsObj: object): string {
|
||||
let resParams = ''
|
||||
let nowIndex = 1
|
||||
for (const key in paramsObj) {
|
||||
if (paramsObj.hasOwnProperty(key)) {
|
||||
if (nowIndex == 1) {
|
||||
resParams += key + '=' + paramsObj[key]
|
||||
} else {
|
||||
resParams += '&' + key + '=' + paramsObj[key]
|
||||
}
|
||||
nowIndex += 1
|
||||
}
|
||||
}
|
||||
Logger.log(this, 'resParam===============', resParams)
|
||||
return resParams
|
||||
}
|
||||
public setParams(paramsObj: object): string {
|
||||
let resParams = ''
|
||||
let nowIndex = 1
|
||||
for (const key in paramsObj) {
|
||||
if (paramsObj.hasOwnProperty(key)) {
|
||||
if (nowIndex == 1) {
|
||||
resParams += key + '=' + paramsObj[key]
|
||||
} else {
|
||||
resParams += '&' + key + '=' + paramsObj[key]
|
||||
}
|
||||
nowIndex += 1
|
||||
}
|
||||
}
|
||||
Logger.log(this, 'resParam===============', resParams)
|
||||
return resParams
|
||||
}
|
||||
|
||||
public setResponseType(responseType: XMLHttpRequestResponseType) {
|
||||
this.responseType = responseType
|
||||
}
|
||||
public setResponseType(responseType: XMLHttpRequestResponseType) {
|
||||
this.responseType = responseType
|
||||
}
|
||||
|
||||
public setContentType() {}
|
||||
public setContentType() {
|
||||
}
|
||||
|
||||
public request(
|
||||
url: string,
|
||||
callback: Function,
|
||||
params: any = null,
|
||||
timeOut: number = 5 * 1000
|
||||
) {
|
||||
if (params && this.methodType == 'GET') {
|
||||
let getParams: string = this.setParams(params)
|
||||
// getParams = StringUtil:encodeURI(params)
|
||||
getParams = encodeURI(getParams)
|
||||
url += '?' + getParams
|
||||
}
|
||||
this.xhr = new XMLHttpRequest() // http请求 fget
|
||||
//this.xhr = cc.loader.getXMLHttpRequest();
|
||||
let xhr: XMLHttpRequest = this.xhr
|
||||
xhr.responseType = this.responseType
|
||||
xhr.timeout = timeOut
|
||||
// xhr.setRequestHeader("Content-Type", "text/plain");
|
||||
xhr.onreadystatechange = () => {
|
||||
Logger.log(
|
||||
this,
|
||||
'status======',
|
||||
xhr.status,
|
||||
xhr.readyState,
|
||||
xhr.statusText
|
||||
)
|
||||
// if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
let response = xhr.response
|
||||
Logger.log(this, 'http response1============', xhr)
|
||||
try {
|
||||
let testJson = JSON.stringify(response)
|
||||
Logger.log(this, 'http response json============', testJson)
|
||||
if (callback) {
|
||||
callback(true, response)
|
||||
callback = null
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(this, 'http response json=====error=======', error)
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
} else if (xhr.readyState == 4 && xhr.status == 301) {
|
||||
//域名转移
|
||||
Logger.log(
|
||||
this,
|
||||
'http response222============',
|
||||
xhr.getResponseHeader('Location')
|
||||
)
|
||||
// console.log("http response333============", xhr.getAllResponseHeaders());
|
||||
if (HttpClient.instance == null) HttpClient.instance = new HttpClient()
|
||||
HttpClient.instance.request(xhr.getResponseHeader('Location'), callback)
|
||||
} else if (xhr.readyState == 4 && xhr.status == 404) {
|
||||
Logger.log(this, 'http onError============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
} else {
|
||||
Logger.log(
|
||||
this,
|
||||
'onreadystatechange else====',
|
||||
xhr.status,
|
||||
xhr.readyState,
|
||||
xhr.response
|
||||
)
|
||||
if (xhr.readyState == 4) {
|
||||
Logger.log(this, 'http onError else============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.onprogress = () => {
|
||||
Logger.log(
|
||||
this,
|
||||
'http onprogress===',
|
||||
xhr.status,
|
||||
xhr.readyState,
|
||||
xhr.response
|
||||
)
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
Logger.log(this, 'http onError============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
xhr.ontimeout = () => {
|
||||
Logger.log(this, 'http ontimeout============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
Logger.log(this, 'http request==============', url)
|
||||
Logger.log(this, 'http request======method========', this.methodType)
|
||||
Logger.log(this, 'http request======params========', params)
|
||||
xhr.open(this.methodType, url, true)
|
||||
xhr.setRequestHeader('content-type', 'text/plain;charset=UTF-8')
|
||||
xhr.send(params)
|
||||
}
|
||||
public request(
|
||||
url: string,
|
||||
callback: Function,
|
||||
params: any = null,
|
||||
timeOut: number = 5 * 1000
|
||||
) {
|
||||
if (params && this.methodType == 'GET') {
|
||||
let getParams: string = this.setParams(params)
|
||||
// getParams = StringUtil:encodeURI(params)
|
||||
getParams = encodeURI(getParams)
|
||||
url += '?' + getParams
|
||||
}
|
||||
this.xhr = new XMLHttpRequest() // http请求 fget
|
||||
//this.xhr = cc.loader.getXMLHttpRequest();
|
||||
let xhr: XMLHttpRequest = this.xhr
|
||||
xhr.responseType = this.responseType
|
||||
xhr.timeout = timeOut
|
||||
// xhr.setRequestHeader("Content-Type", "text/plain");
|
||||
xhr.onreadystatechange = () => {
|
||||
Logger.log(
|
||||
this,
|
||||
'status======',
|
||||
xhr.status,
|
||||
xhr.readyState,
|
||||
xhr.statusText
|
||||
)
|
||||
// if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
let response = xhr.response
|
||||
Logger.log(this, 'http response1============', xhr)
|
||||
try {
|
||||
let testJson = JSON.stringify(response)
|
||||
Logger.log(this, 'http response json============', testJson)
|
||||
if (callback) {
|
||||
callback(true, response)
|
||||
callback = null
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(this, 'http response json=====error=======', error)
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
} else if (xhr.readyState == 4 && xhr.status == 301) {
|
||||
//域名转移
|
||||
Logger.log(
|
||||
this,
|
||||
'http response222============',
|
||||
xhr.getResponseHeader('Location')
|
||||
)
|
||||
// console.log("http response333============", xhr.getAllResponseHeaders());
|
||||
if (HttpClient.instance == null) HttpClient.instance = new HttpClient()
|
||||
HttpClient.instance.request(xhr.getResponseHeader('Location'), callback)
|
||||
} else if (xhr.readyState == 4 && xhr.status == 404) {
|
||||
Logger.log(this, 'http onError============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
} else {
|
||||
Logger.log(
|
||||
this,
|
||||
'onreadystatechange else====',
|
||||
xhr.status,
|
||||
xhr.readyState,
|
||||
xhr.response
|
||||
)
|
||||
if (xhr.readyState == 4) {
|
||||
Logger.log(this, 'http onError else============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.onprogress = () => {
|
||||
Logger.log(
|
||||
this,
|
||||
'http onprogress===',
|
||||
xhr.status,
|
||||
xhr.readyState,
|
||||
xhr.response
|
||||
)
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
Logger.log(this, 'http onError============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
xhr.ontimeout = () => {
|
||||
Logger.log(this, 'http ontimeout============')
|
||||
if (callback) {
|
||||
callback(false)
|
||||
callback = null
|
||||
}
|
||||
}
|
||||
Logger.log(this, 'http request==============', url)
|
||||
Logger.log(this, 'http request======method========', this.methodType)
|
||||
Logger.log(this, 'http request======params========', params)
|
||||
xhr.open(this.methodType, url, true)
|
||||
xhr.setRequestHeader('content-type', 'text/plain;charset=UTF-8')
|
||||
xhr.send(params)
|
||||
}
|
||||
|
||||
public getInfo(callback: Function = null) {}
|
||||
public getInfo(callback: Function = null) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,63 @@
|
||||
import { sys, _decorator } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
import { sys } from 'cc'
|
||||
|
||||
export default class LocalStorage {
|
||||
public static GamePreFlag: string = 'fengshen-game-HaoLocalStorage'
|
||||
public static GamePreFlag: string = 'fengshen-game-HaoLocalStorage'
|
||||
|
||||
public static setItem(key: string, value: string): void {
|
||||
sys.localStorage.setItem(LocalStorage.GamePreFlag + key, value)
|
||||
}
|
||||
public static setItem(key: string, value: string): void {
|
||||
sys.localStorage.setItem(LocalStorage.GamePreFlag + key, value)
|
||||
}
|
||||
|
||||
public static getItem(key: string): string {
|
||||
return sys.localStorage.getItem(LocalStorage.GamePreFlag + key)
|
||||
}
|
||||
public static getItem(key: string): string {
|
||||
return sys.localStorage.getItem(LocalStorage.GamePreFlag + key)
|
||||
}
|
||||
|
||||
public static removeItem(key: string): void {
|
||||
sys.localStorage.removeItem(LocalStorage.GamePreFlag + key)
|
||||
}
|
||||
public static removeItem(key: string): void {
|
||||
sys.localStorage.removeItem(LocalStorage.GamePreFlag + key)
|
||||
}
|
||||
|
||||
public static getInt(key: string): number {
|
||||
let tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) {
|
||||
result = parseInt(tempValue)
|
||||
}
|
||||
return result
|
||||
}
|
||||
public static getInt(key: string): number {
|
||||
let tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) {
|
||||
result = parseInt(tempValue)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public static setInt(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
public static setInt(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
|
||||
public static getFloat(key: string): number {
|
||||
let tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) {
|
||||
result = parseFloat(tempValue)
|
||||
}
|
||||
return result
|
||||
}
|
||||
public static getFloat(key: string): number {
|
||||
let tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) {
|
||||
result = parseFloat(tempValue)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public static setFloat(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
public static setFloat(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
|
||||
public static getBoolean(key: string): boolean {
|
||||
let temp: number = LocalStorage.getInt(key)
|
||||
if (temp == 1) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
public static getBoolean(key: string): boolean {
|
||||
let temp: number = LocalStorage.getInt(key)
|
||||
if (temp == 1) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public static setBoolean(key: string, value: boolean) {
|
||||
if (value) {
|
||||
LocalStorage.setInt(key, 1)
|
||||
} else {
|
||||
LocalStorage.setInt(key, 0)
|
||||
}
|
||||
}
|
||||
public static setBoolean(key: string, value: boolean) {
|
||||
if (value) {
|
||||
LocalStorage.setInt(key, 1)
|
||||
} else {
|
||||
LocalStorage.setInt(key, 0)
|
||||
}
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
sys.localStorage.clear()
|
||||
}
|
||||
public static clear() {
|
||||
sys.localStorage.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +1,138 @@
|
||||
import { error, _decorator } from 'cc'
|
||||
class LOG_LEVEL_TYPES {
|
||||
public static DEBUG = 0
|
||||
public static LOG = 1
|
||||
public static INFO = 2
|
||||
public static WARN = 3
|
||||
public static ERROR = 4
|
||||
public static DEBUG = 0
|
||||
public static LOG = 1
|
||||
public static INFO = 2
|
||||
public static WARN = 3
|
||||
public static ERROR = 4
|
||||
}
|
||||
|
||||
const Log_Level_Names: Array<string> = ['debug', 'log', 'info', 'warn', 'error']
|
||||
|
||||
export class Logger {
|
||||
public static tag: string = '[HaoJslog]' //可以设置当前游戏的前缀
|
||||
public static LEVEL: number = LOG_LEVEL_TYPES.WARN //当前Logger等级
|
||||
public static Log_Color_Config: Array<string> = [
|
||||
'color:#890;font-size:10px;',
|
||||
'color:#000;font-size:11px;',
|
||||
'color:#09f;font-size:12px;',
|
||||
'color:#f90;font-size:13px;',
|
||||
'color:#f00;font-size:15px;',
|
||||
]
|
||||
private static Terminal_Log: boolean = false
|
||||
public static formatNow() {
|
||||
let date: Date = new Date() //后端返回的时间戳是秒
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
' ' +
|
||||
date.getHours() +
|
||||
':' +
|
||||
date.getMinutes() +
|
||||
':' +
|
||||
date.getSeconds() +
|
||||
':' +
|
||||
date.getMilliseconds()
|
||||
)
|
||||
}
|
||||
private static getLogPreKey(nowLevel: number): string {
|
||||
let str: string =
|
||||
'[' +
|
||||
Logger.formatNow() +
|
||||
'] ' +
|
||||
Logger.tag +
|
||||
' [' +
|
||||
Log_Level_Names[nowLevel] +
|
||||
'] '
|
||||
return str
|
||||
}
|
||||
public static debug(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.DEBUG) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.DEBUG)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
// LogErrorFileUtil.debug(fileStr);
|
||||
if (this.Terminal_Log) {
|
||||
console.log(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr)
|
||||
}
|
||||
}
|
||||
public static log(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.LOG) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.LOG)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
// LogErrorFileUtil.log(fileStr);
|
||||
if (this.Terminal_Log) {
|
||||
console.log(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr) //console.log(str, ...params)
|
||||
}
|
||||
}
|
||||
public static info(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.INFO) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.INFO)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.info(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr)
|
||||
}
|
||||
}
|
||||
public static warn(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.WARN) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.WARN)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.warn(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.warn(fileStr)
|
||||
}
|
||||
}
|
||||
public static error(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.ERROR) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.ERROR)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.error(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.error(fileStr)
|
||||
}
|
||||
}
|
||||
public static tag: string = '[HaoJslog]' //可以设置当前游戏的前缀
|
||||
public static LEVEL: number = LOG_LEVEL_TYPES.WARN //当前Logger等级
|
||||
public static Log_Color_Config: Array<string> = [
|
||||
'color:#890;font-size:10px;',
|
||||
'color:#000;font-size:11px;',
|
||||
'color:#09f;font-size:12px;',
|
||||
'color:#f90;font-size:13px;',
|
||||
'color:#f00;font-size:15px;'
|
||||
]
|
||||
private static Terminal_Log: boolean = false
|
||||
|
||||
public static formatNow() {
|
||||
let date: Date = new Date() //后端返回的时间戳是秒
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
' ' +
|
||||
date.getHours() +
|
||||
':' +
|
||||
date.getMinutes() +
|
||||
':' +
|
||||
date.getSeconds() +
|
||||
':' +
|
||||
date.getMilliseconds()
|
||||
)
|
||||
}
|
||||
|
||||
private static getLogPreKey(nowLevel: number): string {
|
||||
return '[' +
|
||||
Logger.formatNow() +
|
||||
'] ' +
|
||||
Logger.tag +
|
||||
' [' +
|
||||
Log_Level_Names[nowLevel] +
|
||||
'] '
|
||||
}
|
||||
|
||||
public static debug(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.DEBUG) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.DEBUG)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
// LogErrorFileUtil.debug(fileStr);
|
||||
if (this.Terminal_Log) {
|
||||
console.log(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr)
|
||||
}
|
||||
}
|
||||
|
||||
public static log(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.LOG) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.LOG)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
// LogErrorFileUtil.log(fileStr);
|
||||
if (this.Terminal_Log) {
|
||||
console.log(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr) //console.log(str, ...params)
|
||||
}
|
||||
}
|
||||
|
||||
public static info(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.INFO) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.INFO)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.info(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr)
|
||||
}
|
||||
}
|
||||
|
||||
public static warn(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.WARN) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.WARN)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.warn(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.warn(fileStr)
|
||||
}
|
||||
}
|
||||
|
||||
public static error(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.ERROR) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.ERROR)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.error(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.error(fileStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,64 @@
|
||||
import { _decorator, Vec2 } from 'cc'
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export default class MathUtils {
|
||||
/**
|
||||
* 2个点之前的直线距离
|
||||
* @param p1
|
||||
* @param p2
|
||||
*/
|
||||
public static distance(x1: number, y1: number, x2: number, y2: number) {
|
||||
// 设两点A(X1,Y1),B(X2,Y2)
|
||||
// 距离D=(X2-X1)的平方+(Y2-Y1)平方的和开平方
|
||||
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))
|
||||
}
|
||||
/**
|
||||
* 2个点之前的直线距离
|
||||
* @param x1
|
||||
* @param y1
|
||||
* @param x2
|
||||
* @param y2
|
||||
*/
|
||||
public static distance(x1: number, y1: number, x2: number, y2: number) {
|
||||
// 设两点A(X1,Y1),B(X2,Y2)
|
||||
// 距离D=(X2-X1)的平方+(Y2-Y1)平方的和开平方
|
||||
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))
|
||||
}
|
||||
|
||||
/**
|
||||
* 2点间的向量
|
||||
* @param p1
|
||||
* @param p2
|
||||
*/
|
||||
public static sub(p1: Vec2, p2: Vec2) {
|
||||
return new Vec2(p1.x - p2.x, p1.y - p2.y)
|
||||
}
|
||||
/**
|
||||
* 2点间的向量
|
||||
* @param p1
|
||||
* @param p2
|
||||
*/
|
||||
public static sub(p1: Vec2, p2: Vec2) {
|
||||
return new Vec2(p1.x - p2.x, p1.y - p2.y)
|
||||
}
|
||||
|
||||
/**
|
||||
* 弧度转角度
|
||||
* @param radians
|
||||
*/
|
||||
public static radiansToDegrees(radians: number) {
|
||||
return (180 / Math.PI) * radians
|
||||
}
|
||||
/**
|
||||
* 弧度转角度
|
||||
* @param radians
|
||||
*/
|
||||
public static radiansToDegrees(radians: number) {
|
||||
return (180 / Math.PI) * radians
|
||||
}
|
||||
|
||||
/**
|
||||
* 角度转弧度
|
||||
* @param degrees
|
||||
*/
|
||||
public static degreesToRadians(degrees: number) {
|
||||
return (Math.PI * degrees) / 180
|
||||
}
|
||||
/**
|
||||
* 角度转弧度
|
||||
* @param degrees
|
||||
*/
|
||||
public static degreesToRadians(degrees: number) {
|
||||
return (Math.PI * degrees) / 180
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回2点间的弧度
|
||||
* @param startP
|
||||
* @param endP
|
||||
*/
|
||||
public static p2pRad(startP: Vec2, endP: Vec2) {
|
||||
let rad: number = Math.atan2(endP.y - startP.y, endP.x - startP.x)
|
||||
return rad
|
||||
}
|
||||
/**
|
||||
* 返回2点间的弧度
|
||||
* @param startP
|
||||
* @param endP
|
||||
*/
|
||||
public static p2pRad(startP: Vec2, endP: Vec2) {
|
||||
let rad: number = Math.atan2(endP.y - startP.y, endP.x - startP.x)
|
||||
return rad
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对捕鱼鱼的方向特定实现的鱼方向转换
|
||||
* @param rot
|
||||
*/
|
||||
public static rotation2Fish(rot: number) {
|
||||
if (rot >= 0 && rot <= 180) {
|
||||
rot = 180 - rot
|
||||
} else {
|
||||
rot = -180 - rot
|
||||
}
|
||||
return rot
|
||||
}
|
||||
/**
|
||||
* 针对捕鱼鱼的方向特定实现的鱼方向转换
|
||||
* @param rot
|
||||
*/
|
||||
public static rotation2Fish(rot: number) {
|
||||
if (rot >= 0 && rot <= 180) {
|
||||
rot = 180 - rot
|
||||
} else {
|
||||
rot = -180 - rot
|
||||
}
|
||||
return rot
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
import { _decorator, Node, Vec3, Vec2 } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
import { Node, Vec2, Vec3 } from 'cc'
|
||||
import MathUtils from './MathUtils'
|
||||
|
||||
export class MoveHelper {
|
||||
public static _vec3: Vec3 = new Vec3()
|
||||
public static _vec2_0: Vec2 = new Vec2()
|
||||
public static _vec2_1: Vec2 = new Vec2()
|
||||
public static moveNode(
|
||||
moveNode: Node,
|
||||
speed: number,
|
||||
tx: number,
|
||||
ty: number,
|
||||
minSpeed: number = 0.01
|
||||
) {
|
||||
let isMoving: boolean = false
|
||||
let times: number = 0
|
||||
moveNode.getPosition(MoveHelper._vec3)
|
||||
MoveHelper._vec2_0.x = MoveHelper._vec3.x
|
||||
MoveHelper._vec2_0.y = MoveHelper._vec3.y
|
||||
MoveHelper._vec2_1.x = tx
|
||||
MoveHelper._vec2_1.y = ty
|
||||
let rad: number = MathUtils.p2pRad(MoveHelper._vec2_0, MoveHelper._vec2_1)
|
||||
let speedX: number = speed * Math.cos(rad)
|
||||
let speedY: number = speed * Math.sin(rad)
|
||||
if (Math.abs(MoveHelper._vec3.x - tx) > minSpeed) {
|
||||
times = Math.floor(Math.abs(speedX / minSpeed))
|
||||
for (let i = 0; i < times; i++) {
|
||||
if (MoveHelper._vec3.x > tx) {
|
||||
MoveHelper._vec3.x -= minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
} else {
|
||||
MoveHelper._vec3.x += minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
if (Math.abs(MoveHelper._vec3.x - tx) <= minSpeed * 2) {
|
||||
MoveHelper._vec3.x = tx
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
}
|
||||
isMoving = true
|
||||
}
|
||||
if (Math.abs(MoveHelper._vec3.y - ty) > minSpeed) {
|
||||
times = Math.floor(Math.abs(speedY / minSpeed))
|
||||
for (let j = 0; j < times; j++) {
|
||||
if (MoveHelper._vec3.y > ty) {
|
||||
MoveHelper._vec3.y -= minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
} else {
|
||||
MoveHelper._vec3.y += minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
if (Math.abs(MoveHelper._vec3.x - ty) <= minSpeed * 2) {
|
||||
MoveHelper._vec3.y = ty
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
}
|
||||
isMoving = true
|
||||
}
|
||||
return isMoving
|
||||
}
|
||||
public static _vec3: Vec3 = new Vec3()
|
||||
public static _vec2_0: Vec2 = new Vec2()
|
||||
public static _vec2_1: Vec2 = new Vec2()
|
||||
|
||||
public static moveNode(
|
||||
moveNode: Node,
|
||||
speed: number,
|
||||
tx: number,
|
||||
ty: number,
|
||||
minSpeed: number = 0.01
|
||||
) {
|
||||
let isMoving: boolean = false
|
||||
let times: number = 0
|
||||
moveNode.getPosition(MoveHelper._vec3)
|
||||
MoveHelper._vec2_0.x = MoveHelper._vec3.x
|
||||
MoveHelper._vec2_0.y = MoveHelper._vec3.y
|
||||
MoveHelper._vec2_1.x = tx
|
||||
MoveHelper._vec2_1.y = ty
|
||||
let rad: number = MathUtils.p2pRad(MoveHelper._vec2_0, MoveHelper._vec2_1)
|
||||
let speedX: number = speed * Math.cos(rad)
|
||||
let speedY: number = speed * Math.sin(rad)
|
||||
if (Math.abs(MoveHelper._vec3.x - tx) > minSpeed) {
|
||||
times = Math.floor(Math.abs(speedX / minSpeed))
|
||||
for (let i = 0; i < times; i++) {
|
||||
if (MoveHelper._vec3.x > tx) {
|
||||
MoveHelper._vec3.x -= minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
} else {
|
||||
MoveHelper._vec3.x += minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
if (Math.abs(MoveHelper._vec3.x - tx) <= minSpeed * 2) {
|
||||
MoveHelper._vec3.x = tx
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
}
|
||||
isMoving = true
|
||||
}
|
||||
if (Math.abs(MoveHelper._vec3.y - ty) > minSpeed) {
|
||||
times = Math.floor(Math.abs(speedY / minSpeed))
|
||||
for (let j = 0; j < times; j++) {
|
||||
if (MoveHelper._vec3.y > ty) {
|
||||
MoveHelper._vec3.y -= minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
} else {
|
||||
MoveHelper._vec3.y += minSpeed
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
if (Math.abs(MoveHelper._vec3.x - ty) <= minSpeed * 2) {
|
||||
MoveHelper._vec3.y = ty
|
||||
moveNode.setPosition(MoveHelper._vec3)
|
||||
}
|
||||
}
|
||||
isMoving = true
|
||||
}
|
||||
return isMoving
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { AssetManager, Prefab, _decorator } from 'cc'
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
import { _decorator, AssetManager, Prefab } from 'cc'
|
||||
import { Logger } from './Logger'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('PrefabLoader')
|
||||
export default class PrefabLoader {
|
||||
private static isLoading: boolean = false
|
||||
private static isLoading: boolean = false
|
||||
|
||||
public static loadPrefab(url: string, callback: Function) {
|
||||
if (this.isLoading) return
|
||||
this.isLoading = true
|
||||
AssetManager.instance.resources.load(
|
||||
url,
|
||||
Prefab,
|
||||
(error: Error, loadedResource) => {
|
||||
if (error) {
|
||||
Logger.warn(this, '载入Prefab失败, 原因:', url, error.message)
|
||||
return
|
||||
}
|
||||
if (!(loadedResource instanceof Prefab)) {
|
||||
Logger.warn(this, '你载入的不是Prefab, 你做了什么事?')
|
||||
return
|
||||
}
|
||||
callback(loadedResource)
|
||||
this.isLoading = false
|
||||
}
|
||||
)
|
||||
}
|
||||
public static loadPrefab(url: string, callback: Function) {
|
||||
if (this.isLoading) return
|
||||
this.isLoading = true
|
||||
AssetManager.instance.resources.load(
|
||||
url,
|
||||
Prefab,
|
||||
(error: Error, loadedResource) => {
|
||||
if (error) {
|
||||
Logger.warn(this, '载入Prefab失败, 原因:', url, error.message)
|
||||
return
|
||||
}
|
||||
if (!(loadedResource instanceof Prefab)) {
|
||||
Logger.warn(this, '你载入的不是Prefab, 你做了什么事?')
|
||||
return
|
||||
}
|
||||
callback(loadedResource)
|
||||
this.isLoading = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
import { Vec2, _decorator } from 'cc'
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export default class RandomUtil {
|
||||
//随机minNum到maxNum的数字 (包含maxNum)
|
||||
public static nextInt(minNum: number, maxNum: number) {
|
||||
return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum)
|
||||
}
|
||||
//随机minNum到maxNum的数字 (包含maxNum)
|
||||
public static nextInt(minNum: number, maxNum: number) {
|
||||
return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum)
|
||||
}
|
||||
|
||||
public static nextNumber(minNum: number, maxNum: number) {
|
||||
return Math.random() * (maxNum - minNum) + minNum
|
||||
}
|
||||
public static nextNumber(minNum: number, maxNum: number) {
|
||||
return Math.random() * (maxNum - minNum) + minNum
|
||||
}
|
||||
|
||||
public static nextSign() {
|
||||
let temp = Math.random()
|
||||
if (temp < 0.5) {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
public static nextSign() {
|
||||
let temp = Math.random()
|
||||
if (temp < 0.5) {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
public static nextBoolean() {
|
||||
let temp = Math.random()
|
||||
if (temp < 0.5) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
public static nextBoolean() {
|
||||
let temp = Math.random()
|
||||
return temp < 0.5;
|
||||
|
||||
public static randomArr(nowArr: Array<any>, needNum: number) {
|
||||
let tempArr: Array<any> = nowArr.concat()
|
||||
let resultArr: Array<any> = []
|
||||
for (let index = 0; index < needNum; index++) {
|
||||
if (tempArr.length <= 0) {
|
||||
break
|
||||
}
|
||||
let randomIndex: number = RandomUtil.nextInt(0, tempArr.length - 1)
|
||||
resultArr.push(tempArr.splice(randomIndex, 1)[0])
|
||||
}
|
||||
return resultArr
|
||||
}
|
||||
}
|
||||
|
||||
public static randomItem(nowArr: Array<any>) {
|
||||
return this.randomArr(nowArr, 1)[0]
|
||||
}
|
||||
public static randomArr(nowArr: Array<any>, needNum: number) {
|
||||
let tempArr: Array<any> = nowArr.concat()
|
||||
let resultArr: Array<any> = []
|
||||
for (let index = 0; index < needNum; index++) {
|
||||
if (tempArr.length <= 0) {
|
||||
break
|
||||
}
|
||||
let randomIndex: number = RandomUtil.nextInt(0, tempArr.length - 1)
|
||||
resultArr.push(tempArr.splice(randomIndex, 1)[0])
|
||||
}
|
||||
return resultArr
|
||||
}
|
||||
|
||||
public static randomP(left: number, right: number, up: number, down: number) {
|
||||
let randomX: number = RandomUtil.nextNumber(left, right)
|
||||
let randomY: number = RandomUtil.nextNumber(up, down)
|
||||
return new Vec2(randomX, randomY)
|
||||
}
|
||||
public static randomItem(nowArr: Array<any>) {
|
||||
return this.randomArr(nowArr, 1)[0]
|
||||
}
|
||||
|
||||
public static randomP(left: number, right: number, up: number, down: number) {
|
||||
let randomX: number = RandomUtil.nextNumber(left, right)
|
||||
let randomY: number = RandomUtil.nextNumber(up, down)
|
||||
return new Vec2(randomX, randomY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,436 +1,428 @@
|
||||
import {
|
||||
_decorator,
|
||||
Node,
|
||||
Material,
|
||||
Color,
|
||||
UIRenderer,
|
||||
Vec2,
|
||||
UITransform,
|
||||
} from 'cc'
|
||||
import { Color, Material, Node, UIRenderer, UITransform, Vec2 } from 'cc'
|
||||
import ShaderMaterialPrefab from '../../game/prefab/ShaderMaterialPrefab'
|
||||
import { Logger } from './Logger'
|
||||
|
||||
export default class ShaderHelper {
|
||||
/**
|
||||
* 清除所有shader
|
||||
* @param showNode
|
||||
* @param material
|
||||
*/
|
||||
public static clearAllEffect(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).default
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 清除所有shader
|
||||
* @param showNode
|
||||
* @param material
|
||||
*/
|
||||
public static clearAllEffect(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).default
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片灰白程度
|
||||
* @param showNode
|
||||
* @param material
|
||||
* @param grayLevel [0.0, 1.0]
|
||||
*/
|
||||
public static setGrayEffect(
|
||||
showNode: Node,
|
||||
grayLevel: number = 1,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).grayMaterial
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('grayLevel', grayLevel)
|
||||
renderComponent.setMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('grayLevel', grayLevel)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 设置图片灰白程度
|
||||
* @param showNode
|
||||
* @param grayLevel
|
||||
* @param material
|
||||
*/
|
||||
public static setGrayEffect(
|
||||
showNode: Node,
|
||||
grayLevel: number = 1,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).grayMaterial
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('grayLevel', grayLevel)
|
||||
renderComponent.setMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('grayLevel', grayLevel)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放变灰过程动画
|
||||
*/
|
||||
public static showGrayMv(showNode: Node) {
|
||||
let grayValue: number = 0.5
|
||||
let intervalId = setInterval(() => {
|
||||
grayValue += 0.01
|
||||
if (grayValue >= 1) {
|
||||
grayValue = 1
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
if (showNode) {
|
||||
ShaderHelper.setGrayEffect(showNode, grayValue)
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
/**
|
||||
* 播放变灰过程动画
|
||||
*/
|
||||
public static showGrayMv(showNode: Node) {
|
||||
let grayValue: number = 0.5
|
||||
let intervalId = setInterval(() => {
|
||||
grayValue += 0.01
|
||||
if (grayValue >= 1) {
|
||||
grayValue = 1
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
if (showNode) {
|
||||
ShaderHelper.setGrayEffect(showNode, grayValue)
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片老化
|
||||
* @param showNode
|
||||
* @param grayLevel [0.0, 1.0]
|
||||
* @param material
|
||||
*/
|
||||
public static setOldPhotoEffect(
|
||||
showNode: Node,
|
||||
grayLevel: number = 1,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).oldPhoto
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('oldLevel', grayLevel)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('oldLevel', grayLevel)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 设置图片老化
|
||||
* @param showNode
|
||||
* @param grayLevel
|
||||
* @param material
|
||||
*/
|
||||
public static setOldPhotoEffect(
|
||||
showNode: Node,
|
||||
grayLevel: number = 1,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).oldPhoto
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('oldLevel', grayLevel)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('oldLevel', grayLevel)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放变灰过程动画
|
||||
*/
|
||||
public static showOldPhotoMv(showNode: Node) {
|
||||
let grayValue: number = 0
|
||||
let intervalId = setInterval(() => {
|
||||
grayValue += 0.01
|
||||
if (grayValue >= 1) {
|
||||
grayValue = 1
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
if (showNode) {
|
||||
ShaderHelper.setOldPhotoEffect(showNode, grayValue)
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
/**
|
||||
* 播放变灰过程动画
|
||||
*/
|
||||
public static showOldPhotoMv(showNode: Node) {
|
||||
let grayValue: number = 0
|
||||
let intervalId = setInterval(() => {
|
||||
grayValue += 0.01
|
||||
if (grayValue >= 1) {
|
||||
grayValue = 1
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
if (showNode) {
|
||||
ShaderHelper.setOldPhotoEffect(showNode, grayValue)
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加内发光特效
|
||||
* showNode:要增加特效的节点或者他的子节点
|
||||
* material:发光特效材质
|
||||
* materialParam: {}
|
||||
* materialParam.glowColor:cc.v4(r,g,b,a) 颜色rbga值的结构体
|
||||
* materialParam.glowColorSize:这里为约束一下值发光宽度值在 [0.0, 0.1] 因为 0.1+ 之后的效果可能不明显,也可以自己尝试修改,个人测试感觉0.01效果最佳
|
||||
* materialParam.glowThreshold:这里为约束一下值发光阈值值在 [0.0, 0.5] 因为 0.5+ 之后的效果可能就是其他效果,个人感觉0.1效果最佳
|
||||
*/
|
||||
public static setGlowInner(
|
||||
showNode: Node,
|
||||
materialParam: any,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).glowInner
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('glowColor', materialParam.glowColor)
|
||||
material.setProperty('glowColorSize', materialParam.glowColorSize)
|
||||
material.setProperty('glowThreshold', materialParam.glowThreshold)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('glowColor', materialParam.glowColor)
|
||||
material.setProperty('glowColorSize', materialParam.glowColorSize)
|
||||
material.setProperty('glowThreshold', materialParam.glowThreshold)
|
||||
renderComponent.setMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 增加内发光特效
|
||||
* showNode:要增加特效的节点或者他的子节点
|
||||
* material:发光特效材质
|
||||
* materialParam: {}
|
||||
* materialParam.glowColor:cc.v4(r,g,b,a) 颜色rbga值的结构体
|
||||
* materialParam.glowColorSize:这里为约束一下值发光宽度值在 [0.0, 0.1] 因为 0.1+ 之后的效果可能不明显,也可以自己尝试修改,个人测试感觉0.01效果最佳
|
||||
* materialParam.glowThreshold:这里为约束一下值发光阈值值在 [0.0, 0.5] 因为 0.5+ 之后的效果可能就是其他效果,个人感觉0.1效果最佳
|
||||
*/
|
||||
public static setGlowInner(
|
||||
showNode: Node,
|
||||
materialParam: any,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).glowInner
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('glowColor', materialParam.glowColor)
|
||||
material.setProperty('glowColorSize', materialParam.glowColorSize)
|
||||
material.setProperty('glowThreshold', materialParam.glowThreshold)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('glowColor', materialParam.glowColor)
|
||||
material.setProperty('glowColorSize', materialParam.glowColorSize)
|
||||
material.setProperty('glowThreshold', materialParam.glowThreshold)
|
||||
renderComponent.setMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不同颜色的发光
|
||||
* @param showNode
|
||||
* @param color
|
||||
*/
|
||||
public static setCommonGlowInner(showNode: Node, color: Color = Color.WHITE) {
|
||||
this.setGlowInner(showNode, {
|
||||
glowColor: color,
|
||||
glowColorSize: 0.015,
|
||||
glowThreshold: 0.1,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 设置不同颜色的发光
|
||||
* @param showNode
|
||||
* @param color
|
||||
*/
|
||||
public static setCommonGlowInner(showNode: Node, color: Color = Color.WHITE) {
|
||||
this.setGlowInner(showNode, {
|
||||
glowColor: color,
|
||||
glowColorSize: 0.015,
|
||||
glowThreshold: 0.1
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放被攻击闪烁过程动画
|
||||
*/
|
||||
public static showFlash(showNode: Node, totalFlashTimes: number = 1) {
|
||||
let timeCount: number = 0
|
||||
let color: Color = Color.WHITE
|
||||
let flashTimes: number = 0
|
||||
let intervalId = setInterval(() => {
|
||||
timeCount += 1
|
||||
if (timeCount % 50 == 0) {
|
||||
let tempCount: number = timeCount / 50
|
||||
if (tempCount % 2 == 0) {
|
||||
color.a = 100
|
||||
this.setGlowInner(showNode, {
|
||||
glowColor: color,
|
||||
glowColorSize: 0.1,
|
||||
glowThreshold: 0,
|
||||
})
|
||||
} else {
|
||||
flashTimes++
|
||||
this.setGlowInner(showNode, {
|
||||
glowColor: color,
|
||||
glowColorSize: 0,
|
||||
glowThreshold: 0,
|
||||
})
|
||||
if (flashTimes > totalFlashTimes) {
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
/**
|
||||
* 播放被攻击闪烁过程动画
|
||||
*/
|
||||
public static showFlash(showNode: Node, totalFlashTimes: number = 1) {
|
||||
let timeCount: number = 0
|
||||
let color: Color = Color.WHITE
|
||||
let flashTimes: number = 0
|
||||
let intervalId = setInterval(() => {
|
||||
timeCount += 1
|
||||
if (timeCount % 50 == 0) {
|
||||
let tempCount: number = timeCount / 50
|
||||
if (tempCount % 2 == 0) {
|
||||
color.a = 100
|
||||
this.setGlowInner(showNode, {
|
||||
glowColor: color,
|
||||
glowColorSize: 0.1,
|
||||
glowThreshold: 0
|
||||
})
|
||||
} else {
|
||||
flashTimes++
|
||||
this.setGlowInner(showNode, {
|
||||
glowColor: color,
|
||||
glowColorSize: 0,
|
||||
glowThreshold: 0
|
||||
})
|
||||
if (flashTimes > totalFlashTimes) {
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 马赛克
|
||||
* @param showNode
|
||||
* @param materialParam
|
||||
* @param material
|
||||
*/
|
||||
public static setMosaic(
|
||||
showNode: Node,
|
||||
materialParam: any,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).mosaic
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('xBlockCount', materialParam.xBlockCount)
|
||||
material.setProperty('yBlockCount', materialParam.yBlockCount)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('xBlockCount', materialParam.xBlockCount)
|
||||
material.setProperty('yBlockCount', materialParam.yBlockCount)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 马赛克
|
||||
* @param showNode
|
||||
* @param materialParam
|
||||
* @param material
|
||||
*/
|
||||
public static setMosaic(
|
||||
showNode: Node,
|
||||
materialParam: any,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).mosaic
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('xBlockCount', materialParam.xBlockCount)
|
||||
material.setProperty('yBlockCount', materialParam.yBlockCount)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('xBlockCount', materialParam.xBlockCount)
|
||||
material.setProperty('yBlockCount', materialParam.yBlockCount)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放被攻击闪烁过程动画
|
||||
*/
|
||||
public static showMosaicMv(showNode: Node, callback: Function = null) {
|
||||
let masaicTimes: number = 500
|
||||
let intervalId = setInterval(() => {
|
||||
masaicTimes -= 2
|
||||
this.setMosaic(showNode, {
|
||||
xBlockCount: masaicTimes,
|
||||
yBlockCount: masaicTimes,
|
||||
})
|
||||
if (masaicTimes <= 30) {
|
||||
clearInterval(intervalId)
|
||||
if (callback) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
/**
|
||||
* 播放被攻击闪烁过程动画
|
||||
*/
|
||||
public static showMosaicMv(showNode: Node, callback: Function = null) {
|
||||
let masaicTimes: number = 500
|
||||
let intervalId = setInterval(() => {
|
||||
masaicTimes -= 2
|
||||
this.setMosaic(showNode, {
|
||||
xBlockCount: masaicTimes,
|
||||
yBlockCount: masaicTimes
|
||||
})
|
||||
if (masaicTimes <= 30) {
|
||||
clearInterval(intervalId)
|
||||
if (callback) {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置圆角剪切
|
||||
* @param showNode
|
||||
* @param roundCornerRadius [0, 1]
|
||||
*/
|
||||
public static setRoundCornerCrop(
|
||||
showNode: Node,
|
||||
roundCornerRadius: number = 0.1,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).roundCornerCrop
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
// material.setProperty("roundCornerRadius", roundCornerRadius);
|
||||
material.setProperty('xRadius', roundCornerRadius)
|
||||
material.setProperty('yRadius', roundCornerRadius)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
// material.setProperty("roundCornerRadius", roundCornerRadius);
|
||||
material.setProperty('xRadius', roundCornerRadius)
|
||||
material.setProperty('yRadius', roundCornerRadius)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 设置圆角剪切
|
||||
* @param showNode
|
||||
* @param roundCornerRadius
|
||||
* @param material
|
||||
*/
|
||||
public static setRoundCornerCrop(
|
||||
showNode: Node,
|
||||
roundCornerRadius: number = 0.1,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).roundCornerCrop
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
// material.setProperty("roundCornerRadius", roundCornerRadius);
|
||||
material.setProperty('xRadius', roundCornerRadius)
|
||||
material.setProperty('yRadius', roundCornerRadius)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
// material.setProperty("roundCornerRadius", roundCornerRadius);
|
||||
material.setProperty('xRadius', roundCornerRadius)
|
||||
material.setProperty('yRadius', roundCornerRadius)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置闪光
|
||||
* @param showNode
|
||||
* @param lightColor 光颜色
|
||||
* @param lightWidth 光的宽度
|
||||
* @param lightAngle 光的角度
|
||||
* @param enableGradient
|
||||
* @param cropAlpha
|
||||
* @param enableFog
|
||||
* @param material
|
||||
*/
|
||||
public static setFlashLight(
|
||||
showNode: Node,
|
||||
lightColor: Color,
|
||||
lightWidth: number,
|
||||
lightAngle: number = 0,
|
||||
enableGradient: boolean = true,
|
||||
cropAlpha: boolean = true,
|
||||
enableFog: boolean = false,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).flashLight
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('lightColor', lightColor)
|
||||
material.setProperty('lightWidth', lightWidth)
|
||||
material.setProperty('lightAngle', lightAngle)
|
||||
material.setProperty('enableGradient', enableGradient ? 1 : 0)
|
||||
material.setProperty('cropAlpha', cropAlpha ? 1 : 0)
|
||||
material.setProperty('enableFog', enableFog ? 1 : 0)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('lightColor', lightColor)
|
||||
material.setProperty('lightWidth', lightWidth)
|
||||
material.setProperty('lightAngle', lightAngle)
|
||||
material.setProperty('enableGradient', enableGradient ? 1 : 0)
|
||||
material.setProperty('cropAlpha', cropAlpha ? 1 : 0)
|
||||
material.setProperty('enableFog', enableFog ? 1 : 0)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 设置闪光
|
||||
* @param showNode
|
||||
* @param lightColor 光颜色
|
||||
* @param lightWidth 光的宽度
|
||||
* @param lightAngle 光的角度
|
||||
* @param enableGradient
|
||||
* @param cropAlpha
|
||||
* @param enableFog
|
||||
* @param material
|
||||
*/
|
||||
public static setFlashLight(
|
||||
showNode: Node,
|
||||
lightColor: Color,
|
||||
lightWidth: number,
|
||||
lightAngle: number = 0,
|
||||
enableGradient: boolean = true,
|
||||
cropAlpha: boolean = true,
|
||||
enableFog: boolean = false,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).flashLight
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('lightColor', lightColor)
|
||||
material.setProperty('lightWidth', lightWidth)
|
||||
material.setProperty('lightAngle', lightAngle)
|
||||
material.setProperty('enableGradient', enableGradient ? 1 : 0)
|
||||
material.setProperty('cropAlpha', cropAlpha ? 1 : 0)
|
||||
material.setProperty('enableFog', enableFog ? 1 : 0)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
material.setProperty('lightColor', lightColor)
|
||||
material.setProperty('lightWidth', lightWidth)
|
||||
material.setProperty('lightAngle', lightAngle)
|
||||
material.setProperty('enableGradient', enableGradient ? 1 : 0)
|
||||
material.setProperty('cropAlpha', cropAlpha ? 1 : 0)
|
||||
material.setProperty('enableFog', enableFog ? 1 : 0)
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家升级shader动画
|
||||
* @param showNode
|
||||
* @param callback
|
||||
*/
|
||||
public static showFlashLightMv(showNode: Node, callback: Function = null) {
|
||||
let nowClor: Color = new Color(0, 0, 0, 255)
|
||||
let colorIndex: number = 0
|
||||
let lightAngle: number = 0
|
||||
let intervalId = setInterval(() => {
|
||||
if (colorIndex == 0) {
|
||||
nowClor.r = nowClor.r + 2
|
||||
if (nowClor.r >= 255) {
|
||||
colorIndex += 1
|
||||
}
|
||||
} else if (colorIndex == 1) {
|
||||
nowClor.g = nowClor.g + 2
|
||||
if (nowClor.g >= 255) {
|
||||
colorIndex += 1
|
||||
}
|
||||
} else {
|
||||
nowClor.b = nowClor.b + 2
|
||||
if (nowClor.b >= 255) {
|
||||
clearInterval(intervalId)
|
||||
ShaderHelper.clearAllEffect(showNode)
|
||||
if (callback) {
|
||||
callback()
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
lightAngle += 1
|
||||
this.setFlashLight(showNode, nowClor, 1, lightAngle)
|
||||
}, 1)
|
||||
}
|
||||
/**
|
||||
* 玩家升级shader动画
|
||||
* @param showNode
|
||||
* @param callback
|
||||
*/
|
||||
public static showFlashLightMv(showNode: Node, callback: Function = null) {
|
||||
let nowClor: Color = new Color(0, 0, 0, 255)
|
||||
let colorIndex: number = 0
|
||||
let lightAngle: number = 0
|
||||
let intervalId = setInterval(() => {
|
||||
if (colorIndex == 0) {
|
||||
nowClor.r = nowClor.r + 2
|
||||
if (nowClor.r >= 255) {
|
||||
colorIndex += 1
|
||||
}
|
||||
} else if (colorIndex == 1) {
|
||||
nowClor.g = nowClor.g + 2
|
||||
if (nowClor.g >= 255) {
|
||||
colorIndex += 1
|
||||
}
|
||||
} else {
|
||||
nowClor.b = nowClor.b + 2
|
||||
if (nowClor.b >= 255) {
|
||||
clearInterval(intervalId)
|
||||
ShaderHelper.clearAllEffect(showNode)
|
||||
if (callback) {
|
||||
callback()
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
lightAngle += 1
|
||||
this.setFlashLight(showNode, nowClor, 1, lightAngle)
|
||||
}, 1)
|
||||
}
|
||||
|
||||
public static setFlag(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).flag
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
public static setFlag(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).flag
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置高斯模糊
|
||||
* @param showNode
|
||||
* @param material
|
||||
*/
|
||||
public static setGaussian(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).gaussian
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
let tran = renderComponent.node.getComponent(UITransform)
|
||||
material.setProperty(
|
||||
'textureSize',
|
||||
new Vec2(tran.contentSize.width, tran.contentSize.height)
|
||||
)
|
||||
renderComponent.setMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
let tran = renderComponent.node.getComponent(UITransform)
|
||||
material.setProperty(
|
||||
'textureSize',
|
||||
new Vec2(tran.contentSize.width, tran.contentSize.height)
|
||||
)
|
||||
// material.setProperty("textureSize", cc.v2(showNode.width, showNode.height));
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 设置高斯模糊
|
||||
* @param showNode
|
||||
* @param material
|
||||
*/
|
||||
public static setGaussian(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(
|
||||
ShaderMaterialPrefab
|
||||
).gaussian
|
||||
) {
|
||||
showNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
let tran = renderComponent.node.getComponent(UITransform)
|
||||
material.setProperty(
|
||||
'textureSize',
|
||||
new Vec2(tran.contentSize.width, tran.contentSize.height)
|
||||
)
|
||||
renderComponent.setMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode
|
||||
.getComponents(UIRenderer)
|
||||
.forEach((renderComponent: UIRenderer) => {
|
||||
let tran = renderComponent.node.getComponent(UITransform)
|
||||
material.setProperty(
|
||||
'textureSize',
|
||||
new Vec2(tran.contentSize.width, tran.contentSize.height)
|
||||
)
|
||||
// material.setProperty("textureSize", cc.v2(showNode.width, showNode.height));
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,139 +1,140 @@
|
||||
import { sys, _decorator } from 'cc'
|
||||
import { sys } from 'cc'
|
||||
import ManifestConfig from '../config/ManifestConfig'
|
||||
import EventManager from './EventManager'
|
||||
import HotUpdate from './HotUpdate'
|
||||
|
||||
export default class VersionManager {
|
||||
public static instance: VersionManager = new VersionManager()
|
||||
public static instance: VersionManager = new VersionManager()
|
||||
|
||||
public static Config_Game_Name: Array<string> = ['游戏大厅']
|
||||
public static Config_Game_Name: Array<string> = ['游戏大厅']
|
||||
|
||||
//热更文件下载来后存放文件夹
|
||||
public static Config_Key: Array<string> = ['main-remote-asset']
|
||||
//热更文件下载来后存放文件夹
|
||||
public static Config_Key: Array<string> = ['main-remote-asset']
|
||||
|
||||
private static Config_ManifestName: string = 'project.manifest'
|
||||
private static Config_ManifestName: string = 'project.manifest'
|
||||
|
||||
public static Config_Url_Key: Array<string> = ['main']
|
||||
public static Config_Url_Key: Array<string> = ['main']
|
||||
|
||||
public iosStoreUrl: string = ''
|
||||
public apkStoreUrl: string = ''
|
||||
public iosStoreUrl: string = ''
|
||||
public apkStoreUrl: string = ''
|
||||
|
||||
public nowVersion: string = ManifestConfig.version //网页显示版本号,如果是热更会替换改值
|
||||
public targetVersion: string = '1.0.0'
|
||||
public nowVersion: string = ManifestConfig.version //网页显示版本号,如果是热更会替换改值
|
||||
public targetVersion: string = '1.0.0'
|
||||
|
||||
public isOpenHotUpdate: boolean = true //是否打开热更
|
||||
public isOpenHotUpdate: boolean = true //是否打开热更
|
||||
|
||||
private hotUpdateList: Array<HotUpdate> = []
|
||||
private hotUpdateList: Array<HotUpdate> = []
|
||||
|
||||
private noUpdateIndex: number = -1 //
|
||||
private noUpdateIndex: number = -1 //
|
||||
|
||||
public init() {
|
||||
this.reInitAll()
|
||||
}
|
||||
public reInitAll() {
|
||||
this.releaseAll()
|
||||
for (let i = 0; i < VersionManager.Config_Key.length; i++) {
|
||||
this.reInit(i)
|
||||
}
|
||||
}
|
||||
public init() {
|
||||
this.reInitAll()
|
||||
}
|
||||
|
||||
public releaseAll() {
|
||||
for (let i = 0; i < VersionManager.Config_Key.length; i++) {
|
||||
if (this.hotUpdateList[i]) {
|
||||
this.hotUpdateList[i].disposeUpdate()
|
||||
}
|
||||
}
|
||||
}
|
||||
public reInitAll() {
|
||||
this.releaseAll()
|
||||
for (let i = 0; i < VersionManager.Config_Key.length; i++) {
|
||||
this.reInit(i)
|
||||
}
|
||||
}
|
||||
|
||||
public reInit(index: number) {
|
||||
if (!this.hotUpdateList[index]) {
|
||||
this.hotUpdateList[index] = new HotUpdate()
|
||||
}
|
||||
this.hotUpdateList[index].init(
|
||||
index,
|
||||
VersionManager.Config_Key[index],
|
||||
VersionManager.Config_ManifestName
|
||||
)
|
||||
if (!this.isOpenHotUpdate) {
|
||||
this.hotUpdateList[index].isCheck = true
|
||||
this.hotUpdateList[index].isFinishUpdate = true
|
||||
}
|
||||
}
|
||||
public releaseAll() {
|
||||
for (let i = 0; i < VersionManager.Config_Key.length; i++) {
|
||||
if (this.hotUpdateList[i]) {
|
||||
this.hotUpdateList[i].disposeUpdate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public checkUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (sys.isNative) {
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
//在大厅热更,不用子游戏热更了
|
||||
hotUpdate.isCheck = true
|
||||
hotUpdate.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
VersionManager.Config_Key[keyIndex]
|
||||
)
|
||||
} else {
|
||||
hotUpdate.checkUpdate()
|
||||
}
|
||||
} else {
|
||||
hotUpdate.isCheck = true
|
||||
hotUpdate.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
VersionManager.Config_Key[keyIndex]
|
||||
)
|
||||
}
|
||||
} else {
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
VersionManager.Config_Key[keyIndex]
|
||||
)
|
||||
}
|
||||
}
|
||||
public reInit(index: number) {
|
||||
if (!this.hotUpdateList[index]) {
|
||||
this.hotUpdateList[index] = new HotUpdate()
|
||||
}
|
||||
this.hotUpdateList[index].init(
|
||||
index,
|
||||
VersionManager.Config_Key[index],
|
||||
VersionManager.Config_ManifestName
|
||||
)
|
||||
if (!this.isOpenHotUpdate) {
|
||||
this.hotUpdateList[index].isCheck = true
|
||||
this.hotUpdateList[index].isFinishUpdate = true
|
||||
}
|
||||
}
|
||||
|
||||
public startUpdate(keyIndex: number) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
hotUpdate.startUpdate()
|
||||
}
|
||||
public checkUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (sys.isNative) {
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
//在大厅热更,不用子游戏热更了
|
||||
hotUpdate.isCheck = true
|
||||
hotUpdate.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
VersionManager.Config_Key[keyIndex]
|
||||
)
|
||||
} else {
|
||||
hotUpdate.checkUpdate()
|
||||
}
|
||||
} else {
|
||||
hotUpdate.isCheck = true
|
||||
hotUpdate.isFinishUpdate = true
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
VersionManager.Config_Key[keyIndex]
|
||||
)
|
||||
}
|
||||
} else {
|
||||
EventManager.instance.dispatchEvent(
|
||||
HotUpdate.Event_On_ALREADY_UP_TO_DATE,
|
||||
VersionManager.Config_Key[keyIndex]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public isCheck(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
return true
|
||||
}
|
||||
return hotUpdate.isCheck
|
||||
}
|
||||
return true
|
||||
}
|
||||
public startUpdate(keyIndex: number) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
hotUpdate.startUpdate()
|
||||
}
|
||||
|
||||
public needUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
return false
|
||||
}
|
||||
return hotUpdate.needUpdate
|
||||
}
|
||||
return false
|
||||
}
|
||||
public isCheck(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
return true
|
||||
}
|
||||
return hotUpdate.isCheck
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public isUpdating(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
return hotUpdate.isUpdating
|
||||
}
|
||||
return false
|
||||
}
|
||||
public needUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
return false
|
||||
}
|
||||
return hotUpdate.needUpdate
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isFinishUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
return true
|
||||
}
|
||||
return hotUpdate.isFinishUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
public isUpdating(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
return hotUpdate.isUpdating
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isFinishUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
let hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex == this.noUpdateIndex) {
|
||||
return true
|
||||
}
|
||||
return hotUpdate.isFinishUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { _decorator } from 'cc'
|
||||
export class GameConfig {
|
||||
public static GameName: string = 'FishSingle'
|
||||
public static GameName: string = 'FishSingle'
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
import { _decorator } from 'cc'
|
||||
export default class GameEvent {}
|
||||
export default class GameEvent {
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
16
package.json
16
package.json
@@ -6,5 +6,19 @@
|
||||
"version": "3.8.2"
|
||||
},
|
||||
"_sourceId": "f769f6bf-2fe4-41a7-b7ad-f38f57e2d1b9",
|
||||
"_storeId": "2898572b8dca79ebffc4f4584f234c2c"
|
||||
"_storeId": "2898572b8dca79ebffc4f4584f234c2c",
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.0.2",
|
||||
"@eslint/js": "^9.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
||||
"acorn": "^8.11.3",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-standard-with-typescript": "^43.0.1",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-n": "^16.6.2",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"globals": "^15.0.0",
|
||||
"prettier": "^3.2.5",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
|
||||
1832
pnpm-lock.yaml
generated
1832
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"__version__": "3.0.5",
|
||||
"game": {
|
||||
"name": "未知游戏",
|
||||
"name": "UNKNOW GAME",
|
||||
"app_id": "UNKNOW",
|
||||
"c_id": "0"
|
||||
},
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
"customSplash": {
|
||||
"id": "customSplash",
|
||||
"label": "customSplash",
|
||||
"enable": true,
|
||||
"enable": false,
|
||||
"customSplash": {
|
||||
"complete": false,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?sid=5d73e8c847732207609c34c0adf271fb"
|
||||
"form": "https://creator-api.cocos.com/api/form/show?"
|
||||
}
|
||||
},
|
||||
"removeSplash": {
|
||||
"id": "removeSplash",
|
||||
"label": "removeSplash",
|
||||
"enable": true,
|
||||
"enable": false,
|
||||
"removeSplash": {
|
||||
"complete": true,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?sid=5d73e8c847732207609c34c0adf271fb"
|
||||
"complete": false,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user