i
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "1f75e345-9236-4518-97a3-9862de267a19",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "1f75e345-9236-4518-97a3-9862de267a19",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "79470a7f-2ce8-48ce-86d3-e2662124378f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "79470a7f-2ce8-48ce-86d3-e2662124378f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CommonEvent')
|
||||
export default class CommonEvent {
|
||||
public static Event_FrameUpdate: string = 'Event_FrameUpdate'
|
||||
public static Event_ConnectTimeOut: string = 'Event_ConnectTimeOut'
|
||||
public static Event_ResourceLoader: string = 'Event_ResourceLoader'
|
||||
public static Event_CheckUpdate: string = 'Event_CheckUpdate'
|
||||
public static Event_Scene_Switch: string = 'Event_Scene_Switch'
|
||||
}
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CommonEvent')
|
||||
export default class CommonEvent {
|
||||
public static Event_FrameUpdate: string = 'Event_FrameUpdate'
|
||||
public static Event_ConnectTimeOut: string = 'Event_ConnectTimeOut'
|
||||
public static Event_ResourceLoader: string = 'Event_ResourceLoader'
|
||||
public static Event_CheckUpdate: string = 'Event_CheckUpdate'
|
||||
public static Event_Scene_Switch: string = 'Event_Scene_Switch'
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "76f96525-e455-4a24-9d2b-27a0cb2fdfd2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "76f96525-e455-4a24-9d2b-27a0cb2fdfd2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import DateUtil from '../utils/DateUtil'
|
||||
|
||||
import NetConfig from './NetConfig'
|
||||
|
||||
export default class ManifestConfig {
|
||||
public static packageUrl: string = ''
|
||||
public static remoteManifestUrl: string = ''
|
||||
public static remoteVersionUrl: string = ''
|
||||
public static version: string = '1.0.0' // 更新包要更新这里
|
||||
public static assets: object = {}
|
||||
public static searchPaths: Array<any> = []
|
||||
|
||||
public static getManifestStr(key: string) {
|
||||
const obj: {
|
||||
packageUrl?: string
|
||||
remoteManifestUrl?: string
|
||||
remoteVersionUrl?: string
|
||||
version?: string
|
||||
assets?: object
|
||||
searchPaths?: Array<any>
|
||||
} = {}
|
||||
obj.packageUrl = `${NetConfig.hotupdateUrl}/hotupdate/${key}/`
|
||||
obj.remoteManifestUrl = `${NetConfig.hotupdateUrl}/hotupdate/${key}/project.manifest?t=${DateUtil.now()}`
|
||||
obj.remoteManifestUrl = `${
|
||||
NetConfig.hotupdateUrl
|
||||
}/hotupdate/${key}/project.manifest?t=${DateUtil.now()}`
|
||||
obj.remoteVersionUrl = `${NetConfig.hotupdateUrl}/hotupdate/${key}/version.manifest?t=${DateUtil.now()}`
|
||||
obj.remoteVersionUrl = `${
|
||||
NetConfig.hotupdateUrl
|
||||
}/hotupdate/${key}/version.manifest?t=${DateUtil.now()}`
|
||||
obj.version = ManifestConfig.version
|
||||
obj.assets = {}
|
||||
obj.searchPaths = []
|
||||
return JSON.stringify(obj)
|
||||
}
|
||||
}
|
||||
import DateUtil from '../utils/DateUtil'
|
||||
|
||||
import NetConfig from './NetConfig'
|
||||
|
||||
export default class ManifestConfig {
|
||||
public static packageUrl: string = ''
|
||||
public static remoteManifestUrl: string = ''
|
||||
public static remoteVersionUrl: string = ''
|
||||
public static version: string = '1.0.0' // 更新包要更新这里
|
||||
public static assets: object = {}
|
||||
public static searchPaths: Array<any> = []
|
||||
|
||||
public static getManifestStr(key: string) {
|
||||
const obj: {
|
||||
packageUrl?: string
|
||||
remoteManifestUrl?: string
|
||||
remoteVersionUrl?: string
|
||||
version?: string
|
||||
assets?: object
|
||||
searchPaths?: Array<any>
|
||||
} = {}
|
||||
obj.packageUrl = `${NetConfig.hotupdateUrl}/hotupdate/${key}/`
|
||||
obj.remoteManifestUrl = `${NetConfig.hotupdateUrl}/hotupdate/${key}/project.manifest?t=${DateUtil.now()}`
|
||||
obj.remoteManifestUrl = `${
|
||||
NetConfig.hotupdateUrl
|
||||
}/hotupdate/${key}/project.manifest?t=${DateUtil.now()}`
|
||||
obj.remoteVersionUrl = `${NetConfig.hotupdateUrl}/hotupdate/${key}/version.manifest?t=${DateUtil.now()}`
|
||||
obj.remoteVersionUrl = `${
|
||||
NetConfig.hotupdateUrl
|
||||
}/hotupdate/${key}/version.manifest?t=${DateUtil.now()}`
|
||||
obj.version = ManifestConfig.version
|
||||
obj.assets = {}
|
||||
obj.searchPaths = []
|
||||
return JSON.stringify(obj)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "711d7240-649f-4cb4-9d0d-06e13979eb98",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "711d7240-649f-4cb4-9d0d-06e13979eb98",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
import { AudioClip } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
|
||||
export default class MusicConfig {
|
||||
public static musicKey2Path: Map<string, string> = new Map<string, string>() // 资源预加载路径
|
||||
|
||||
public static musicKey2Cache: Map<string, AudioClip> = new Map<string, AudioClip>() // 资源加载后cache路径
|
||||
|
||||
public static init() {
|
||||
if (typeof GameConfig.GameName === 'undefined' || GameConfig.GameName === null) {
|
||||
console.error('GameConfig.GameName 未配置!')
|
||||
return
|
||||
}
|
||||
|
||||
const musicConfig = {
|
||||
background_1: 'music/background_1',
|
||||
background_2: 'music/background_2',
|
||||
background_3: 'music/background_3',
|
||||
deadfish_1: 'music/deadfish_1',
|
||||
deadfish_2: 'music/deadfish_2',
|
||||
deadfish_3: 'music/deadfish_3',
|
||||
deadfish_4: 'music/deadfish_4',
|
||||
deadfish_5: 'music/deadfish_5',
|
||||
deadfish_6: 'music/deadfish_6',
|
||||
deadfish_7: 'music/deadfish_7',
|
||||
deadfish_8: 'music/deadfish_8',
|
||||
deadfish_9: 'music/deadfish_9',
|
||||
deadfish_10: 'music/deadfish_10',
|
||||
deadfish_11: 'music/deadfish_11',
|
||||
deadfish_12: 'music/deadfish_12',
|
||||
deadfish_13: 'music/deadfish_13',
|
||||
deadfish_14: 'music/deadfish_14',
|
||||
deadfish_15: 'music/deadfish_15',
|
||||
deadfish_16: 'music/deadfish_16',
|
||||
deadfish_17: 'music/deadfish_17',
|
||||
deadfish_18: 'music/deadfish_18',
|
||||
deadfish_19: 'music/deadfish_19',
|
||||
deadfish_20: 'music/deadfish_20',
|
||||
deadfish_21: 'music/deadfish_21',
|
||||
deadfish_22: 'music/deadfish_22',
|
||||
deadfish_23: 'music/deadfish_23',
|
||||
deadfish_24: 'music/deadfish_24',
|
||||
deadfish_25: 'music/deadfish_25',
|
||||
deadfish_26: 'music/deadfish_26',
|
||||
deadfish_27: 'music/deadfish_27',
|
||||
deadfish_28: 'music/deadfish_28',
|
||||
deadfish_29: 'music/deadfish_29',
|
||||
fire: 'music/fire',
|
||||
}
|
||||
// 音乐要预加载的配置
|
||||
for (const key in musicConfig) {
|
||||
if (Object.prototype.hasOwnProperty.call(musicConfig, key)) {
|
||||
const path = `${GameConfig.GameName}/${musicConfig[key]}`
|
||||
MusicConfig.musicKey2Path.set(key, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
import { AudioClip } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
|
||||
export default class MusicConfig {
|
||||
public static musicKey2Path: Map<string, string> = new Map<string, string>() // 资源预加载路径
|
||||
|
||||
public static musicKey2Cache: Map<string, AudioClip> = new Map<string, AudioClip>() // 资源加载后cache路径
|
||||
|
||||
public static init() {
|
||||
if (typeof GameConfig.GameName === 'undefined' || GameConfig.GameName === null) {
|
||||
console.error('GameConfig.GameName 未配置!')
|
||||
return
|
||||
}
|
||||
|
||||
const musicConfig = {
|
||||
background_1: 'music/background_1',
|
||||
background_2: 'music/background_2',
|
||||
background_3: 'music/background_3',
|
||||
deadfish_1: 'music/deadfish_1',
|
||||
deadfish_2: 'music/deadfish_2',
|
||||
deadfish_3: 'music/deadfish_3',
|
||||
deadfish_4: 'music/deadfish_4',
|
||||
deadfish_5: 'music/deadfish_5',
|
||||
deadfish_6: 'music/deadfish_6',
|
||||
deadfish_7: 'music/deadfish_7',
|
||||
deadfish_8: 'music/deadfish_8',
|
||||
deadfish_9: 'music/deadfish_9',
|
||||
deadfish_10: 'music/deadfish_10',
|
||||
deadfish_11: 'music/deadfish_11',
|
||||
deadfish_12: 'music/deadfish_12',
|
||||
deadfish_13: 'music/deadfish_13',
|
||||
deadfish_14: 'music/deadfish_14',
|
||||
deadfish_15: 'music/deadfish_15',
|
||||
deadfish_16: 'music/deadfish_16',
|
||||
deadfish_17: 'music/deadfish_17',
|
||||
deadfish_18: 'music/deadfish_18',
|
||||
deadfish_19: 'music/deadfish_19',
|
||||
deadfish_20: 'music/deadfish_20',
|
||||
deadfish_21: 'music/deadfish_21',
|
||||
deadfish_22: 'music/deadfish_22',
|
||||
deadfish_23: 'music/deadfish_23',
|
||||
deadfish_24: 'music/deadfish_24',
|
||||
deadfish_25: 'music/deadfish_25',
|
||||
deadfish_26: 'music/deadfish_26',
|
||||
deadfish_27: 'music/deadfish_27',
|
||||
deadfish_28: 'music/deadfish_28',
|
||||
deadfish_29: 'music/deadfish_29',
|
||||
fire: 'music/fire',
|
||||
}
|
||||
// 音乐要预加载的配置
|
||||
for (const key in musicConfig) {
|
||||
if (Object.prototype.hasOwnProperty.call(musicConfig, key)) {
|
||||
const path = `${GameConfig.GameName}/${musicConfig[key]}`
|
||||
MusicConfig.musicKey2Path.set(key, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "92bd7fa0-c97e-4b6f-b518-d1d4d73c03f5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "92bd7fa0-c97e-4b6f-b518-d1d4d73c03f5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default class NetConfig {
|
||||
public static hotupdateUrl: string = 'http://localhost:33/hotupdate'
|
||||
}
|
||||
export default class NetConfig {
|
||||
public static hotupdateUrl: string = 'http://localhost:33/hotupdate'
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4e758c3c-41e2-4fe7-a0ea-43fe6be9b381",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4e758c3c-41e2-4fe7-a0ea-43fe6be9b381",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "9c2b477c-5efb-432e-8d18-08cc17a2e103",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "9c2b477c-5efb-432e-8d18-08cc17a2e103",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
import { Component, Label, Node, Vec3, _decorator, instantiate, tween } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CommonTips')
|
||||
export default class CommonTips extends Component {
|
||||
public static TipsZorderIndex: number = 999
|
||||
@property({ type: Label })
|
||||
txtContent: Label | null = null
|
||||
|
||||
private tips: string = ''
|
||||
private static showingNameList: Array<string> = []
|
||||
|
||||
onLoad() {}
|
||||
|
||||
start() {
|
||||
tween(this.node)
|
||||
.by(1.5, { position: new Vec3(0, 100, 0) })
|
||||
.to(0.2, { /* opacity: 0 */ scale: Vec3.ZERO })
|
||||
.call(() => {
|
||||
this.node.destroy()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
const index: number = CommonTips.showingNameList.indexOf(this.tips)
|
||||
CommonTips.showingNameList.splice(index, 1)
|
||||
this.unscheduleAllCallbacks()
|
||||
}
|
||||
|
||||
public static showMsg(msg: string, parentNode: Node = null) {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/CommonTips`,
|
||||
(loadedResource) => {
|
||||
parentNode = parentNode || DialogBase.GetRootCanvas()
|
||||
if (!CommonTips.showingNameList.includes(msg)) CommonTips.showingNameList.push(msg)
|
||||
|
||||
const dialogNode = instantiate(loadedResource)
|
||||
dialogNode.setPosition(0, 0)
|
||||
const dialogScript: CommonTips = dialogNode.getComponent(CommonTips)
|
||||
dialogScript.tips = msg
|
||||
dialogScript.txtContent.string = msg
|
||||
parentNode.insertChild(dialogNode, CommonTips.TipsZorderIndex)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
import { Component, Label, Node, Vec3, _decorator, instantiate, tween } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('CommonTips')
|
||||
export default class CommonTips extends Component {
|
||||
public static TipsZorderIndex: number = 999
|
||||
@property({ type: Label })
|
||||
txtContent: Label | null = null
|
||||
|
||||
private tips: string = ''
|
||||
private static showingNameList: Array<string> = []
|
||||
|
||||
onLoad() {}
|
||||
|
||||
start() {
|
||||
tween(this.node)
|
||||
.by(1.5, { position: new Vec3(0, 100, 0) })
|
||||
.to(0.2, { /* opacity: 0 */ scale: Vec3.ZERO })
|
||||
.call(() => {
|
||||
this.node.destroy()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
const index: number = CommonTips.showingNameList.indexOf(this.tips)
|
||||
CommonTips.showingNameList.splice(index, 1)
|
||||
this.unscheduleAllCallbacks()
|
||||
}
|
||||
|
||||
public static showMsg(msg: string, parentNode: Node = null) {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/CommonTips`,
|
||||
(loadedResource) => {
|
||||
parentNode = parentNode || DialogBase.GetRootCanvas()
|
||||
if (!CommonTips.showingNameList.includes(msg)) CommonTips.showingNameList.push(msg)
|
||||
|
||||
const dialogNode = instantiate(loadedResource)
|
||||
dialogNode.setPosition(0, 0)
|
||||
const dialogScript: CommonTips = dialogNode.getComponent(CommonTips)
|
||||
dialogScript.tips = msg
|
||||
dialogScript.txtContent.string = msg
|
||||
parentNode.insertChild(dialogNode, CommonTips.TipsZorderIndex)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4524f0ef-319a-4f20-9d62-fe359bbcbc71",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4524f0ef-319a-4f20-9d62-fe359bbcbc71",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import { Component, Node, Prefab, Widget, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('DarkLayer')
|
||||
export default class DarkLayer extends Component {
|
||||
private static prefab: Prefab
|
||||
|
||||
onLoad() {
|
||||
this.getComponent(Widget).target = DialogBase.GetRootCanvas()
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/DarkLayer`,
|
||||
(loadedResource) => {
|
||||
DarkLayer.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static getDarkLayer() {
|
||||
const dialogNode: Node = instantiate(DarkLayer.prefab)
|
||||
return dialogNode
|
||||
}
|
||||
}
|
||||
import { Component, Node, Prefab, Widget, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('DarkLayer')
|
||||
export default class DarkLayer extends Component {
|
||||
private static prefab: Prefab
|
||||
|
||||
onLoad() {
|
||||
this.getComponent(Widget).target = DialogBase.GetRootCanvas()
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/DarkLayer`,
|
||||
(loadedResource) => {
|
||||
DarkLayer.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static getDarkLayer() {
|
||||
const dialogNode: Node = instantiate(DarkLayer.prefab)
|
||||
return dialogNode
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4fa811bd-9cd5-4ac6-ad87-d68f4a41dcdf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4fa811bd-9cd5-4ac6-ad87-d68f4a41dcdf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
import { Component, Node, Widget, _decorator } from 'cc'
|
||||
|
||||
import { UIRoot } from '../../game/utils/UIRoot'
|
||||
|
||||
import DarkLayer from './DarkLayer'
|
||||
|
||||
const { ccclass } = _decorator
|
||||
|
||||
@ccclass('DialogBase')
|
||||
export default class DialogBase extends Component {
|
||||
private static LocalZOrder: number = 5
|
||||
private darkLayer: Node | null = null
|
||||
|
||||
// private static _canvas: Node;
|
||||
public static GetRootCanvas(): Node {
|
||||
// if(DialogBase._canvas == null)
|
||||
// DialogBase._canvas = director.getScene().getChildByName('Canvas');
|
||||
// return DialogBase._canvas;
|
||||
return UIRoot.Instance.node
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
DialogBase.LocalZOrder += 1
|
||||
const closeLayer: Node = this.node.getChildByName('closeLayer')
|
||||
if (closeLayer) {
|
||||
const closeLayerWidget: Widget = closeLayer.getComponent(Widget)
|
||||
if (closeLayerWidget) {
|
||||
closeLayerWidget.target = DialogBase.GetRootCanvas()
|
||||
closeLayerWidget.left = 0
|
||||
closeLayerWidget.right = 0
|
||||
closeLayerWidget.top = 0
|
||||
closeLayerWidget.bottom = 0
|
||||
}
|
||||
}
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
onLoadMe() {}
|
||||
|
||||
start(isPlayMv: boolean = false) {
|
||||
this.darkLayer = DarkLayer.getDarkLayer()
|
||||
this.node.insertChild(this.darkLayer, 0) // this.node.addChild(this.darkLayer, -1);
|
||||
if (isPlayMv) this.node.setScale(0, 0)
|
||||
else this.onStartMe()
|
||||
}
|
||||
|
||||
onStartMe() {}
|
||||
|
||||
onClickClose() {
|
||||
this.node.destroy()
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
this.onUpdateMe(dt)
|
||||
}
|
||||
|
||||
onUpdateMe(dt) {}
|
||||
|
||||
onDestroy() {
|
||||
DialogBase.LocalZOrder -= 1
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onDestroyMe() {}
|
||||
}
|
||||
import { Component, Node, Widget, _decorator } from 'cc'
|
||||
|
||||
import { UIRoot } from '../../game/utils/UIRoot'
|
||||
|
||||
import DarkLayer from './DarkLayer'
|
||||
|
||||
const { ccclass } = _decorator
|
||||
|
||||
@ccclass('DialogBase')
|
||||
export default class DialogBase extends Component {
|
||||
private static LocalZOrder: number = 5
|
||||
private darkLayer: Node | null = null
|
||||
|
||||
// private static _canvas: Node;
|
||||
public static GetRootCanvas(): Node {
|
||||
// if(DialogBase._canvas == null)
|
||||
// DialogBase._canvas = director.getScene().getChildByName('Canvas');
|
||||
// return DialogBase._canvas;
|
||||
return UIRoot.Instance.node
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
DialogBase.LocalZOrder += 1
|
||||
const closeLayer: Node = this.node.getChildByName('closeLayer')
|
||||
if (closeLayer) {
|
||||
const closeLayerWidget: Widget = closeLayer.getComponent(Widget)
|
||||
if (closeLayerWidget) {
|
||||
closeLayerWidget.target = DialogBase.GetRootCanvas()
|
||||
closeLayerWidget.left = 0
|
||||
closeLayerWidget.right = 0
|
||||
closeLayerWidget.top = 0
|
||||
closeLayerWidget.bottom = 0
|
||||
}
|
||||
}
|
||||
this.onLoadMe()
|
||||
}
|
||||
|
||||
onLoadMe() {}
|
||||
|
||||
start(isPlayMv: boolean = false) {
|
||||
this.darkLayer = DarkLayer.getDarkLayer()
|
||||
this.node.insertChild(this.darkLayer, 0) // this.node.addChild(this.darkLayer, -1);
|
||||
if (isPlayMv) this.node.setScale(0, 0)
|
||||
else this.onStartMe()
|
||||
}
|
||||
|
||||
onStartMe() {}
|
||||
|
||||
onClickClose() {
|
||||
this.node.destroy()
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
this.onUpdateMe(dt)
|
||||
}
|
||||
|
||||
onUpdateMe(dt) {}
|
||||
|
||||
onDestroy() {
|
||||
DialogBase.LocalZOrder -= 1
|
||||
this.onDestroyMe()
|
||||
}
|
||||
|
||||
onDestroyMe() {}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1fc7cf08-75c2-4ec4-b4c0-6f27eb483210",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1fc7cf08-75c2-4ec4-b4c0-6f27eb483210",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
import { Component, Node, Prefab, Quat, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingPrefab')
|
||||
export default class LoadingPrefab extends Component {
|
||||
public static instance: Node
|
||||
private static prefab: Prefab
|
||||
public static LoadingZorderIndex: number = 99
|
||||
@property({ type: Node })
|
||||
loadingSp: Node | null = null
|
||||
|
||||
private _quatCache: Quat
|
||||
private _vec3Cache: Vec3
|
||||
|
||||
onLoad() {
|
||||
this._quatCache = new Quat()
|
||||
this._vec3Cache = new Vec3()
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
public static close() {
|
||||
if (!LoadingPrefab.instance) return
|
||||
|
||||
LoadingPrefab.instance.removeFromParent()
|
||||
LoadingPrefab.instance.destroy()
|
||||
LoadingPrefab.instance = null
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/LoadingPrefab`,
|
||||
(loadedResource) => {
|
||||
LoadingPrefab.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private static createLoadingPrefab(parentNode: Node = null) {
|
||||
const dialogNode: Node = instantiate(LoadingPrefab.prefab)
|
||||
LoadingPrefab.instance = dialogNode
|
||||
if (!parentNode) parentNode = DialogBase.GetRootCanvas()
|
||||
|
||||
parentNode.insertChild(dialogNode, LoadingPrefab.LoadingZorderIndex)
|
||||
dialogNode.setPosition(0, 0)
|
||||
}
|
||||
|
||||
public static async show(parentNode: Node = null) {
|
||||
if (LoadingPrefab.instance) return
|
||||
if (!LoadingPrefab.prefab) await LoadingPrefab.preLoad()
|
||||
|
||||
this.createLoadingPrefab(parentNode)
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
this.loadingSp.getRotation(this._quatCache)
|
||||
Quat.toEuler(this._vec3Cache, this._quatCache)
|
||||
this._vec3Cache.z += 10
|
||||
this.loadingSp.setRotationFromEuler(this._vec3Cache)
|
||||
if (this._vec3Cache.z >= 360) this.loadingSp.getRotation(Quat.IDENTITY)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
LoadingPrefab.instance = null
|
||||
LoadingPrefab.prefab = null
|
||||
}
|
||||
}
|
||||
import { Component, Node, Prefab, Quat, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingPrefab')
|
||||
export default class LoadingPrefab extends Component {
|
||||
public static instance: Node
|
||||
private static prefab: Prefab
|
||||
public static LoadingZorderIndex: number = 99
|
||||
@property({ type: Node })
|
||||
loadingSp: Node | null = null
|
||||
|
||||
private _quatCache: Quat
|
||||
private _vec3Cache: Vec3
|
||||
|
||||
onLoad() {
|
||||
this._quatCache = new Quat()
|
||||
this._vec3Cache = new Vec3()
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
public static close() {
|
||||
if (!LoadingPrefab.instance) return
|
||||
|
||||
LoadingPrefab.instance.removeFromParent()
|
||||
LoadingPrefab.instance.destroy()
|
||||
LoadingPrefab.instance = null
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/LoadingPrefab`,
|
||||
(loadedResource) => {
|
||||
LoadingPrefab.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private static createLoadingPrefab(parentNode: Node = null) {
|
||||
const dialogNode: Node = instantiate(LoadingPrefab.prefab)
|
||||
LoadingPrefab.instance = dialogNode
|
||||
if (!parentNode) parentNode = DialogBase.GetRootCanvas()
|
||||
|
||||
parentNode.insertChild(dialogNode, LoadingPrefab.LoadingZorderIndex)
|
||||
dialogNode.setPosition(0, 0)
|
||||
}
|
||||
|
||||
public static async show(parentNode: Node = null) {
|
||||
if (LoadingPrefab.instance) return
|
||||
if (!LoadingPrefab.prefab) await LoadingPrefab.preLoad()
|
||||
|
||||
this.createLoadingPrefab(parentNode)
|
||||
}
|
||||
|
||||
update(dt) {
|
||||
this.loadingSp.getRotation(this._quatCache)
|
||||
Quat.toEuler(this._vec3Cache, this._quatCache)
|
||||
this._vec3Cache.z += 10
|
||||
this.loadingSp.setRotationFromEuler(this._vec3Cache)
|
||||
if (this._vec3Cache.z >= 360) this.loadingSp.getRotation(Quat.IDENTITY)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
LoadingPrefab.instance = null
|
||||
LoadingPrefab.prefab = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "172559f4-6da9-4c5d-a0b4-af9f5116f021",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "172559f4-6da9-4c5d-a0b4-af9f5116f021",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
import { Component, Node, Prefab, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
import Progress from './Progress'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingScenePrefab')
|
||||
export default class LoadingScenePrefab extends Component {
|
||||
public static instance: Node
|
||||
private static prefab: Prefab
|
||||
public static LoadingZorderIndex: number = 99
|
||||
@property({ type: Node })
|
||||
private progressNode: Node | null = null
|
||||
|
||||
onLoad() {}
|
||||
|
||||
start() {}
|
||||
|
||||
public updateProgress(completedCount: number, totalCount: number, item: any = null) {
|
||||
this.progressNode
|
||||
.getComponent(Progress)
|
||||
.updateProgress(completedCount, totalCount, '消耗流量,预下载所有"鱼"类中,请耐心等待...')
|
||||
}
|
||||
|
||||
public static updateLoading(completedCount: number, totalCount: number, item: any = null) {
|
||||
if (LoadingScenePrefab.instance) {
|
||||
const nodeTs: LoadingScenePrefab =
|
||||
LoadingScenePrefab.instance.getComponent(LoadingScenePrefab)
|
||||
if (nodeTs) nodeTs.updateProgress(completedCount, totalCount, item)
|
||||
}
|
||||
}
|
||||
|
||||
private static createPrefab(parentNode: Node = null) {
|
||||
const dialogNode: Node = instantiate(LoadingScenePrefab.prefab)
|
||||
LoadingScenePrefab.instance = dialogNode
|
||||
if (!parentNode) parentNode = DialogBase.GetRootCanvas()
|
||||
|
||||
parentNode.insertChild(dialogNode, LoadingScenePrefab.LoadingZorderIndex)
|
||||
dialogNode.setPosition(0, 0)
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/LoadingScenePrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
LoadingScenePrefab.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static close() {
|
||||
if (!LoadingScenePrefab.instance) return
|
||||
|
||||
LoadingScenePrefab.instance.destroy()
|
||||
LoadingScenePrefab.instance = null
|
||||
}
|
||||
|
||||
public static async show(parentNode: Node = null) {
|
||||
if (LoadingScenePrefab.instance) return
|
||||
if (!LoadingScenePrefab.prefab) await LoadingScenePrefab.preLoad()
|
||||
|
||||
this.createPrefab(parentNode)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
LoadingScenePrefab.instance = null
|
||||
LoadingScenePrefab.prefab = null
|
||||
}
|
||||
}
|
||||
import { Component, Node, Prefab, _decorator, instantiate } from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
import DialogBase from './DialogBase'
|
||||
import Progress from './Progress'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('LoadingScenePrefab')
|
||||
export default class LoadingScenePrefab extends Component {
|
||||
public static instance: Node
|
||||
private static prefab: Prefab
|
||||
public static LoadingZorderIndex: number = 99
|
||||
@property({ type: Node })
|
||||
private progressNode: Node | null = null
|
||||
|
||||
onLoad() {}
|
||||
|
||||
start() {}
|
||||
|
||||
public updateProgress(completedCount: number, totalCount: number, item: any = null) {
|
||||
this.progressNode
|
||||
.getComponent(Progress)
|
||||
.updateProgress(completedCount, totalCount, '消耗流量,预下载所有"鱼"类中,请耐心等待...')
|
||||
}
|
||||
|
||||
public static updateLoading(completedCount: number, totalCount: number, item: any = null) {
|
||||
if (LoadingScenePrefab.instance) {
|
||||
const nodeTs: LoadingScenePrefab =
|
||||
LoadingScenePrefab.instance.getComponent(LoadingScenePrefab)
|
||||
if (nodeTs) nodeTs.updateProgress(completedCount, totalCount, item)
|
||||
}
|
||||
}
|
||||
|
||||
private static createPrefab(parentNode: Node = null) {
|
||||
const dialogNode: Node = instantiate(LoadingScenePrefab.prefab)
|
||||
LoadingScenePrefab.instance = dialogNode
|
||||
if (!parentNode) parentNode = DialogBase.GetRootCanvas()
|
||||
|
||||
parentNode.insertChild(dialogNode, LoadingScenePrefab.LoadingZorderIndex)
|
||||
dialogNode.setPosition(0, 0)
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/LoadingScenePrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
LoadingScenePrefab.prefab = loadedResource
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static close() {
|
||||
if (!LoadingScenePrefab.instance) return
|
||||
|
||||
LoadingScenePrefab.instance.destroy()
|
||||
LoadingScenePrefab.instance = null
|
||||
}
|
||||
|
||||
public static async show(parentNode: Node = null) {
|
||||
if (LoadingScenePrefab.instance) return
|
||||
if (!LoadingScenePrefab.prefab) await LoadingScenePrefab.preLoad()
|
||||
|
||||
this.createPrefab(parentNode)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
LoadingScenePrefab.instance = null
|
||||
LoadingScenePrefab.prefab = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e2e744b0-b723-4151-8de6-a2c222b8fe29",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e2e744b0-b723-4151-8de6-a2c222b8fe29",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
import {
|
||||
AssetManager,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
Component,
|
||||
Prefab,
|
||||
_decorator,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import MusicConfig from '../config/MusicConfig'
|
||||
import LocalStorage from '../utils/LocalStorage'
|
||||
import { Logger } from '../utils/Logger'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
/**
|
||||
* 背景音乐
|
||||
*/
|
||||
|
||||
@ccclass('MusicPrefab')
|
||||
export default class MusicPrefab extends Component {
|
||||
private static instance: MusicPrefab
|
||||
private static MUSIC_VOLUMN_KEY: string = 'musicVolumn'
|
||||
public static musicVolumn: number = 1
|
||||
|
||||
public static play(key: string) {
|
||||
const url: string = MusicConfig.musicKey2Path.get(key)
|
||||
if (url) {
|
||||
AssetManager.instance.resources.load(url, AudioClip, (error: Error, clip: AudioClip) => {
|
||||
if (error) {
|
||||
Logger.warn(this, 'load music error===', error.message)
|
||||
} else {
|
||||
if (clip) {
|
||||
this.instance.node.getComponent(AudioSource).clip = clip
|
||||
this.instance.node.getComponent(AudioSource).volume = this.musicVolumn
|
||||
this.instance.node.getComponent(AudioSource).play()
|
||||
this.instance.node.getComponent(AudioSource).loop = true
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Logger.warn(this, '播放不存在的music=', key)
|
||||
}
|
||||
}
|
||||
|
||||
public static changeVolumn(nowVolumn: number) {
|
||||
this.musicVolumn = nowVolumn
|
||||
this.instance.node.getComponent(AudioSource).volume = nowVolumn
|
||||
LocalStorage.setItem(MusicPrefab.MUSIC_VOLUMN_KEY, this.musicVolumn.toString())
|
||||
}
|
||||
|
||||
private static preInit() {
|
||||
this.musicVolumn = Number.parseFloat(LocalStorage.getItem(MusicPrefab.MUSIC_VOLUMN_KEY))
|
||||
if (Number.isNaN(this.musicVolumn)) this.musicVolumn = 1
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/MusicPrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
MusicPrefab.instance = instantiate(loadedResource).getComponent(MusicPrefab)
|
||||
this.preInit()
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static destory() {
|
||||
if (MusicPrefab.instance) {
|
||||
MusicPrefab.instance.getComponent(AudioSource).stop()
|
||||
MusicPrefab.instance.destroy()
|
||||
}
|
||||
MusicPrefab.instance = null
|
||||
}
|
||||
}
|
||||
import {
|
||||
AssetManager,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
Component,
|
||||
Prefab,
|
||||
_decorator,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import MusicConfig from '../config/MusicConfig'
|
||||
import LocalStorage from '../utils/LocalStorage'
|
||||
import { Logger } from '../utils/Logger'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
/**
|
||||
* 背景音乐
|
||||
*/
|
||||
|
||||
@ccclass('MusicPrefab')
|
||||
export default class MusicPrefab extends Component {
|
||||
private static instance: MusicPrefab
|
||||
private static MUSIC_VOLUMN_KEY: string = 'musicVolumn'
|
||||
public static musicVolumn: number = 1
|
||||
|
||||
public static play(key: string) {
|
||||
const url: string = MusicConfig.musicKey2Path.get(key)
|
||||
if (url) {
|
||||
AssetManager.instance.resources.load(url, AudioClip, (error: Error, clip: AudioClip) => {
|
||||
if (error) {
|
||||
Logger.warn(this, 'load music error===', error.message)
|
||||
} else {
|
||||
if (clip) {
|
||||
this.instance.node.getComponent(AudioSource).clip = clip
|
||||
this.instance.node.getComponent(AudioSource).volume = this.musicVolumn
|
||||
this.instance.node.getComponent(AudioSource).play()
|
||||
this.instance.node.getComponent(AudioSource).loop = true
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Logger.warn(this, '播放不存在的music=', key)
|
||||
}
|
||||
}
|
||||
|
||||
public static changeVolumn(nowVolumn: number) {
|
||||
this.musicVolumn = nowVolumn
|
||||
this.instance.node.getComponent(AudioSource).volume = nowVolumn
|
||||
LocalStorage.setItem(MusicPrefab.MUSIC_VOLUMN_KEY, this.musicVolumn.toString())
|
||||
}
|
||||
|
||||
private static preInit() {
|
||||
this.musicVolumn = Number.parseFloat(LocalStorage.getItem(MusicPrefab.MUSIC_VOLUMN_KEY))
|
||||
if (Number.isNaN(this.musicVolumn)) this.musicVolumn = 1
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/MusicPrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
MusicPrefab.instance = instantiate(loadedResource).getComponent(MusicPrefab)
|
||||
this.preInit()
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static destory() {
|
||||
if (MusicPrefab.instance) {
|
||||
MusicPrefab.instance.getComponent(AudioSource).stop()
|
||||
MusicPrefab.instance.destroy()
|
||||
}
|
||||
MusicPrefab.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e947ef07-b958-4471-b5a5-f0acd7e299d2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e947ef07-b958-4471-b5a5-f0acd7e299d2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
import { Component, Label, ProgressBar, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('Progress')
|
||||
export default class Progress extends Component {
|
||||
@property(Label)
|
||||
public percentLable: Label
|
||||
|
||||
@property(ProgressBar)
|
||||
public bar: ProgressBar
|
||||
|
||||
onLoad() {
|
||||
this.bar.node.active = false
|
||||
this.bar.progress = 0
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
updatePercent(current, filePercent) {
|
||||
// this.percentLable.string = filePercent.toFixed(2);
|
||||
}
|
||||
|
||||
updatefileTotal(current: number, filePercent: number) {
|
||||
if (!this.bar.node.active) this.bar.node.active = true
|
||||
let nowPercent = Math.round((current / filePercent) * 100)
|
||||
const curMB = this.getMB(current)
|
||||
const totalMB = this.getMB(filePercent)
|
||||
// this.percentLable.string = "正在更新 " + nowPercent + "%" + " ( " + curMB + " / "+totalMB +" MB)";
|
||||
nowPercent = Math.min(nowPercent, 100)
|
||||
this.percentLable.string = `正在更新 ${nowPercent}%`
|
||||
this.bar.progress = current / filePercent
|
||||
}
|
||||
|
||||
public updateProgress(
|
||||
current: number,
|
||||
total: number,
|
||||
msg: string = '正在加载资源,此过程不消耗流量...',
|
||||
) {
|
||||
this.bar.node.active = true
|
||||
// this.setMsg(msg+ current + "/" + total);
|
||||
this.setMsg(msg)
|
||||
this.bar.progress = current / total
|
||||
}
|
||||
|
||||
getMB(bytes: number) {
|
||||
bytes /= 1024
|
||||
bytes /= 1024
|
||||
return bytes.toFixed(2)
|
||||
}
|
||||
|
||||
public setMsg(msg: string = '游戏加载中,请稍后...') {
|
||||
this.percentLable.string = msg
|
||||
}
|
||||
}
|
||||
import { Component, Label, ProgressBar, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('Progress')
|
||||
export default class Progress extends Component {
|
||||
@property(Label)
|
||||
public percentLable: Label
|
||||
|
||||
@property(ProgressBar)
|
||||
public bar: ProgressBar
|
||||
|
||||
onLoad() {
|
||||
this.bar.node.active = false
|
||||
this.bar.progress = 0
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
updatePercent(current, filePercent) {
|
||||
// this.percentLable.string = filePercent.toFixed(2);
|
||||
}
|
||||
|
||||
updatefileTotal(current: number, filePercent: number) {
|
||||
if (!this.bar.node.active) this.bar.node.active = true
|
||||
let nowPercent = Math.round((current / filePercent) * 100)
|
||||
const curMB = this.getMB(current)
|
||||
const totalMB = this.getMB(filePercent)
|
||||
// this.percentLable.string = "正在更新 " + nowPercent + "%" + " ( " + curMB + " / "+totalMB +" MB)";
|
||||
nowPercent = Math.min(nowPercent, 100)
|
||||
this.percentLable.string = `正在更新 ${nowPercent}%`
|
||||
this.bar.progress = current / filePercent
|
||||
}
|
||||
|
||||
public updateProgress(
|
||||
current: number,
|
||||
total: number,
|
||||
msg: string = '正在加载资源,此过程不消耗流量...',
|
||||
) {
|
||||
this.bar.node.active = true
|
||||
// this.setMsg(msg+ current + "/" + total);
|
||||
this.setMsg(msg)
|
||||
this.bar.progress = current / total
|
||||
}
|
||||
|
||||
getMB(bytes: number) {
|
||||
bytes /= 1024
|
||||
bytes /= 1024
|
||||
return bytes.toFixed(2)
|
||||
}
|
||||
|
||||
public setMsg(msg: string = '游戏加载中,请稍后...') {
|
||||
this.percentLable.string = msg
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ba38c648-abb9-41f8-a06b-830bb5aea91d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ba38c648-abb9-41f8-a06b-830bb5aea91d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +1,128 @@
|
||||
import {
|
||||
AssetManager,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
Component,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
_decorator,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import CommonEvent from '../config/CommonEvent'
|
||||
import MusicConfig from '../config/MusicConfig'
|
||||
import EventManager from '../utils/EventManager'
|
||||
import LocalStorage from '../utils/LocalStorage'
|
||||
import { Logger } from '../utils/Logger'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
// /**
|
||||
// * 音效
|
||||
// * Ios暂时有bug,弃用
|
||||
// */
|
||||
|
||||
@ccclass('SoundPrefab')
|
||||
export default class SoundPrefab extends Component {
|
||||
private static prefab: Prefab | null = null
|
||||
private static SOUND_VOLUMN_KEY: string = 'soundVolumn'
|
||||
public static soundVolumn: number = 1
|
||||
private static Pool_Init_Num: number = 30
|
||||
private static pool: NodePool = new NodePool()
|
||||
private static nowAudioNodeList: Array<Node> = []
|
||||
private audioName: string = ''
|
||||
private audioUrl: string = ''
|
||||
|
||||
private static getAudioNode() {
|
||||
let node: Node = null
|
||||
// if (this.pool.size() > 0) {
|
||||
|
||||
// node = this.pool.get();
|
||||
// } else {
|
||||
node = instantiate(this.prefab)
|
||||
// }
|
||||
return node
|
||||
}
|
||||
|
||||
public static play(key: string) {
|
||||
const url: string = MusicConfig.musicKey2Path.get(key)
|
||||
if (url) {
|
||||
AssetManager.instance.resources.load(url, AudioClip, (error: Error, clip: AudioClip) => {
|
||||
if (error) {
|
||||
Logger.warn(this, 'load sound error===', error.message)
|
||||
} else {
|
||||
if (clip) {
|
||||
const audioNode: Node = this.getAudioNode()
|
||||
if (audioNode) {
|
||||
audioNode.getComponent(AudioSource).clip = clip
|
||||
audioNode.getComponent(AudioSource).volume = SoundPrefab.soundVolumn
|
||||
audioNode.getComponent(AudioSource).loop = false
|
||||
audioNode.getComponent(AudioSource).currentTime = 0 // rewind();
|
||||
audioNode.getComponent(AudioSource).play()
|
||||
audioNode.getComponent(SoundPrefab).audioName = key
|
||||
audioNode.getComponent(SoundPrefab).audioUrl = url
|
||||
this.nowAudioNodeList.push(audioNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Logger.warn(this, '播放不存在的music=', key)
|
||||
}
|
||||
}
|
||||
|
||||
public static changeVolumn(nowVolumn: number) {
|
||||
this.soundVolumn = nowVolumn
|
||||
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
|
||||
const audioNode: Node = this.nowAudioNodeList[i]
|
||||
const audioSource: AudioSource = audioNode.getComponent(AudioSource)
|
||||
if (audioSource.playing) audioSource.volume = nowVolumn
|
||||
}
|
||||
LocalStorage.setItem(SoundPrefab.SOUND_VOLUMN_KEY, SoundPrefab.soundVolumn.toString())
|
||||
}
|
||||
|
||||
private static preInit() {
|
||||
EventManager.instance.addListener(CommonEvent.Event_FrameUpdate, this.updateFrame, this)
|
||||
SoundPrefab.soundVolumn = Number.parseFloat(LocalStorage.getItem(SoundPrefab.SOUND_VOLUMN_KEY))
|
||||
if (Number.isNaN(SoundPrefab.soundVolumn)) SoundPrefab.soundVolumn = 1
|
||||
}
|
||||
|
||||
private static updateFrame() {
|
||||
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
|
||||
const audioNode: Node = this.nowAudioNodeList[i]
|
||||
const audioSource: AudioSource = audioNode.getComponent(AudioSource)
|
||||
if (!audioSource.playing) SoundPrefab.nowAudioNodeList.splice(i, 1)
|
||||
}
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/SoundPrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
SoundPrefab.prefab = loadedResource
|
||||
this.preInit()
|
||||
// for (let i = 0; i < this.Pool_Init_Num; i++) {
|
||||
// let tempNode: cc.Node = cc.instantiate(loadedResource);
|
||||
// this.pool.put(tempNode);
|
||||
// }
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static destory() {
|
||||
EventManager.instance.removeListener(CommonEvent.Event_FrameUpdate, this.updateFrame)
|
||||
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
|
||||
const audioNode: Node = this.nowAudioNodeList[i]
|
||||
audioNode.getComponent(AudioSource).stop()
|
||||
audioNode.getComponent(AudioSource).destroy()
|
||||
}
|
||||
this.nowAudioNodeList = []
|
||||
this.pool.clear()
|
||||
}
|
||||
}
|
||||
import {
|
||||
AssetManager,
|
||||
AudioClip,
|
||||
AudioSource,
|
||||
Component,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
_decorator,
|
||||
instantiate,
|
||||
} from 'cc'
|
||||
|
||||
import { GameConfig } from '../../game/config/GameConfig'
|
||||
import CommonEvent from '../config/CommonEvent'
|
||||
import MusicConfig from '../config/MusicConfig'
|
||||
import EventManager from '../utils/EventManager'
|
||||
import LocalStorage from '../utils/LocalStorage'
|
||||
import { Logger } from '../utils/Logger'
|
||||
import PrefabLoader from '../utils/PrefabLoader'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
// /**
|
||||
// * 音效
|
||||
// * Ios暂时有bug,弃用
|
||||
// */
|
||||
|
||||
@ccclass('SoundPrefab')
|
||||
export default class SoundPrefab extends Component {
|
||||
private static prefab: Prefab | null = null
|
||||
private static SOUND_VOLUMN_KEY: string = 'soundVolumn'
|
||||
public static soundVolumn: number = 1
|
||||
private static Pool_Init_Num: number = 30
|
||||
private static pool: NodePool = new NodePool()
|
||||
private static nowAudioNodeList: Array<Node> = []
|
||||
private audioName: string = ''
|
||||
private audioUrl: string = ''
|
||||
|
||||
private static getAudioNode() {
|
||||
let node: Node = null
|
||||
// if (this.pool.size() > 0) {
|
||||
|
||||
// node = this.pool.get();
|
||||
// } else {
|
||||
node = instantiate(this.prefab)
|
||||
// }
|
||||
return node
|
||||
}
|
||||
|
||||
public static play(key: string) {
|
||||
const url: string = MusicConfig.musicKey2Path.get(key)
|
||||
if (url) {
|
||||
AssetManager.instance.resources.load(url, AudioClip, (error: Error, clip: AudioClip) => {
|
||||
if (error) {
|
||||
Logger.warn(this, 'load sound error===', error.message)
|
||||
} else {
|
||||
if (clip) {
|
||||
const audioNode: Node = this.getAudioNode()
|
||||
if (audioNode) {
|
||||
audioNode.getComponent(AudioSource).clip = clip
|
||||
audioNode.getComponent(AudioSource).volume = SoundPrefab.soundVolumn
|
||||
audioNode.getComponent(AudioSource).loop = false
|
||||
audioNode.getComponent(AudioSource).currentTime = 0 // rewind();
|
||||
audioNode.getComponent(AudioSource).play()
|
||||
audioNode.getComponent(SoundPrefab).audioName = key
|
||||
audioNode.getComponent(SoundPrefab).audioUrl = url
|
||||
this.nowAudioNodeList.push(audioNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Logger.warn(this, '播放不存在的music=', key)
|
||||
}
|
||||
}
|
||||
|
||||
public static changeVolumn(nowVolumn: number) {
|
||||
this.soundVolumn = nowVolumn
|
||||
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
|
||||
const audioNode: Node = this.nowAudioNodeList[i]
|
||||
const audioSource: AudioSource = audioNode.getComponent(AudioSource)
|
||||
if (audioSource.playing) audioSource.volume = nowVolumn
|
||||
}
|
||||
LocalStorage.setItem(SoundPrefab.SOUND_VOLUMN_KEY, SoundPrefab.soundVolumn.toString())
|
||||
}
|
||||
|
||||
private static preInit() {
|
||||
EventManager.instance.addListener(CommonEvent.Event_FrameUpdate, this.updateFrame, this)
|
||||
SoundPrefab.soundVolumn = Number.parseFloat(LocalStorage.getItem(SoundPrefab.SOUND_VOLUMN_KEY))
|
||||
if (Number.isNaN(SoundPrefab.soundVolumn)) SoundPrefab.soundVolumn = 1
|
||||
}
|
||||
|
||||
private static updateFrame() {
|
||||
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
|
||||
const audioNode: Node = this.nowAudioNodeList[i]
|
||||
const audioSource: AudioSource = audioNode.getComponent(AudioSource)
|
||||
if (!audioSource.playing) SoundPrefab.nowAudioNodeList.splice(i, 1)
|
||||
}
|
||||
}
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/share/uicomponent/SoundPrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
SoundPrefab.prefab = loadedResource
|
||||
this.preInit()
|
||||
// for (let i = 0; i < this.Pool_Init_Num; i++) {
|
||||
// let tempNode: cc.Node = cc.instantiate(loadedResource);
|
||||
// this.pool.put(tempNode);
|
||||
// }
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static destory() {
|
||||
EventManager.instance.removeListener(CommonEvent.Event_FrameUpdate, this.updateFrame)
|
||||
for (let i = 0; i < this.nowAudioNodeList.length; i++) {
|
||||
const audioNode: Node = this.nowAudioNodeList[i]
|
||||
audioNode.getComponent(AudioSource).stop()
|
||||
audioNode.getComponent(AudioSource).destroy()
|
||||
}
|
||||
this.nowAudioNodeList = []
|
||||
this.pool.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d262f2b2-8af6-4db9-b1e4-0c08493efa10",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d262f2b2-8af6-4db9-b1e4-0c08493efa10",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import { Component, SpriteFrame, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('TextureMgr')
|
||||
export default class TextureMgr extends Component {
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset1: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset2: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset3: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset4: SpriteFrame[] = []
|
||||
|
||||
onLoad() {
|
||||
// init logic
|
||||
}
|
||||
}
|
||||
import { Component, SpriteFrame, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('TextureMgr')
|
||||
export default class TextureMgr extends Component {
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset1: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset2: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset3: SpriteFrame[] = []
|
||||
|
||||
@property({ type: [SpriteFrame] })
|
||||
public Spriteset4: SpriteFrame[] = []
|
||||
|
||||
onLoad() {
|
||||
// init logic
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1147cca4-2fe9-4d82-8850-0d97cb3318d5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1147cca4-2fe9-4d82-8850-0d97cb3318d5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a8097de0-2f13-4b1b-be6b-4635b5d8281d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a8097de0-2f13-4b1b-be6b-4635b5d8281d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
import { _decorator, Canvas, error, log, view } from 'cc'
|
||||
import DialogBase from '../uicomponent/DialogBase'
|
||||
|
||||
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
|
||||
// const framesize = view.getFrameSize()
|
||||
// if (!this.winSizeWidth) {
|
||||
// this.winSizeWidth = screen.width
|
||||
// this.winSizeHeiht = screen.height
|
||||
// }
|
||||
// const designsize = view.getDesignResolutionSize()
|
||||
// const canvas: Canvas = DialogBase.GetRootCanvas().getComponent(Canvas)
|
||||
|
||||
// const ratio: number = framesize.height / framesize.width
|
||||
// const 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')
|
||||
// }
|
||||
}
|
||||
}
|
||||
import { _decorator, Canvas, error, log, view } from 'cc'
|
||||
import DialogBase from '../uicomponent/DialogBase'
|
||||
|
||||
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
|
||||
// const framesize = view.getFrameSize()
|
||||
// if (!this.winSizeWidth) {
|
||||
// this.winSizeWidth = screen.width
|
||||
// this.winSizeHeiht = screen.height
|
||||
// }
|
||||
// const designsize = view.getDesignResolutionSize()
|
||||
// const canvas: Canvas = DialogBase.GetRootCanvas().getComponent(Canvas)
|
||||
|
||||
// const ratio: number = framesize.height / framesize.width
|
||||
// const 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d2b64431-33c2-4fa1-83b0-0ece0e0a35e2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d2b64431-33c2-4fa1-83b0-0ece0e0a35e2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('BitUtil')
|
||||
export default class BitUtil {
|
||||
// index是二进制从右到左
|
||||
public static isBitSet(value: number, index: number): boolean {
|
||||
const str: string = value.toString(2)
|
||||
return Number.parseInt(str[str.length - 1 - index]) === 1
|
||||
}
|
||||
|
||||
// 从右到左计算
|
||||
public static setBitValue(value: number, index: number): number {
|
||||
let newValue: number = value
|
||||
const str: string = value.toString(2)
|
||||
let newStr: string = ''
|
||||
const 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 = Number.parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
|
||||
public static clearBitValue(value: number, index: number) {
|
||||
let newValue: number = value
|
||||
const 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 = Number.parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
}
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('BitUtil')
|
||||
export default class BitUtil {
|
||||
// index是二进制从右到左
|
||||
public static isBitSet(value: number, index: number): boolean {
|
||||
const str: string = value.toString(2)
|
||||
return Number.parseInt(str[str.length - 1 - index]) === 1
|
||||
}
|
||||
|
||||
// 从右到左计算
|
||||
public static setBitValue(value: number, index: number): number {
|
||||
let newValue: number = value
|
||||
const str: string = value.toString(2)
|
||||
let newStr: string = ''
|
||||
const 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 = Number.parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
|
||||
public static clearBitValue(value: number, index: number) {
|
||||
let newValue: number = value
|
||||
const 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 = Number.parseInt(newStr, 2)
|
||||
return newValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8a5aad8d-c1cf-4e6a-bbbe-bc0ef0b4d05f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8a5aad8d-c1cf-4e6a-bbbe-bc0ef0b4d05f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Color, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ColorHelper')
|
||||
export default class ColorHelper {
|
||||
public static getColor(hexStr: string): Color {
|
||||
const color: Color = Color.BLACK
|
||||
return color.fromHEX(hexStr)
|
||||
}
|
||||
}
|
||||
import { Color, _decorator } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ColorHelper')
|
||||
export default class ColorHelper {
|
||||
public static getColor(hexStr: string): Color {
|
||||
const color: Color = Color.BLACK
|
||||
return color.fromHEX(hexStr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d1bc656e-a928-4212-a2b4-408b73ef0ec9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d1bc656e-a928-4212-a2b4-408b73ef0ec9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
export default class DateUtil {
|
||||
public static formatNumStr(num: number) {
|
||||
let str = `${num}`
|
||||
if (num < 10) str = `0${num}`
|
||||
return str
|
||||
}
|
||||
|
||||
public static formateYearMonthDayStr(timestamp: number) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
}
|
||||
|
||||
public static formateMonthDayStr(timestamp: number) {
|
||||
const 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) {
|
||||
const 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) {
|
||||
const 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) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
}
|
||||
|
||||
// timestamp:1453094034000
|
||||
// 根据时间戳返回 19:53
|
||||
public static formatHourMinStr(timestamp: number) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${this.formatNumStr(date.getHours())}:${this.formatNumStr(date.getMinutes())}`
|
||||
}
|
||||
|
||||
// timestamp:1453094034000
|
||||
// 根据时间戳返回 19:53:11
|
||||
public static formatHourMinSecondStr(timestamp: number) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${this.formatNumStr(date.getHours())}:${this.formatNumStr(date.getMinutes())}:${this.formatNumStr(date.getSeconds())}`
|
||||
}
|
||||
|
||||
public static now(): number {
|
||||
const date: Date = new Date()
|
||||
return date.getTime()
|
||||
}
|
||||
|
||||
public static betweenTime(startTime: number, endTime: number) {
|
||||
const date: Date = new Date()
|
||||
return date.getTime() >= startTime && date.getTime() <= endTime
|
||||
}
|
||||
|
||||
// 根据时间戳返回 1天19:53:11
|
||||
public static formatLeftTime(timestamp: number) {
|
||||
const day: number = Math.floor(timestamp / (1000 * 60 * 60 * 24))
|
||||
const hour: number = Math.floor(timestamp / (1000 * 60 * 60)) % 24
|
||||
const min: number = Math.floor(timestamp / (1000 * 60)) % 60
|
||||
const second: number = Math.floor(timestamp / 1000) % 60
|
||||
return `${day}天${this.formatNumStr(hour)}:${this.formatNumStr(min)}:${this.formatNumStr(second)}`
|
||||
}
|
||||
|
||||
public static isToday(dateTime: number): boolean {
|
||||
const nowDate: Date = new Date()
|
||||
const checkDate: Date = new Date(dateTime)
|
||||
return (
|
||||
checkDate.getFullYear() === nowDate.getFullYear() &&
|
||||
checkDate.getMonth() === nowDate.getMonth() &&
|
||||
checkDate.getDate() === nowDate.getDate()
|
||||
)
|
||||
}
|
||||
}
|
||||
export default class DateUtil {
|
||||
public static formatNumStr(num: number) {
|
||||
let str = `${num}`
|
||||
if (num < 10) str = `0${num}`
|
||||
return str
|
||||
}
|
||||
|
||||
public static formateYearMonthDayStr(timestamp: number) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
}
|
||||
|
||||
public static formateMonthDayStr(timestamp: number) {
|
||||
const 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) {
|
||||
const 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) {
|
||||
const 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) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||
}
|
||||
|
||||
// timestamp:1453094034000
|
||||
// 根据时间戳返回 19:53
|
||||
public static formatHourMinStr(timestamp: number) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${this.formatNumStr(date.getHours())}:${this.formatNumStr(date.getMinutes())}`
|
||||
}
|
||||
|
||||
// timestamp:1453094034000
|
||||
// 根据时间戳返回 19:53:11
|
||||
public static formatHourMinSecondStr(timestamp: number) {
|
||||
const date: Date = new Date(timestamp)
|
||||
return `${this.formatNumStr(date.getHours())}:${this.formatNumStr(date.getMinutes())}:${this.formatNumStr(date.getSeconds())}`
|
||||
}
|
||||
|
||||
public static now(): number {
|
||||
const date: Date = new Date()
|
||||
return date.getTime()
|
||||
}
|
||||
|
||||
public static betweenTime(startTime: number, endTime: number) {
|
||||
const date: Date = new Date()
|
||||
return date.getTime() >= startTime && date.getTime() <= endTime
|
||||
}
|
||||
|
||||
// 根据时间戳返回 1天19:53:11
|
||||
public static formatLeftTime(timestamp: number) {
|
||||
const day: number = Math.floor(timestamp / (1000 * 60 * 60 * 24))
|
||||
const hour: number = Math.floor(timestamp / (1000 * 60 * 60)) % 24
|
||||
const min: number = Math.floor(timestamp / (1000 * 60)) % 60
|
||||
const second: number = Math.floor(timestamp / 1000) % 60
|
||||
return `${day}天${this.formatNumStr(hour)}:${this.formatNumStr(min)}:${this.formatNumStr(second)}`
|
||||
}
|
||||
|
||||
public static isToday(dateTime: number): boolean {
|
||||
const nowDate: Date = new Date()
|
||||
const checkDate: Date = new Date(dateTime)
|
||||
return (
|
||||
checkDate.getFullYear() === nowDate.getFullYear() &&
|
||||
checkDate.getMonth() === nowDate.getMonth() &&
|
||||
checkDate.getDate() === nowDate.getDate()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b42f778f-ca3e-4982-bd84-c8a54d39ced4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b42f778f-ca3e-4982-bd84-c8a54d39ced4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
export default class EventManager {
|
||||
public static instance: EventManager = new EventManager()
|
||||
|
||||
private callbackList = {}
|
||||
|
||||
public constructor() {}
|
||||
|
||||
// 注册事件
|
||||
public addListener(eventName: string, callback: Function, caller: any) {
|
||||
if (this.callbackList[eventName]) {
|
||||
const eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
// 不同元件才放入,相同元件覆蓋
|
||||
let add: boolean = true
|
||||
for (let i = 0; i < eventList.length; i++) {
|
||||
const 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--) {
|
||||
const event: HaoEvent = this.callbackList[eventName][i]
|
||||
if (event.callback == callback) {
|
||||
this.callbackList[eventName].splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispatchEvent(eventName, parameter?: any, ...restOfName: any[]) {
|
||||
const eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
if (eventList) {
|
||||
for (let i = eventList.length - 1; i >= 0; i--) {
|
||||
const 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--) {
|
||||
const event: HaoEvent = eventList[i]
|
||||
event.isStop = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public addBtnEvent(
|
||||
parentNode: Node,
|
||||
objectNode: Node,
|
||||
scriptName: string,
|
||||
eventName: string,
|
||||
data: any = null,
|
||||
) {
|
||||
const btn: Button = objectNode.addComponent(Button)
|
||||
const 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 removeBtnEffect(objectNode: Node) {
|
||||
const b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.NONE
|
||||
}
|
||||
|
||||
public addBtnEffect(objectNode: Node, scale: number = 1.1) {
|
||||
const 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'),
|
||||
) {
|
||||
const 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) {
|
||||
const b = objectNode.getComponent(Slider)
|
||||
const clickEventHandler = new Component.EventHandler()
|
||||
clickEventHandler.target = parentNode // 这个 node 节点是你的事件处理代码组件所属的节点
|
||||
clickEventHandler.component = parentNode.name // 这个是代码文件名
|
||||
clickEventHandler.handler = EventName
|
||||
clickEventHandler.customEventData = data
|
||||
b.slideEvents.push(clickEventHandler)
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
export default class EventManager {
|
||||
public static instance: EventManager = new EventManager()
|
||||
|
||||
private callbackList = {}
|
||||
|
||||
public constructor() {}
|
||||
|
||||
// 注册事件
|
||||
public addListener(eventName: string, callback: Function, caller: any) {
|
||||
if (this.callbackList[eventName]) {
|
||||
const eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
// 不同元件才放入,相同元件覆蓋
|
||||
let add: boolean = true
|
||||
for (let i = 0; i < eventList.length; i++) {
|
||||
const 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--) {
|
||||
const event: HaoEvent = this.callbackList[eventName][i]
|
||||
if (event.callback == callback) {
|
||||
this.callbackList[eventName].splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispatchEvent(eventName, parameter?: any, ...restOfName: any[]) {
|
||||
const eventList: Array<HaoEvent> = this.callbackList[eventName]
|
||||
if (eventList) {
|
||||
for (let i = eventList.length - 1; i >= 0; i--) {
|
||||
const 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--) {
|
||||
const event: HaoEvent = eventList[i]
|
||||
event.isStop = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public addBtnEvent(
|
||||
parentNode: Node,
|
||||
objectNode: Node,
|
||||
scriptName: string,
|
||||
eventName: string,
|
||||
data: any = null,
|
||||
) {
|
||||
const btn: Button = objectNode.addComponent(Button)
|
||||
const 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 removeBtnEffect(objectNode: Node) {
|
||||
const b = objectNode.getComponent(Button)
|
||||
b.transition = Button.Transition.NONE
|
||||
}
|
||||
|
||||
public addBtnEffect(objectNode: Node, scale: number = 1.1) {
|
||||
const 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'),
|
||||
) {
|
||||
const 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) {
|
||||
const b = objectNode.getComponent(Slider)
|
||||
const clickEventHandler = new Component.EventHandler()
|
||||
clickEventHandler.target = parentNode // 这个 node 节点是你的事件处理代码组件所属的节点
|
||||
clickEventHandler.component = parentNode.name // 这个是代码文件名
|
||||
clickEventHandler.handler = EventName
|
||||
clickEventHandler.customEventData = data
|
||||
b.slideEvents.push(clickEventHandler)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b7dbd2a3-1ad1-45b8-8cae-53c431e08789",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b7dbd2a3-1ad1-45b8-8cae-53c431e08789",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
export default class Grid {
|
||||
public row: number
|
||||
public col: number
|
||||
|
||||
constructor(row: number, col: number) {
|
||||
this.row = row
|
||||
this.col = col
|
||||
}
|
||||
|
||||
public static init(row: number, col: number) {
|
||||
return new Grid(row, col)
|
||||
}
|
||||
}
|
||||
export default class Grid {
|
||||
public row: number
|
||||
public col: number
|
||||
|
||||
constructor(row: number, col: number) {
|
||||
this.row = row
|
||||
this.col = col
|
||||
}
|
||||
|
||||
public static init(row: number, col: number) {
|
||||
return new Grid(row, col)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "696c7042-c332-4a1a-a7f8-a898e63b35b4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "696c7042-c332-4a1a-a7f8-a898e63b35b4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
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 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
|
||||
}
|
||||
}
|
||||
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 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "87a63258-3b93-48f6-945d-5bfd9959bb70",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "87a63258-3b93-48f6-945d-5bfd9959bb70",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,257 +1,257 @@
|
||||
import { native, sys } from 'cc'
|
||||
|
||||
import ManifestConfig from '../config/ManifestConfig'
|
||||
|
||||
import CommonTips from '../uicomponent/CommonTips'
|
||||
|
||||
import EventManager from './EventManager'
|
||||
import { Logger } from './Logger'
|
||||
import VersionManager from './VersionManager'
|
||||
|
||||
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: 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
|
||||
|
||||
constructor() {}
|
||||
|
||||
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报错了'
|
||||
|
||||
Logger.log(this, 'init removeDirectory=', `${this.storagePath}_temp`)
|
||||
}
|
||||
this.needUpdate = false
|
||||
this.isUpdating = false
|
||||
this.isFinishUpdate = false
|
||||
this.isCheck = false
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// 显示强制更新,即更细包面板
|
||||
private showPackUpdateDialog() {
|
||||
CommonTips.showMsg('有新的版本需要更新,下载后请先卸载,以前的版本,再安装!')
|
||||
this.jumpToPack()
|
||||
this.showPackUpdateDialog()
|
||||
}
|
||||
|
||||
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:
|
||||
const fullFilePath: string = `${this.storagePath}/${event.getAssetId()}`
|
||||
const 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();
|
||||
}
|
||||
}
|
||||
|
||||
public checkUpdate() {
|
||||
if (this.isUpdating || this.isCheck) {
|
||||
Logger.log(this, 'Checking or updating ...')
|
||||
return
|
||||
}
|
||||
const 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);
|
||||
const manifestStr: string = ManifestConfig.getManifestStr(hotupdateUrlKey)
|
||||
Logger.log(this, 'checkUpdate=======manifestStr=======', manifestStr)
|
||||
const manifest = new native.Manifest(manifestStr, this.storagePath)
|
||||
this._am.setVerifyCallback((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()
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = Number.parseInt(vA[0])
|
||||
this.remoteBigVersion = Number.parseInt(vB[0])
|
||||
for (let i = 0; i < vA.length; ++i) {
|
||||
const a = Number.parseInt(vA[i])
|
||||
const b = Number.parseInt(vB[i] || '0')
|
||||
if (a !== b) return a - b
|
||||
}
|
||||
if (vB.length > vA.length) return -1
|
||||
else return 0
|
||||
}
|
||||
|
||||
public startUpdate() {
|
||||
if (this.isUpdating) return
|
||||
const localManifest = this._am.getLocalManifest()
|
||||
const 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 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 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)
|
||||
}
|
||||
}
|
||||
import { native, sys } from 'cc'
|
||||
|
||||
import ManifestConfig from '../config/ManifestConfig'
|
||||
|
||||
import CommonTips from '../uicomponent/CommonTips'
|
||||
|
||||
import EventManager from './EventManager'
|
||||
import { Logger } from './Logger'
|
||||
import VersionManager from './VersionManager'
|
||||
|
||||
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: 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
|
||||
|
||||
constructor() {}
|
||||
|
||||
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报错了'
|
||||
|
||||
Logger.log(this, 'init removeDirectory=', `${this.storagePath}_temp`)
|
||||
}
|
||||
this.needUpdate = false
|
||||
this.isUpdating = false
|
||||
this.isFinishUpdate = false
|
||||
this.isCheck = false
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// 显示强制更新,即更细包面板
|
||||
private showPackUpdateDialog() {
|
||||
CommonTips.showMsg('有新的版本需要更新,下载后请先卸载,以前的版本,再安装!')
|
||||
this.jumpToPack()
|
||||
this.showPackUpdateDialog()
|
||||
}
|
||||
|
||||
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:
|
||||
const fullFilePath: string = `${this.storagePath}/${event.getAssetId()}`
|
||||
const 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();
|
||||
}
|
||||
}
|
||||
|
||||
public checkUpdate() {
|
||||
if (this.isUpdating || this.isCheck) {
|
||||
Logger.log(this, 'Checking or updating ...')
|
||||
return
|
||||
}
|
||||
const 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);
|
||||
const manifestStr: string = ManifestConfig.getManifestStr(hotupdateUrlKey)
|
||||
Logger.log(this, 'checkUpdate=======manifestStr=======', manifestStr)
|
||||
const manifest = new native.Manifest(manifestStr, this.storagePath)
|
||||
this._am.setVerifyCallback((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()
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = Number.parseInt(vA[0])
|
||||
this.remoteBigVersion = Number.parseInt(vB[0])
|
||||
for (let i = 0; i < vA.length; ++i) {
|
||||
const a = Number.parseInt(vA[i])
|
||||
const b = Number.parseInt(vB[i] || '0')
|
||||
if (a !== b) return a - b
|
||||
}
|
||||
if (vB.length > vA.length) return -1
|
||||
else return 0
|
||||
}
|
||||
|
||||
public startUpdate() {
|
||||
if (this.isUpdating) return
|
||||
const localManifest = this._am.getLocalManifest()
|
||||
const 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 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 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a0006bd3-77dc-49ae-991e-77aa5a70f4a6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a0006bd3-77dc-49ae-991e-77aa5a70f4a6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +1,130 @@
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
import { Logger } from './Logger'
|
||||
|
||||
const { ccclass } = _decorator
|
||||
|
||||
@ccclass('HttpClient')
|
||||
export default class 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});
|
||||
|
||||
private methodType: string = 'GET'
|
||||
|
||||
private responseType: XMLHttpRequestResponseType = 'json'
|
||||
|
||||
private xhr: XMLHttpRequest
|
||||
|
||||
// --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 (Object.prototype.hasOwnProperty.call(paramsObj, 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 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();
|
||||
const 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) {
|
||||
const response = xhr.response
|
||||
Logger.log(this, 'http response1============', xhr)
|
||||
try {
|
||||
const 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) {}
|
||||
}
|
||||
import { _decorator } from 'cc'
|
||||
|
||||
import { Logger } from './Logger'
|
||||
|
||||
const { ccclass } = _decorator
|
||||
|
||||
@ccclass('HttpClient')
|
||||
export default class 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});
|
||||
|
||||
private methodType: string = 'GET'
|
||||
|
||||
private responseType: XMLHttpRequestResponseType = 'json'
|
||||
|
||||
private xhr: XMLHttpRequest
|
||||
|
||||
// --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 (Object.prototype.hasOwnProperty.call(paramsObj, 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 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();
|
||||
const 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) {
|
||||
const response = xhr.response
|
||||
Logger.log(this, 'http response1============', xhr)
|
||||
try {
|
||||
const 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) {}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "97dba6a3-a0b7-42ef-9abc-de779e8bd220",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "97dba6a3-a0b7-42ef-9abc-de779e8bd220",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
import { sys } from 'cc'
|
||||
|
||||
export default class LocalStorage {
|
||||
public static GamePreFlag: string = 'fengshen-game-HaoLocalStorage'
|
||||
|
||||
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 removeItem(key: string): void {
|
||||
sys.localStorage.removeItem(LocalStorage.GamePreFlag + key)
|
||||
}
|
||||
|
||||
public static getInt(key: string): number {
|
||||
const tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) result = Number.parseInt(tempValue)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
public static setInt(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
|
||||
public static getFloat(key: string): number {
|
||||
const tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) result = Number.parseFloat(tempValue)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
public static setFloat(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
|
||||
public static getBoolean(key: string): boolean {
|
||||
const temp: number = LocalStorage.getInt(key)
|
||||
return temp === 1
|
||||
}
|
||||
|
||||
public static setBoolean(key: string, value: boolean) {
|
||||
if (value) LocalStorage.setInt(key, 1)
|
||||
else LocalStorage.setInt(key, 0)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
sys.localStorage.clear()
|
||||
}
|
||||
}
|
||||
import { sys } from 'cc'
|
||||
|
||||
export default class LocalStorage {
|
||||
public static GamePreFlag: string = 'fengshen-game-HaoLocalStorage'
|
||||
|
||||
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 removeItem(key: string): void {
|
||||
sys.localStorage.removeItem(LocalStorage.GamePreFlag + key)
|
||||
}
|
||||
|
||||
public static getInt(key: string): number {
|
||||
const tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) result = Number.parseInt(tempValue)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
public static setInt(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
|
||||
public static getFloat(key: string): number {
|
||||
const tempValue: string = LocalStorage.getItem(key)
|
||||
let result: number = 0
|
||||
if (tempValue) result = Number.parseFloat(tempValue)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
public static setFloat(key: string, value: number): void {
|
||||
LocalStorage.setItem(key, value.toString())
|
||||
}
|
||||
|
||||
public static getBoolean(key: string): boolean {
|
||||
const temp: number = LocalStorage.getInt(key)
|
||||
return temp === 1
|
||||
}
|
||||
|
||||
public static setBoolean(key: string, value: boolean) {
|
||||
if (value) LocalStorage.setInt(key, 1)
|
||||
else LocalStorage.setInt(key, 0)
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
sys.localStorage.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6ac377cd-dfa3-4928-ae69-ae600d9aabb1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6ac377cd-dfa3-4928-ae69-ae600d9aabb1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
class LOG_LEVEL_TYPES {
|
||||
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() {
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.DEBUG)
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.LOG)
|
||||
const 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
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.INFO)
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.WARN)
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.ERROR)
|
||||
const 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)
|
||||
}
|
||||
}
|
||||
class LOG_LEVEL_TYPES {
|
||||
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() {
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.DEBUG)
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.LOG)
|
||||
const 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
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.INFO)
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.WARN)
|
||||
const 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
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.ERROR)
|
||||
const 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "64f5d910-1b40-421a-a57e-315335fd7b33",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "64f5d910-1b40-421a-a57e-315335fd7b33",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export default class MathUtils {
|
||||
/**
|
||||
* 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((x1 - x2) ** 2 + (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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 弧度转角度
|
||||
* @param radians
|
||||
*/
|
||||
public static radiansToDegrees(radians: number) {
|
||||
return (180 / Math.PI) * radians
|
||||
}
|
||||
|
||||
/**
|
||||
* 角度转弧度
|
||||
* @param degrees
|
||||
*/
|
||||
public static degreesToRadians(degrees: number) {
|
||||
return (Math.PI * degrees) / 180
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回2点间的弧度
|
||||
* @param startP
|
||||
* @param endP
|
||||
*/
|
||||
public static p2pRad(startP: Vec2, endP: Vec2) {
|
||||
const 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
|
||||
}
|
||||
}
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export default class MathUtils {
|
||||
/**
|
||||
* 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((x1 - x2) ** 2 + (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)
|
||||
}
|
||||
|
||||
/**
|
||||
* 弧度转角度
|
||||
* @param radians
|
||||
*/
|
||||
public static radiansToDegrees(radians: number) {
|
||||
return (180 / Math.PI) * radians
|
||||
}
|
||||
|
||||
/**
|
||||
* 角度转弧度
|
||||
* @param degrees
|
||||
*/
|
||||
public static degreesToRadians(degrees: number) {
|
||||
return (Math.PI * degrees) / 180
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回2点间的弧度
|
||||
* @param startP
|
||||
* @param endP
|
||||
*/
|
||||
public static p2pRad(startP: Vec2, endP: Vec2) {
|
||||
const 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "93c7eb99-4e1c-4343-9017-b8511388166a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "93c7eb99-4e1c-4343-9017-b8511388166a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
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
|
||||
const rad: number = MathUtils.p2pRad(MoveHelper._vec2_0, MoveHelper._vec2_1)
|
||||
const speedX: number = speed * Math.cos(rad)
|
||||
const 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
|
||||
}
|
||||
}
|
||||
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
|
||||
const rad: number = MathUtils.p2pRad(MoveHelper._vec2_0, MoveHelper._vec2_1)
|
||||
const speedX: number = speed * Math.cos(rad)
|
||||
const 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4304fd05-cb03-46da-a6a6-f742febe535e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4304fd05-cb03-46da-a6a6-f742febe535e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { AssetManager, Prefab, _decorator } from 'cc'
|
||||
|
||||
import { Logger } from './Logger'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('PrefabLoader')
|
||||
export default class PrefabLoader {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
import { AssetManager, Prefab, _decorator } from 'cc'
|
||||
|
||||
import { Logger } from './Logger'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('PrefabLoader')
|
||||
export default class PrefabLoader {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "10db6736-1255-4a28-91a1-fe4c41312d29",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "10db6736-1255-4a28-91a1-fe4c41312d29",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
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)
|
||||
}
|
||||
|
||||
public static nextNumber(minNum: number, maxNum: number) {
|
||||
return Math.random() * (maxNum - minNum) + minNum
|
||||
}
|
||||
|
||||
public static nextSign() {
|
||||
const temp = Math.random()
|
||||
if (temp < 0.5) return 1
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
public static nextBoolean() {
|
||||
const temp = Math.random()
|
||||
return temp < 0.5
|
||||
}
|
||||
|
||||
public static randomArr(nowArr: Array<any>, needNum: number) {
|
||||
const tempArr: Array<any> = nowArr.concat()
|
||||
const resultArr: Array<any> = []
|
||||
for (let index = 0; index < needNum; index++) {
|
||||
if (tempArr.length <= 0) break
|
||||
|
||||
const 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 randomP(left: number, right: number, up: number, down: number) {
|
||||
const randomX: number = RandomUtil.nextNumber(left, right)
|
||||
const randomY: number = RandomUtil.nextNumber(up, down)
|
||||
return new Vec2(randomX, randomY)
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
public static nextNumber(minNum: number, maxNum: number) {
|
||||
return Math.random() * (maxNum - minNum) + minNum
|
||||
}
|
||||
|
||||
public static nextSign() {
|
||||
const temp = Math.random()
|
||||
if (temp < 0.5) return 1
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
public static nextBoolean() {
|
||||
const temp = Math.random()
|
||||
return temp < 0.5
|
||||
}
|
||||
|
||||
public static randomArr(nowArr: Array<any>, needNum: number) {
|
||||
const tempArr: Array<any> = nowArr.concat()
|
||||
const resultArr: Array<any> = []
|
||||
for (let index = 0; index < needNum; index++) {
|
||||
if (tempArr.length <= 0) break
|
||||
|
||||
const 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 randomP(left: number, right: number, up: number, down: number) {
|
||||
const randomX: number = RandomUtil.nextNumber(left, right)
|
||||
const randomY: number = RandomUtil.nextNumber(up, down)
|
||||
return new Vec2(randomX, randomY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "09813185-c544-4799-88cd-3134aa4da011",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "09813185-c544-4799-88cd-3134aa4da011",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,383 +1,383 @@
|
||||
import { Color, Material, Node, UIRenderer, UITransform, Vec2 } from 'cc'
|
||||
|
||||
import ShaderMaterialPrefab from '../../game/prefab/ShaderMaterialPrefab'
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片灰白程度
|
||||
* @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
|
||||
const intervalId = setInterval(() => {
|
||||
grayValue += 0.01
|
||||
if (grayValue >= 1) {
|
||||
grayValue = 1
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
if (showNode) ShaderHelper.setGrayEffect(showNode, grayValue)
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片老化
|
||||
* @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
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不同颜色的发光
|
||||
* @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
|
||||
const color: Color = Color.WHITE
|
||||
let flashTimes: number = 0
|
||||
const intervalId = setInterval(() => {
|
||||
timeCount += 1
|
||||
if (timeCount % 50 === 0) {
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放被攻击闪烁过程动画
|
||||
*/
|
||||
public static showMosaicMv(showNode: Node, callback: Function = null) {
|
||||
let masaicTimes: number = 500
|
||||
const intervalId = setInterval(() => {
|
||||
masaicTimes -= 2
|
||||
this.setMosaic(showNode, {
|
||||
xBlockCount: masaicTimes,
|
||||
yBlockCount: masaicTimes,
|
||||
})
|
||||
if (masaicTimes <= 30) {
|
||||
clearInterval(intervalId)
|
||||
if (callback) callback()
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置圆角剪切
|
||||
* @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)
|
||||
// })
|
||||
// })
|
||||
const setMaterialProperties = (renderer: UIRenderer) => {
|
||||
try {
|
||||
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)
|
||||
renderer.setSharedMaterial(material, 0)
|
||||
} catch (error) {
|
||||
console.error('Error setting material properties:', error)
|
||||
}
|
||||
}
|
||||
const renderComponents = [
|
||||
...showNode.getComponents(UIRenderer),
|
||||
...showNode.children.flatMap(childNode => childNode.getComponents(UIRenderer)),
|
||||
]
|
||||
|
||||
renderComponents.forEach((renderComponent: UIRenderer) => {
|
||||
setMaterialProperties(renderComponent)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家升级shader动画
|
||||
* @param showNode
|
||||
* @param callback
|
||||
*/
|
||||
public static showFlashLightMv(showNode: Node, callback: Function = null) {
|
||||
const nowClor: Color = new Color(0, 0, 0, 255)
|
||||
let colorIndex: number = 0
|
||||
let lightAngle: number = 0
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置高斯模糊
|
||||
* @param showNode
|
||||
* @param material
|
||||
*/
|
||||
public static setGaussian(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(ShaderMaterialPrefab).gaussian,
|
||||
) {
|
||||
showNode.getComponents(UIRenderer).forEach((renderComponent: UIRenderer) => {
|
||||
const tran = renderComponent.node.getComponent(UITransform)
|
||||
material.setProperty('textureSize', new Vec2(tran.contentSize.width, tran.contentSize.height))
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode.getComponents(UIRenderer).forEach((renderComponent: UIRenderer) => {
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
import { Color, Material, Node, UIRenderer, UITransform, Vec2 } from 'cc'
|
||||
|
||||
import ShaderMaterialPrefab from '../../game/prefab/ShaderMaterialPrefab'
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片灰白程度
|
||||
* @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
|
||||
const intervalId = setInterval(() => {
|
||||
grayValue += 0.01
|
||||
if (grayValue >= 1) {
|
||||
grayValue = 1
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
if (showNode) ShaderHelper.setGrayEffect(showNode, grayValue)
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图片老化
|
||||
* @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
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置不同颜色的发光
|
||||
* @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
|
||||
const color: Color = Color.WHITE
|
||||
let flashTimes: number = 0
|
||||
const intervalId = setInterval(() => {
|
||||
timeCount += 1
|
||||
if (timeCount % 50 === 0) {
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放被攻击闪烁过程动画
|
||||
*/
|
||||
public static showMosaicMv(showNode: Node, callback: Function = null) {
|
||||
let masaicTimes: number = 500
|
||||
const intervalId = setInterval(() => {
|
||||
masaicTimes -= 2
|
||||
this.setMosaic(showNode, {
|
||||
xBlockCount: masaicTimes,
|
||||
yBlockCount: masaicTimes,
|
||||
})
|
||||
if (masaicTimes <= 30) {
|
||||
clearInterval(intervalId)
|
||||
if (callback) callback()
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置圆角剪切
|
||||
* @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)
|
||||
// })
|
||||
// })
|
||||
const setMaterialProperties = (renderer: UIRenderer) => {
|
||||
try {
|
||||
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)
|
||||
renderer.setSharedMaterial(material, 0)
|
||||
} catch (error) {
|
||||
console.error('Error setting material properties:', error)
|
||||
}
|
||||
}
|
||||
const renderComponents = [
|
||||
...showNode.getComponents(UIRenderer),
|
||||
...showNode.children.flatMap(childNode => childNode.getComponents(UIRenderer)),
|
||||
]
|
||||
|
||||
renderComponents.forEach((renderComponent: UIRenderer) => {
|
||||
setMaterialProperties(renderComponent)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家升级shader动画
|
||||
* @param showNode
|
||||
* @param callback
|
||||
*/
|
||||
public static showFlashLightMv(showNode: Node, callback: Function = null) {
|
||||
const nowClor: Color = new Color(0, 0, 0, 255)
|
||||
let colorIndex: number = 0
|
||||
let lightAngle: number = 0
|
||||
const 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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置高斯模糊
|
||||
* @param showNode
|
||||
* @param material
|
||||
*/
|
||||
public static setGaussian(
|
||||
showNode: Node,
|
||||
material: Material = ShaderMaterialPrefab.instance.getComponent(ShaderMaterialPrefab).gaussian,
|
||||
) {
|
||||
showNode.getComponents(UIRenderer).forEach((renderComponent: UIRenderer) => {
|
||||
const tran = renderComponent.node.getComponent(UITransform)
|
||||
material.setProperty('textureSize', new Vec2(tran.contentSize.width, tran.contentSize.height))
|
||||
renderComponent.setSharedMaterial(material, 0)
|
||||
})
|
||||
showNode.children.forEach((childNode) => {
|
||||
childNode.getComponents(UIRenderer).forEach((renderComponent: UIRenderer) => {
|
||||
const 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "347c6bb0-da88-4e18-b261-9298e6dcaa7a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "347c6bb0-da88-4e18-b261-9298e6dcaa7a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,133 +1,133 @@
|
||||
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 Config_Game_Name: Array<string> = ['游戏大厅']
|
||||
|
||||
// 热更文件下载来后存放文件夹
|
||||
public static Config_Key: Array<string> = ['main-remote-asset']
|
||||
|
||||
private static Config_ManifestName: string = 'project.manifest'
|
||||
|
||||
public static Config_Url_Key: Array<string> = ['main']
|
||||
|
||||
public iosStoreUrl: string = ''
|
||||
public apkStoreUrl: string = ''
|
||||
|
||||
public nowVersion: string = ManifestConfig.version // 网页显示版本号,如果是热更会替换改值
|
||||
public targetVersion: string = '1.0.0'
|
||||
|
||||
public isOpenHotUpdate: boolean = true // 是否打开热更
|
||||
|
||||
private hotUpdateList: Array<HotUpdate> = []
|
||||
|
||||
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 releaseAll() {
|
||||
for (let i = 0; i < VersionManager.Config_Key.length; i++)
|
||||
if (this.hotUpdateList[i]) this.hotUpdateList[i].disposeUpdate()
|
||||
}
|
||||
|
||||
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 checkUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const 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 startUpdate(keyIndex: number) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
hotUpdate.startUpdate()
|
||||
}
|
||||
|
||||
public isCheck(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex === this.noUpdateIndex) return true
|
||||
|
||||
return hotUpdate.isCheck
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public needUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex === this.noUpdateIndex) return false
|
||||
|
||||
return hotUpdate.needUpdate
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isUpdating(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
return hotUpdate.isUpdating
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isFinishUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex === this.noUpdateIndex) return true
|
||||
|
||||
return hotUpdate.isFinishUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
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 Config_Game_Name: Array<string> = ['游戏大厅']
|
||||
|
||||
// 热更文件下载来后存放文件夹
|
||||
public static Config_Key: Array<string> = ['main-remote-asset']
|
||||
|
||||
private static Config_ManifestName: string = 'project.manifest'
|
||||
|
||||
public static Config_Url_Key: Array<string> = ['main']
|
||||
|
||||
public iosStoreUrl: string = ''
|
||||
public apkStoreUrl: string = ''
|
||||
|
||||
public nowVersion: string = ManifestConfig.version // 网页显示版本号,如果是热更会替换改值
|
||||
public targetVersion: string = '1.0.0'
|
||||
|
||||
public isOpenHotUpdate: boolean = true // 是否打开热更
|
||||
|
||||
private hotUpdateList: Array<HotUpdate> = []
|
||||
|
||||
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 releaseAll() {
|
||||
for (let i = 0; i < VersionManager.Config_Key.length; i++)
|
||||
if (this.hotUpdateList[i]) this.hotUpdateList[i].disposeUpdate()
|
||||
}
|
||||
|
||||
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 checkUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const 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 startUpdate(keyIndex: number) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
hotUpdate.startUpdate()
|
||||
}
|
||||
|
||||
public isCheck(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex === this.noUpdateIndex) return true
|
||||
|
||||
return hotUpdate.isCheck
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public needUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex === this.noUpdateIndex) return false
|
||||
|
||||
return hotUpdate.needUpdate
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isUpdating(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
return hotUpdate.isUpdating
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public isFinishUpdate(keyIndex: number) {
|
||||
if (keyIndex < this.hotUpdateList.length) {
|
||||
const hotUpdate: HotUpdate = this.hotUpdateList[keyIndex]
|
||||
if (keyIndex === this.noUpdateIndex) return true
|
||||
|
||||
return hotUpdate.isFinishUpdate
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c79a6571-dc2f-4715-a5d6-151542eef238",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c79a6571-dc2f-4715-a5d6-151542eef238",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "2ac3d2c9-b418-4202-b672-736c533b89ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "2ac3d2c9-b418-4202-b672-736c533b89ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "37ac4184-546f-4fa8-9030-da49dbe4219c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "37ac4184-546f-4fa8-9030-da49dbe4219c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DEV } from 'cc/env'
|
||||
|
||||
export default {
|
||||
url: () => (DEV ? 'https://fish.wanzhuanyongcheng.cn' : 'https://fish.jdt168.com'),
|
||||
wsUrl: () => (DEV ? 'fish.wanzhuanyongcheng.cn' : 'fish.jdt168.com'),
|
||||
}
|
||||
import { DEV } from 'cc/env'
|
||||
|
||||
export default {
|
||||
url: () => (DEV ? 'https://fish.wanzhuanyongcheng.cn' : 'https://fish.jdt168.com'),
|
||||
wsUrl: () => (DEV ? 'fish.wanzhuanyongcheng.cn' : 'fish.jdt168.com'),
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f01978bd-5d14-49a6-bea7-4b7ad0c82b7b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f01978bd-5d14-49a6-bea7-4b7ad0c82b7b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
import { FishInfo } from './FishInfo'
|
||||
import config from './Config'
|
||||
export class FishConfig {
|
||||
public static config: Array<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),
|
||||
// new FishInfo(1, '蝴蝶鱼'),
|
||||
// new FishInfo(2, '鲶鱼'),
|
||||
// new FishInfo(3, '狮子鱼'),
|
||||
// new FishInfo(4, '条纹鱼'),
|
||||
// new FishInfo(5, '沙丁鱼'),
|
||||
// new FishInfo(6, '石斑鱼'),
|
||||
// new FishInfo(7, '河豚'),
|
||||
// new FishInfo(8, '海螺'),
|
||||
// new FishInfo(9, '接吻鱼'),
|
||||
// new FishInfo(10, '海姆'),
|
||||
// new FishInfo(11, '绿鳍鱼'),
|
||||
// new FishInfo(12, '鲎'),
|
||||
// new FishInfo(13, '魔鬼鱼'),
|
||||
// new FishInfo(14, '小海龟'),
|
||||
// new FishInfo(15, '锤头鲨'),
|
||||
// new FishInfo(16, '金枪鱼'),
|
||||
// new FishInfo(17, '大三元'),
|
||||
// new FishInfo(18, '黄金鲎'),
|
||||
// new FishInfo(19, '大四喜'),
|
||||
// new FishInfo(20, '黄金锤头鲨'),
|
||||
// new FishInfo(21, '金海姆'),
|
||||
// new FishInfo(22, '五福临门'),
|
||||
// new FishInfo(23, '金海龟'),
|
||||
// new FishInfo(24, '金鲨'),
|
||||
// new FishInfo(25, '蓝鲨'),
|
||||
// new FishInfo(26, '美人鱼'),
|
||||
// new FishInfo(27, '金龙'),
|
||||
// new FishInfo(28, '章鱼'),
|
||||
// new FishInfo(29, '电鳗鱼'),
|
||||
]
|
||||
|
||||
public static async init() {
|
||||
this.config = []
|
||||
return new Promise<boolean>((resolve) => {
|
||||
fetch(`${config.url()}/fish/list`)
|
||||
.then((response) => response.text())
|
||||
.then((response) => {
|
||||
const { data: res } = JSON.parse(response)
|
||||
res.data.forEach((item) => {
|
||||
this.config.push(new FishInfo(item.ID, item.name, item.health))
|
||||
})
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public static getFishInfoByType(fishType: number) {
|
||||
for (let i = 0; i < this.config.length; i++) {
|
||||
const fishInfo: FishInfo = this.config[i]
|
||||
if (fishInfo.fishType === fishType) return fishInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
import { FishInfo } from './FishInfo'
|
||||
import config from './Config'
|
||||
export class FishConfig {
|
||||
public static config: Array<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),
|
||||
// new FishInfo(1, '蝴蝶鱼'),
|
||||
// new FishInfo(2, '鲶鱼'),
|
||||
// new FishInfo(3, '狮子鱼'),
|
||||
// new FishInfo(4, '条纹鱼'),
|
||||
// new FishInfo(5, '沙丁鱼'),
|
||||
// new FishInfo(6, '石斑鱼'),
|
||||
// new FishInfo(7, '河豚'),
|
||||
// new FishInfo(8, '海螺'),
|
||||
// new FishInfo(9, '接吻鱼'),
|
||||
// new FishInfo(10, '海姆'),
|
||||
// new FishInfo(11, '绿鳍鱼'),
|
||||
// new FishInfo(12, '鲎'),
|
||||
// new FishInfo(13, '魔鬼鱼'),
|
||||
// new FishInfo(14, '小海龟'),
|
||||
// new FishInfo(15, '锤头鲨'),
|
||||
// new FishInfo(16, '金枪鱼'),
|
||||
// new FishInfo(17, '大三元'),
|
||||
// new FishInfo(18, '黄金鲎'),
|
||||
// new FishInfo(19, '大四喜'),
|
||||
// new FishInfo(20, '黄金锤头鲨'),
|
||||
// new FishInfo(21, '金海姆'),
|
||||
// new FishInfo(22, '五福临门'),
|
||||
// new FishInfo(23, '金海龟'),
|
||||
// new FishInfo(24, '金鲨'),
|
||||
// new FishInfo(25, '蓝鲨'),
|
||||
// new FishInfo(26, '美人鱼'),
|
||||
// new FishInfo(27, '金龙'),
|
||||
// new FishInfo(28, '章鱼'),
|
||||
// new FishInfo(29, '电鳗鱼'),
|
||||
]
|
||||
|
||||
public static async init() {
|
||||
this.config = []
|
||||
return new Promise<boolean>((resolve) => {
|
||||
fetch(`${config.url()}/fish/list`)
|
||||
.then((response) => response.text())
|
||||
.then((response) => {
|
||||
const { data: res } = JSON.parse(response)
|
||||
res.data.forEach((item) => {
|
||||
this.config.push(new FishInfo(item.ID, item.name, item.health))
|
||||
})
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public static getFishInfoByType(fishType: number) {
|
||||
for (let i = 0; i < this.config.length; i++) {
|
||||
const fishInfo: FishInfo = this.config[i]
|
||||
if (fishInfo.fishType === fishType) return fishInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c7516237-7eb2-4767-8cc7-7ce0b2d5484e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c7516237-7eb2-4767-8cc7-7ce0b2d5484e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "03f14923-6d67-4d91-97ad-a81bf4f1551f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "03f14923-6d67-4d91-97ad-a81bf4f1551f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f84ce3e3-8c47-43ff-a6f4-7cda4c320fcf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f84ce3e3-8c47-43ff-a6f4-7cda4c320fcf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5f3df30a-4677-4f9c-97a9-e80fcb5b8295",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "5f3df30a-4677-4f9c-97a9-e80fcb5b8295",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "704e17b3-0f7b-478a-8ad1-1cb2f5d89a8f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "704e17b3-0f7b-478a-8ad1-1cb2f5d89a8f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export class FishPathInfo {
|
||||
public pathId: string
|
||||
public path: Array<Vec2> = []
|
||||
|
||||
constructor(pathId: string, path: Array<Vec2>) {
|
||||
this.pathId = pathId
|
||||
this.path = path
|
||||
}
|
||||
}
|
||||
import { Vec2 } from 'cc'
|
||||
|
||||
export class FishPathInfo {
|
||||
public pathId: string
|
||||
public path: Array<Vec2> = []
|
||||
|
||||
constructor(pathId: string, path: Array<Vec2>) {
|
||||
this.pathId = pathId
|
||||
this.path = path
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "01cc78a7-9862-45b4-ad09-ebb92c01de58",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "01cc78a7-9862-45b4-ad09-ebb92c01de58",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export class GameConfig {
|
||||
public static GameName: string = 'FishSingle'
|
||||
}
|
||||
export class GameConfig {
|
||||
public static GameName: string = 'FishSingle'
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8b274344-0b4c-4ac5-a289-2f8cd7a5596b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8b274344-0b4c-4ac5-a289-2f8cd7a5596b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "1e8eeb35-adbc-485b-879b-bf95de554cfd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "1e8eeb35-adbc-485b-879b-bf95de554cfd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,156 +1,156 @@
|
||||
import {
|
||||
Component,
|
||||
EventTouch,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
instantiate,
|
||||
sys,
|
||||
} from 'cc'
|
||||
|
||||
import FishBulletBase from '../../../fish/script/FishBulletBase'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
|
||||
import { MoveHelper } from '../../engine/utils/MoveHelper'
|
||||
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
|
||||
import CannonManager from './CannonManager'
|
||||
import FishNetManager from './FishNetManager'
|
||||
import WsManager from './WsManager'
|
||||
|
||||
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: Vec3
|
||||
private _vec2Cache: Vec2
|
||||
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)
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
update() {
|
||||
this.checkMoveBullet()
|
||||
}
|
||||
|
||||
// 检测子弹是否移动完成
|
||||
private checkMoveBullet() {
|
||||
for (let i = this.bulletList.length - 1; i >= 0; i--) {
|
||||
const bullet: FishBulletBase = this.bulletList[i]
|
||||
const 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 发射炮弹
|
||||
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 < 15000) return
|
||||
this._fireTime = this._fireTimeNew
|
||||
}
|
||||
|
||||
const tran = this.node.getComponent(UITransform)
|
||||
const location = event.getUILocation()
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
const 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()
|
||||
const rad: number = MathUtils.p2pRad(new Vec2(this._vec3Cache.x, this._vec3Cache.y), localP)
|
||||
const rot: number = MathUtils.radiansToDegrees(rad)
|
||||
const 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()
|
||||
// 旋转炮台
|
||||
CannonManager.instance.rotateCannon(location)
|
||||
} else {
|
||||
CommonTips.showMsg('豆子不足!')
|
||||
}
|
||||
}
|
||||
|
||||
// 创建子弹
|
||||
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)
|
||||
}
|
||||
|
||||
public killBullet(bullet: FishBulletBase) {
|
||||
const index: number = this.bulletList.indexOf(bullet)
|
||||
if (index >= 0) {
|
||||
this.bulletList.splice(index, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁子弹
|
||||
private destroyBullet(bullet: FishBulletBase) {
|
||||
// 临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
|
||||
if (sys.platform === 'EDITOR_PAGE') {
|
||||
bullet.node.destroy()
|
||||
return
|
||||
}
|
||||
if (!this.bulletPool[bullet.bulletType]) this.bulletPool[bullet.bulletType] = new NodePool()
|
||||
this.bulletPool[bullet.bulletType].put(bullet.node)
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
BulletManager.instance = null
|
||||
}
|
||||
}
|
||||
import {
|
||||
Component,
|
||||
EventTouch,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
instantiate,
|
||||
sys,
|
||||
} from 'cc'
|
||||
|
||||
import FishBulletBase from '../../../fish/script/FishBulletBase'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import MathUtils from '../../engine/utils/MathUtils'
|
||||
|
||||
import { MoveHelper } from '../../engine/utils/MoveHelper'
|
||||
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
|
||||
import CannonManager from './CannonManager'
|
||||
import FishNetManager from './FishNetManager'
|
||||
import WsManager from './WsManager'
|
||||
|
||||
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: Vec3
|
||||
private _vec2Cache: Vec2
|
||||
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)
|
||||
}
|
||||
|
||||
start() {}
|
||||
|
||||
update() {
|
||||
this.checkMoveBullet()
|
||||
}
|
||||
|
||||
// 检测子弹是否移动完成
|
||||
private checkMoveBullet() {
|
||||
for (let i = this.bulletList.length - 1; i >= 0; i--) {
|
||||
const bullet: FishBulletBase = this.bulletList[i]
|
||||
const 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 发射炮弹
|
||||
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 < 15000) return
|
||||
this._fireTime = this._fireTimeNew
|
||||
}
|
||||
|
||||
const tran = this.node.getComponent(UITransform)
|
||||
const location = event.getUILocation()
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
const 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()
|
||||
const rad: number = MathUtils.p2pRad(new Vec2(this._vec3Cache.x, this._vec3Cache.y), localP)
|
||||
const rot: number = MathUtils.radiansToDegrees(rad)
|
||||
const 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()
|
||||
// 旋转炮台
|
||||
CannonManager.instance.rotateCannon(location)
|
||||
} else {
|
||||
CommonTips.showMsg('豆子不足!')
|
||||
}
|
||||
}
|
||||
|
||||
// 创建子弹
|
||||
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)
|
||||
}
|
||||
|
||||
public killBullet(bullet: FishBulletBase) {
|
||||
const index: number = this.bulletList.indexOf(bullet)
|
||||
if (index >= 0) {
|
||||
this.bulletList.splice(index, 1)
|
||||
this.destroyBullet(bullet)
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁子弹
|
||||
private destroyBullet(bullet: FishBulletBase) {
|
||||
// 临时代码,因为回收在内存卡顿。后面在优化 2023-2-10
|
||||
if (sys.platform === 'EDITOR_PAGE') {
|
||||
bullet.node.destroy()
|
||||
return
|
||||
}
|
||||
if (!this.bulletPool[bullet.bulletType]) this.bulletPool[bullet.bulletType] = new NodePool()
|
||||
this.bulletPool[bullet.bulletType].put(bullet.node)
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
BulletManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bd065d0b-0b60-4981-aea0-75d2f209b7ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bd065d0b-0b60-4981-aea0-75d2f209b7ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
import {
|
||||
Component,
|
||||
EventMouse,
|
||||
Node,
|
||||
Sprite,
|
||||
SpriteFrame,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
} 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: 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())
|
||||
}
|
||||
|
||||
// 炮塔旋转
|
||||
public rotateCannon(uilocation: Vec2) {
|
||||
const location = uilocation
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
const tran = this.node.getComponent(UITransform)
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
|
||||
const localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
this.view.getPosition(this._vec3Cache)
|
||||
const rad: number = MathUtils.p2pRad(new Vec2(this._vec3Cache.x, this._vec3Cache.y), localTouch)
|
||||
const 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
|
||||
}
|
||||
}
|
||||
import {
|
||||
Component,
|
||||
EventMouse,
|
||||
Node,
|
||||
Sprite,
|
||||
SpriteFrame,
|
||||
UITransform,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
} 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: 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())
|
||||
}
|
||||
|
||||
// 炮塔旋转
|
||||
public rotateCannon(uilocation: Vec2) {
|
||||
const location = uilocation
|
||||
this._vec3Cache.x = location.x
|
||||
this._vec3Cache.y = location.y
|
||||
this._vec3Cache.z = 0
|
||||
const tran = this.node.getComponent(UITransform)
|
||||
tran.convertToNodeSpaceAR(this._vec3Cache, this._vec3Cache)
|
||||
|
||||
const localTouch: Vec2 = new Vec2(this._vec3Cache.x, this._vec3Cache.y)
|
||||
this.view.getPosition(this._vec3Cache)
|
||||
const rad: number = MathUtils.p2pRad(new Vec2(this._vec3Cache.x, this._vec3Cache.y), localTouch)
|
||||
const 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d03d3fa0-9f23-4106-be05-9d106bd8f8c8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d03d3fa0-9f23-4106-be05-9d106bd8f8c8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,272 +1,272 @@
|
||||
import {
|
||||
Animation,
|
||||
Component,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
Tween,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
game,
|
||||
instantiate,
|
||||
tween,
|
||||
} from 'cc'
|
||||
|
||||
import FishBase from '../../../fish/script/FishBase'
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishConfig } from '../config/FishConfig'
|
||||
import { FishInfo } from '../config/FishInfo'
|
||||
import { FishMap } from '../config/FishMap'
|
||||
import { FishMapInfo } from '../config/FishMapInfo'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
|
||||
import TimeHelper from '../utils/TimeHelper'
|
||||
|
||||
import ScoreManager from './ScoreManager'
|
||||
import WsManager from './WsManager'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
interface dataType {
|
||||
fisn: Array<FishType>
|
||||
}
|
||||
|
||||
interface FishType {
|
||||
fishId: string
|
||||
fishInfo: FishInfo
|
||||
fishType: string
|
||||
isDead: number
|
||||
fishPathInfo: Array<fishPathInfoType>
|
||||
}
|
||||
|
||||
interface fishPathInfoType {
|
||||
pathId: string
|
||||
path: Array<PathPoint>
|
||||
}
|
||||
|
||||
interface PathPoint {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
// 鱼管理类
|
||||
@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: Map<string, FishBase> = new Map()
|
||||
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 _fishPosCache: Vec3
|
||||
|
||||
onLoad() {
|
||||
WsManager.instance.on(100, this.randomFish, this)
|
||||
FishManager.instance = this
|
||||
this._fishPosCache = new Vec3()
|
||||
Logger.log('maxRandomTime=', this.minRandomTime, this.maxRandomTime, game.frameRate)
|
||||
}
|
||||
|
||||
start() {
|
||||
// this.randomFish()
|
||||
}
|
||||
|
||||
update() {
|
||||
// this.checkRandomFish()
|
||||
this.checkFishMoveEnd()
|
||||
// this.checkFishMap()
|
||||
}
|
||||
|
||||
private checkFishMap() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.mapCount > 0) {
|
||||
this.mapCount--
|
||||
if (this.mapCount <= 0) FishUI.instance.playWaveEffect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否随机鱼
|
||||
private checkRandomFish() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.nextRandomFishTime > 0) {
|
||||
this.nextRandomFishTime--
|
||||
// if (this.nextRandomFishTime === 0) this.randomFish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测鱼是否移动结束
|
||||
private checkFishMoveEnd() {
|
||||
this.fishList.forEach(async (item: FishBase, key: string) => {
|
||||
if (this.isFishMap) {
|
||||
// 鱼阵回收
|
||||
if (item.isDead === 2) {
|
||||
item.node.getPosition(this._fishPosCache)
|
||||
this._fishPosCache.x -= 2
|
||||
item.node.setPosition(this._fishPosCache)
|
||||
if (this._fishPosCache.x <= -screen.width / 2) {
|
||||
// winSize.width
|
||||
await WsManager.instance.onSend({
|
||||
type: 102,
|
||||
fish_id: item.fishId,
|
||||
})
|
||||
// this.fishList.splice(index, 1)
|
||||
this.destroyFish(item)
|
||||
// this.fishList.delete(item.fishId)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
} else if (!item.getComponent(FishMover).isMoving) {
|
||||
// 普通鱼回收
|
||||
await WsManager.instance.onSend({
|
||||
type: 102,
|
||||
fish_id: item.fishId,
|
||||
})
|
||||
// this.fishList.splice(index, 1)
|
||||
this.destroyFish(item)
|
||||
// this.fishList.delete(item.fishId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private checkEndFishMap() {
|
||||
// Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
|
||||
if (this.isFishMap && this.fishList.size <= 0) {
|
||||
this.isFishMap = false
|
||||
// this.randomFish()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 原:本地随机生成鱼
|
||||
* 新:服务端生成鱼
|
||||
*/
|
||||
private async randomFish(data: dataType) {
|
||||
const arr = data.fisn
|
||||
const paths: Array<FishPathInfo> = []
|
||||
if (!Array.isArray(arr) || this.isFishMap) return
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const fish: FishBase = this.createFishByType(arr[i])
|
||||
for (let k = 0; k < arr[i].fishPathInfo.length; k++) {
|
||||
const path: Array<Vec2> = []
|
||||
|
||||
for (let j = 0; j < arr[i].fishPathInfo[k].path.length; j++) {
|
||||
const p: Vec2 = new Vec2(
|
||||
arr[i].fishPathInfo[k].path[j].x,
|
||||
arr[i].fishPathInfo[k].path[j].y,
|
||||
)
|
||||
path.push(p)
|
||||
}
|
||||
paths.push(new FishPathInfo(arr[i].fishPathInfo[k].pathId, path))
|
||||
}
|
||||
fish.fishPathInfo = paths[0]
|
||||
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.fishList.set(fish.fishId, fish)
|
||||
// this.fishContainer.addChild(fish.node)
|
||||
this.fishContainer.addChild(this.fishList.get(fish.fishId).node)
|
||||
}
|
||||
}
|
||||
|
||||
// 创建鱼类
|
||||
public createFishByType(data: FishType | any): FishBase {
|
||||
let fishNode: Node
|
||||
const fishType: number = Number(data.fishType)
|
||||
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
|
||||
fishNode = this.fishPool[fishType - 1].get()
|
||||
} else {
|
||||
fishNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
}
|
||||
TimeHelper.exeNextFrame(fishNode, () => fishNode.getComponent(Animation).play())
|
||||
const fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
|
||||
fishNode.getComponent(FishBase).fishInfo = fishInfo
|
||||
fishNode.getComponent(FishBase).fishType = fishType
|
||||
fishNode.getComponent(FishBase).fishId = data.fishId
|
||||
fishNode.getComponent(FishBase).isDead = 2
|
||||
return fishNode.getComponent(FishBase)
|
||||
}
|
||||
|
||||
// 销毁鱼类
|
||||
public killFish(res: any) {
|
||||
const fishCheck = this.fishList.get(res.fish_id)
|
||||
// console.log('正在执行销毁=', fishCheck.fishId, res.fish_id, res.fish_status, fishCheck.isDead)
|
||||
if (fishCheck) {
|
||||
fishCheck.isDead = 1
|
||||
setTimeout(() => {
|
||||
GameMusicHelper.playFishDead(fishCheck.fishType)
|
||||
fishCheck.node.getPosition(this._fishPosCache)
|
||||
const vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
|
||||
ScoreManager.instance.addScore(Number(res.fish_number), vec2)
|
||||
this.destroyFish(fishCheck)
|
||||
// console.log('killFish=', fishCheck.fishId, fishCheck.fishInfo.name)
|
||||
this.checkEndFishMap()
|
||||
}, 500)
|
||||
tween(fishCheck.node)
|
||||
.repeatForever(tween().by(0.6, { angle: -360 }))
|
||||
.start()
|
||||
|
||||
// this.fishList.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
private destroyFish(fish: FishBase) {
|
||||
const f = this.fishList.get(fish.fishId)
|
||||
if (!f) return
|
||||
if (!this.fishPool[f.fishType - 1]) {
|
||||
this.fishPool[f.fishType - 1] = new NodePool()
|
||||
}
|
||||
this.fishPool[f.fishType - 1].put(f.node)
|
||||
this.fishList.delete(f.fishId)
|
||||
}
|
||||
|
||||
public playFishMap() {
|
||||
this.isFishMap = true
|
||||
this.fishList.forEach((fish: FishBase, key: string) => {
|
||||
this.destroyFish(fish)
|
||||
})
|
||||
}
|
||||
|
||||
public startFishMap() {
|
||||
const map: FishMap = FishPathConfig.randomFishMap()
|
||||
const fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
|
||||
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
|
||||
for (let i = 0; i < fishMapInfoList.length; i++) {
|
||||
const fishMapInfo: FishMapInfo = fishMapInfoList[i]
|
||||
// 暂时屏蔽
|
||||
// @ts-ignore
|
||||
const fish: FishBase = this.createFishByType(fishMapInfo.fishType)
|
||||
fish.node.angle = 0
|
||||
this.fishContainer.addChild(fish.node)
|
||||
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
|
||||
this.fishList.set(fish.fishId, fish)
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishManager.instance = null
|
||||
WsManager.instance.off(100)
|
||||
}
|
||||
|
||||
protected onDisable(): void {}
|
||||
}
|
||||
import {
|
||||
Animation,
|
||||
Component,
|
||||
Node,
|
||||
NodePool,
|
||||
Prefab,
|
||||
Tween,
|
||||
Vec2,
|
||||
Vec3,
|
||||
_decorator,
|
||||
game,
|
||||
instantiate,
|
||||
tween,
|
||||
} from 'cc'
|
||||
|
||||
import FishBase from '../../../fish/script/FishBase'
|
||||
import FishMover from '../../../fish/script/FishMover'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import { Logger } from '../../engine/utils/Logger'
|
||||
import RandomUtil from '../../engine/utils/RandomUtil'
|
||||
import { FishConfig } from '../config/FishConfig'
|
||||
import { FishInfo } from '../config/FishInfo'
|
||||
import { FishMap } from '../config/FishMap'
|
||||
import { FishMapInfo } from '../config/FishMapInfo'
|
||||
import { FishPathConfig } from '../config/FishPathConfig'
|
||||
import GameMusicHelper from '../utils/GameMusicHelper'
|
||||
|
||||
import TimeHelper from '../utils/TimeHelper'
|
||||
|
||||
import ScoreManager from './ScoreManager'
|
||||
import WsManager from './WsManager'
|
||||
import { FishPathInfo } from '../config/FishPathInfo'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
interface dataType {
|
||||
fisn: Array<FishType>
|
||||
}
|
||||
|
||||
interface FishType {
|
||||
fishId: string
|
||||
fishInfo: FishInfo
|
||||
fishType: string
|
||||
isDead: number
|
||||
fishPathInfo: Array<fishPathInfoType>
|
||||
}
|
||||
|
||||
interface fishPathInfoType {
|
||||
pathId: string
|
||||
path: Array<PathPoint>
|
||||
}
|
||||
|
||||
interface PathPoint {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
// 鱼管理类
|
||||
@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: Map<string, FishBase> = new Map()
|
||||
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 _fishPosCache: Vec3
|
||||
|
||||
onLoad() {
|
||||
WsManager.instance.on(100, this.randomFish, this)
|
||||
FishManager.instance = this
|
||||
this._fishPosCache = new Vec3()
|
||||
Logger.log('maxRandomTime=', this.minRandomTime, this.maxRandomTime, game.frameRate)
|
||||
}
|
||||
|
||||
start() {
|
||||
// this.randomFish()
|
||||
}
|
||||
|
||||
update() {
|
||||
// this.checkRandomFish()
|
||||
this.checkFishMoveEnd()
|
||||
// this.checkFishMap()
|
||||
}
|
||||
|
||||
private checkFishMap() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.mapCount > 0) {
|
||||
this.mapCount--
|
||||
if (this.mapCount <= 0) FishUI.instance.playWaveEffect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否随机鱼
|
||||
private checkRandomFish() {
|
||||
if (!this.isFishMap) {
|
||||
if (this.nextRandomFishTime > 0) {
|
||||
this.nextRandomFishTime--
|
||||
// if (this.nextRandomFishTime === 0) this.randomFish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测鱼是否移动结束
|
||||
private checkFishMoveEnd() {
|
||||
this.fishList.forEach(async (item: FishBase, key: string) => {
|
||||
if (this.isFishMap) {
|
||||
// 鱼阵回收
|
||||
if (item.isDead === 2) {
|
||||
item.node.getPosition(this._fishPosCache)
|
||||
this._fishPosCache.x -= 2
|
||||
item.node.setPosition(this._fishPosCache)
|
||||
if (this._fishPosCache.x <= -screen.width / 2) {
|
||||
// winSize.width
|
||||
await WsManager.instance.onSend({
|
||||
type: 102,
|
||||
fish_id: item.fishId,
|
||||
})
|
||||
// this.fishList.splice(index, 1)
|
||||
this.destroyFish(item)
|
||||
// this.fishList.delete(item.fishId)
|
||||
this.checkEndFishMap()
|
||||
}
|
||||
}
|
||||
} else if (!item.getComponent(FishMover).isMoving) {
|
||||
// 普通鱼回收
|
||||
await WsManager.instance.onSend({
|
||||
type: 102,
|
||||
fish_id: item.fishId,
|
||||
})
|
||||
// this.fishList.splice(index, 1)
|
||||
this.destroyFish(item)
|
||||
// this.fishList.delete(item.fishId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private checkEndFishMap() {
|
||||
// Logger.log('checkEndFishMap==', this.isFishMap, this.fishList)
|
||||
if (this.isFishMap && this.fishList.size <= 0) {
|
||||
this.isFishMap = false
|
||||
// this.randomFish()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 原:本地随机生成鱼
|
||||
* 新:服务端生成鱼
|
||||
*/
|
||||
private async randomFish(data: dataType) {
|
||||
const arr = data.fisn
|
||||
const paths: Array<FishPathInfo> = []
|
||||
if (!Array.isArray(arr) || this.isFishMap) return
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const fish: FishBase = this.createFishByType(arr[i])
|
||||
for (let k = 0; k < arr[i].fishPathInfo.length; k++) {
|
||||
const path: Array<Vec2> = []
|
||||
|
||||
for (let j = 0; j < arr[i].fishPathInfo[k].path.length; j++) {
|
||||
const p: Vec2 = new Vec2(
|
||||
arr[i].fishPathInfo[k].path[j].x,
|
||||
arr[i].fishPathInfo[k].path[j].y,
|
||||
)
|
||||
path.push(p)
|
||||
}
|
||||
paths.push(new FishPathInfo(arr[i].fishPathInfo[k].pathId, path))
|
||||
}
|
||||
fish.fishPathInfo = paths[0]
|
||||
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.fishList.set(fish.fishId, fish)
|
||||
// this.fishContainer.addChild(fish.node)
|
||||
this.fishContainer.addChild(this.fishList.get(fish.fishId).node)
|
||||
}
|
||||
}
|
||||
|
||||
// 创建鱼类
|
||||
public createFishByType(data: FishType | any): FishBase {
|
||||
let fishNode: Node
|
||||
const fishType: number = Number(data.fishType)
|
||||
if (this.fishPool[fishType - 1] && this.fishPool[fishType - 1].size() > 0) {
|
||||
fishNode = this.fishPool[fishType - 1].get()
|
||||
} else {
|
||||
fishNode = instantiate(this.fishPrefabList[fishType - 1])
|
||||
}
|
||||
TimeHelper.exeNextFrame(fishNode, () => fishNode.getComponent(Animation).play())
|
||||
const fishInfo: FishInfo = FishConfig.getFishInfoByType(fishType)
|
||||
fishNode.getComponent(FishBase).fishInfo = fishInfo
|
||||
fishNode.getComponent(FishBase).fishType = fishType
|
||||
fishNode.getComponent(FishBase).fishId = data.fishId
|
||||
fishNode.getComponent(FishBase).isDead = 2
|
||||
return fishNode.getComponent(FishBase)
|
||||
}
|
||||
|
||||
// 销毁鱼类
|
||||
public killFish(res: any) {
|
||||
const fishCheck = this.fishList.get(res.fish_id)
|
||||
// console.log('正在执行销毁=', fishCheck.fishId, res.fish_id, res.fish_status, fishCheck.isDead)
|
||||
if (fishCheck) {
|
||||
fishCheck.isDead = 1
|
||||
setTimeout(() => {
|
||||
GameMusicHelper.playFishDead(fishCheck.fishType)
|
||||
fishCheck.node.getPosition(this._fishPosCache)
|
||||
const vec2 = new Vec2(this._fishPosCache.x, this._fishPosCache.y)
|
||||
ScoreManager.instance.addScore(Number(res.fish_number), vec2)
|
||||
this.destroyFish(fishCheck)
|
||||
// console.log('killFish=', fishCheck.fishId, fishCheck.fishInfo.name)
|
||||
this.checkEndFishMap()
|
||||
}, 500)
|
||||
tween(fishCheck.node)
|
||||
.repeatForever(tween().by(0.6, { angle: -360 }))
|
||||
.start()
|
||||
|
||||
// this.fishList.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
private destroyFish(fish: FishBase) {
|
||||
const f = this.fishList.get(fish.fishId)
|
||||
if (!f) return
|
||||
if (!this.fishPool[f.fishType - 1]) {
|
||||
this.fishPool[f.fishType - 1] = new NodePool()
|
||||
}
|
||||
this.fishPool[f.fishType - 1].put(f.node)
|
||||
this.fishList.delete(f.fishId)
|
||||
}
|
||||
|
||||
public playFishMap() {
|
||||
this.isFishMap = true
|
||||
this.fishList.forEach((fish: FishBase, key: string) => {
|
||||
this.destroyFish(fish)
|
||||
})
|
||||
}
|
||||
|
||||
public startFishMap() {
|
||||
const map: FishMap = FishPathConfig.randomFishMap()
|
||||
const fishMapInfoList: Array<FishMapInfo> = map.fishMapInfoList
|
||||
Logger.log('startFishMap==', this.isFishMap, this.fishList, map)
|
||||
for (let i = 0; i < fishMapInfoList.length; i++) {
|
||||
const fishMapInfo: FishMapInfo = fishMapInfoList[i]
|
||||
// 暂时屏蔽
|
||||
// @ts-ignore
|
||||
const fish: FishBase = this.createFishByType(fishMapInfo.fishType)
|
||||
fish.node.angle = 0
|
||||
this.fishContainer.addChild(fish.node)
|
||||
fish.node.setPosition(fishMapInfo.x + screen.width, fishMapInfo.y)
|
||||
this.fishList.set(fish.fishId, fish)
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
FishManager.instance = null
|
||||
WsManager.instance.off(100)
|
||||
}
|
||||
|
||||
protected onDisable(): void {}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b20609a9-5a1b-4119-9fb1-399b45155aab",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b20609a9-5a1b-4119-9fb1-399b45155aab",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
import { Component, Node, NodePool, Prefab, Vec2, Vec3, _decorator, instantiate } 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 addFishNet(netType: number, p: Vec2) {
|
||||
const fishNet: FishNetBase = this.createFishNet(netType)
|
||||
this.node.addChild(fishNet.node)
|
||||
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
fishNet.playMv()
|
||||
}
|
||||
|
||||
// 创建鱼网
|
||||
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 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
|
||||
}
|
||||
}
|
||||
import { Component, Node, NodePool, Prefab, Vec2, Vec3, _decorator, instantiate } 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 addFishNet(netType: number, p: Vec2) {
|
||||
const fishNet: FishNetBase = this.createFishNet(netType)
|
||||
this.node.addChild(fishNet.node)
|
||||
fishNet.node.setPosition(new Vec3(p.x, p.y, 0))
|
||||
fishNet.playMv()
|
||||
}
|
||||
|
||||
// 创建鱼网
|
||||
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 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,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fec491b0-4f6f-4a17-928d-a4ee3c2bb567",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fec491b0-4f6f-4a17-928d-a4ee3c2bb567",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
import { Component, Node, NodePool, Prefab, Vec2, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import ScorePrefab from '../prefab/ScorePrefab'
|
||||
|
||||
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 addScore(score: number, p: Vec2) {
|
||||
const 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 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)
|
||||
}
|
||||
|
||||
// 销毁积分
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
|
||||
onDisable() {}
|
||||
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
}
|
||||
}
|
||||
import { Component, Node, NodePool, Prefab, Vec2, Vec3, _decorator, instantiate } from 'cc'
|
||||
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import ScorePrefab from '../prefab/ScorePrefab'
|
||||
|
||||
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 addScore(score: number, p: Vec2) {
|
||||
const 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 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)
|
||||
}
|
||||
|
||||
// 销毁积分
|
||||
private destroyScore(scorePrefab: ScorePrefab) {
|
||||
this.scorePool.put(scorePrefab.node)
|
||||
}
|
||||
|
||||
onDisable() {}
|
||||
|
||||
onDestroy() {
|
||||
ScoreManager.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ff2defbe-9c85-4632-b16a-021567da1bdd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ff2defbe-9c85-4632-b16a-021567da1bdd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
import { _decorator } from 'cc'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import config from '../config/Config'
|
||||
|
||||
export default class WsManager {
|
||||
private static _instance: WsManager = null
|
||||
uid: string
|
||||
|
||||
message: any
|
||||
|
||||
t_id: any = null
|
||||
|
||||
public static get instance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new WsManager()
|
||||
}
|
||||
return this._instance
|
||||
}
|
||||
|
||||
private _socket: WebSocket | null = null
|
||||
|
||||
protected m_mapCallbackFun: Map<number, Function>
|
||||
|
||||
constructor() {
|
||||
this.m_mapCallbackFun = new Map<number, Function>()
|
||||
}
|
||||
|
||||
public on(msgId: number, cb: Function, target: any) {
|
||||
let callback = cb.bind(target)
|
||||
let fnCallback: Function = this.m_mapCallbackFun.get(msgId)
|
||||
if (fnCallback) {
|
||||
console.error('重复注册消息处理函数! msgId:' + msgId)
|
||||
} else {
|
||||
this.m_mapCallbackFun.set(msgId, callback)
|
||||
}
|
||||
}
|
||||
|
||||
public off(msgId: number) {
|
||||
if (this.m_mapCallbackFun.has(msgId)) {
|
||||
this.m_mapCallbackFun.delete(msgId)
|
||||
}
|
||||
}
|
||||
|
||||
public get(msgId: number) {
|
||||
return this.m_mapCallbackFun.get(msgId)
|
||||
}
|
||||
|
||||
public offAll() {
|
||||
this.m_mapCallbackFun.clear()
|
||||
}
|
||||
|
||||
// 获取url参数
|
||||
public getQueryString(name: string) {
|
||||
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
|
||||
var r = window.location.search.substr(1).match(reg)
|
||||
if (r != null) {
|
||||
return unescape(r[2])
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
this.uid = this.getQueryString('uid')
|
||||
this._socket = new WebSocket(`wss://${config.wsUrl()}/fish/home?uid=${this.uid}`)
|
||||
|
||||
// 添加事件监听器
|
||||
this._socket.onopen = this.onOpen.bind(this)
|
||||
this._socket.onmessage = this.onMessage.bind(this)
|
||||
this._socket.onclose = this.onClose.bind(this)
|
||||
this._socket.onerror = this.onError.bind(this)
|
||||
}
|
||||
|
||||
public onOpen(): void {
|
||||
console.log('WebSocket connection opened.')
|
||||
setInterval(() => {
|
||||
this._socket.send(JSON.stringify('ping'))
|
||||
}, 20000)
|
||||
this.clear()
|
||||
}
|
||||
|
||||
public async onSend(data: any): Promise<void> {
|
||||
if (this._socket && this._socket.readyState === WebSocket.OPEN) {
|
||||
this._socket.send(JSON.stringify(data))
|
||||
} else {
|
||||
console.error('消息发送失败!!!')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理接收到的消息
|
||||
* @param event WebSocket message event
|
||||
*/
|
||||
public onMessage(event: MessageEvent): void {
|
||||
this.message = JSON.parse(event.data)
|
||||
|
||||
if (this.message.code === 200 || this.message.code === 5) {
|
||||
FishUI.instance.refreshScore(this.message)
|
||||
}
|
||||
|
||||
let fnCallback: Function = this.m_mapCallbackFun.get(this.message.code)
|
||||
|
||||
if (fnCallback) {
|
||||
fnCallback(this.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭WebSocket连接
|
||||
*/
|
||||
public onClose(): void {
|
||||
console.log('链接已关闭')
|
||||
CommonTips.showMsg('游戏服务器中断关闭,正在重试')
|
||||
// this.init()
|
||||
if (this._socket) {
|
||||
this._socket.close()
|
||||
this._socket = null
|
||||
}
|
||||
this.t_id = setInterval(() => {
|
||||
WsManager.instance.init()
|
||||
}, 8000)
|
||||
}
|
||||
|
||||
public onError(event: Event): void {
|
||||
CommonTips.showMsg('网络连接失败,正在重试链接游戏服务器')
|
||||
this.t_id = setInterval(() => {
|
||||
WsManager.instance.init()
|
||||
}, 8000)
|
||||
}
|
||||
|
||||
public clear() {
|
||||
if (this.t_id) {
|
||||
clearInterval(this.t_id)
|
||||
this.t_id = null
|
||||
}
|
||||
}
|
||||
}
|
||||
import { _decorator } from 'cc'
|
||||
import CommonTips from '../../engine/uicomponent/CommonTips'
|
||||
import FishUI from '../../../fish/script/FishUI'
|
||||
import config from '../config/Config'
|
||||
|
||||
export default class WsManager {
|
||||
private static _instance: WsManager = null
|
||||
uid: string
|
||||
|
||||
message: any
|
||||
|
||||
t_id: any = null
|
||||
|
||||
public static get instance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new WsManager()
|
||||
}
|
||||
return this._instance
|
||||
}
|
||||
|
||||
private _socket: WebSocket | null = null
|
||||
|
||||
protected m_mapCallbackFun: Map<number, Function>
|
||||
|
||||
constructor() {
|
||||
this.m_mapCallbackFun = new Map<number, Function>()
|
||||
}
|
||||
|
||||
public on(msgId: number, cb: Function, target: any) {
|
||||
let callback = cb.bind(target)
|
||||
let fnCallback: Function = this.m_mapCallbackFun.get(msgId)
|
||||
if (fnCallback) {
|
||||
console.error('重复注册消息处理函数! msgId:' + msgId)
|
||||
} else {
|
||||
this.m_mapCallbackFun.set(msgId, callback)
|
||||
}
|
||||
}
|
||||
|
||||
public off(msgId: number) {
|
||||
if (this.m_mapCallbackFun.has(msgId)) {
|
||||
this.m_mapCallbackFun.delete(msgId)
|
||||
}
|
||||
}
|
||||
|
||||
public get(msgId: number) {
|
||||
return this.m_mapCallbackFun.get(msgId)
|
||||
}
|
||||
|
||||
public offAll() {
|
||||
this.m_mapCallbackFun.clear()
|
||||
}
|
||||
|
||||
// 获取url参数
|
||||
public getQueryString(name: string) {
|
||||
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
|
||||
var r = window.location.search.substr(1).match(reg)
|
||||
if (r != null) {
|
||||
return unescape(r[2])
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public init(): void {
|
||||
this.uid = this.getQueryString('uid')
|
||||
this._socket = new WebSocket(`wss://${config.wsUrl()}/fish/home?uid=${this.uid}`)
|
||||
|
||||
// 添加事件监听器
|
||||
this._socket.onopen = this.onOpen.bind(this)
|
||||
this._socket.onmessage = this.onMessage.bind(this)
|
||||
this._socket.onclose = this.onClose.bind(this)
|
||||
this._socket.onerror = this.onError.bind(this)
|
||||
}
|
||||
|
||||
public onOpen(): void {
|
||||
console.log('WebSocket connection opened.')
|
||||
setInterval(() => {
|
||||
this._socket.send(JSON.stringify('ping'))
|
||||
}, 20000)
|
||||
this.clear()
|
||||
}
|
||||
|
||||
public async onSend(data: any): Promise<void> {
|
||||
if (this._socket && this._socket.readyState === WebSocket.OPEN) {
|
||||
this._socket.send(JSON.stringify(data))
|
||||
} else {
|
||||
console.error('消息发送失败!!!')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理接收到的消息
|
||||
* @param event WebSocket message event
|
||||
*/
|
||||
public onMessage(event: MessageEvent): void {
|
||||
this.message = JSON.parse(event.data)
|
||||
|
||||
if (this.message.code === 200 || this.message.code === 5) {
|
||||
FishUI.instance.refreshScore(this.message)
|
||||
}
|
||||
|
||||
let fnCallback: Function = this.m_mapCallbackFun.get(this.message.code)
|
||||
|
||||
if (fnCallback) {
|
||||
fnCallback(this.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭WebSocket连接
|
||||
*/
|
||||
public onClose(): void {
|
||||
console.log('链接已关闭')
|
||||
CommonTips.showMsg('游戏服务器中断关闭,正在重试')
|
||||
// this.init()
|
||||
if (this._socket) {
|
||||
this._socket.close()
|
||||
this._socket = null
|
||||
}
|
||||
this.t_id = setInterval(() => {
|
||||
WsManager.instance.init()
|
||||
}, 8000)
|
||||
}
|
||||
|
||||
public onError(event: Event): void {
|
||||
CommonTips.showMsg('网络连接失败,正在重试链接游戏服务器')
|
||||
this.t_id = setInterval(() => {
|
||||
WsManager.instance.init()
|
||||
}, 8000)
|
||||
}
|
||||
|
||||
public clear() {
|
||||
if (this.t_id) {
|
||||
clearInterval(this.t_id)
|
||||
this.t_id = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "44f1bff8-2972-4ae5-8f53-e0daaa97b92e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "44f1bff8-2972-4ae5-8f53-e0daaa97b92e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a52a8a98-fc73-4bb3-9081-157a181af0a9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a52a8a98-fc73-4bb3-9081-157a181af0a9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import { Component, Node, Prefab, _decorator, instantiate } 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
|
||||
public static instance: Node
|
||||
@property({ type: Prefab })
|
||||
private scorePrefab: Prefab | null = null
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/game/prefab/ResourcePrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
ResourcePrefab.prefab = loadedResource
|
||||
ResourcePrefab.instance = instantiate(loadedResource)
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
ResourcePrefab.instance = null
|
||||
ResourcePrefab.prefab = null
|
||||
}
|
||||
|
||||
public static getScorePrefab() {
|
||||
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
|
||||
}
|
||||
}
|
||||
import { Component, Node, Prefab, _decorator, instantiate } 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
|
||||
public static instance: Node
|
||||
@property({ type: Prefab })
|
||||
private scorePrefab: Prefab | null = null
|
||||
|
||||
public static preLoad(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
PrefabLoader.loadPrefab(
|
||||
`${GameConfig.GameName}/game/prefab/ResourcePrefab`,
|
||||
(loadedResource: Prefab) => {
|
||||
ResourcePrefab.prefab = loadedResource
|
||||
ResourcePrefab.instance = instantiate(loadedResource)
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
public static clear() {
|
||||
ResourcePrefab.instance = null
|
||||
ResourcePrefab.prefab = null
|
||||
}
|
||||
|
||||
public static getScorePrefab() {
|
||||
return ResourcePrefab.instance.getComponent(ResourcePrefab).scorePrefab
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e0c999fe-5635-4caa-8c3b-d16793848320",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e0c999fe-5635-4caa-8c3b-d16793848320",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { Component, Label, Tween, Vec2, Vec3, _decorator, tween } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ScorePrefab')
|
||||
export default class ScorePrefab extends Component {
|
||||
@property({ type: Label })
|
||||
private txtScore: Label | null = null
|
||||
|
||||
public init(score: number) {
|
||||
if (score <= 0) this.txtScore.string = 'Miss'
|
||||
else this.txtScore.string = `${score}`
|
||||
}
|
||||
|
||||
public playMoveEffect(p: Vec2, callback: Function = null) {
|
||||
tween(this.node)
|
||||
.to(0.5, { scale: new Vec3(3, 3, 3), position: new Vec3(p.x, p.y, 0) })
|
||||
.call(() => {
|
||||
if (callback) callback()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
}
|
||||
import { Component, Label, Tween, Vec2, Vec3, _decorator, tween } from 'cc'
|
||||
|
||||
const { ccclass, property } = _decorator
|
||||
|
||||
@ccclass('ScorePrefab')
|
||||
export default class ScorePrefab extends Component {
|
||||
@property({ type: Label })
|
||||
private txtScore: Label | null = null
|
||||
|
||||
public init(score: number) {
|
||||
if (score <= 0) this.txtScore.string = 'Miss'
|
||||
else this.txtScore.string = `${score}`
|
||||
}
|
||||
|
||||
public playMoveEffect(p: Vec2, callback: Function = null) {
|
||||
tween(this.node)
|
||||
.to(0.5, { scale: new Vec3(3, 3, 3), position: new Vec3(p.x, p.y, 0) })
|
||||
.call(() => {
|
||||
if (callback) callback()
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
Tween.stopAllByTarget(this.node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "465f63cc-b6fe-4ea9-9a10-79254fbe67cc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "465f63cc-b6fe-4ea9-9a10-79254fbe67cc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user