This commit is contained in:
2024-10-05 04:22:34 +08:00
parent 5993f231fd
commit 30911fcf5c
298 changed files with 28632 additions and 28632 deletions

View File

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

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}

View File

@@ -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() {}
}

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}

View File

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

View File

@@ -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": []
}
}