feat: 新增资源分包与启动场景,支持音效播放
This commit is contained in:
11
assets/bundle1.meta
Normal file
11
assets/bundle1.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "7a995555-e54a-4884-a1d2-99f976cd83c9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"isBundle": true
|
||||
}
|
||||
}
|
||||
9
assets/bundle1/images.meta
Normal file
9
assets/bundle1/images.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a1cb63d6-303b-43d6-87c5-72e7193afbab",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 288 KiB After Width: | Height: | Size: 288 KiB |
9
assets/bundle1/music.meta
Normal file
9
assets/bundle1/music.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "23e28622-675d-4df7-85ca-7a99241e265a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
assets/bundle1/music/Attack.mp3
Normal file
BIN
assets/bundle1/music/Attack.mp3
Normal file
Binary file not shown.
14
assets/bundle1/music/Attack.mp3.meta
Normal file
14
assets/bundle1/music/Attack.mp3.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "audio-clip",
|
||||
"imported": true,
|
||||
"uuid": "5d1cb41c-cc52-4f72-abf1-04e6b5e26278",
|
||||
"files": [
|
||||
".json",
|
||||
".mp3"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"downloadMode": 0
|
||||
}
|
||||
}
|
||||
BIN
assets/bundle1/music/Bgm.mp3
Normal file
BIN
assets/bundle1/music/Bgm.mp3
Normal file
Binary file not shown.
14
assets/bundle1/music/Bgm.mp3.meta
Normal file
14
assets/bundle1/music/Bgm.mp3.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "audio-clip",
|
||||
"imported": true,
|
||||
"uuid": "87656531-d490-442b-9f0e-e51ae6468158",
|
||||
"files": [
|
||||
".json",
|
||||
".mp3"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"downloadMode": 0
|
||||
}
|
||||
}
|
||||
BIN
assets/bundle1/music/Failed.mp3
Normal file
BIN
assets/bundle1/music/Failed.mp3
Normal file
Binary file not shown.
14
assets/bundle1/music/Failed.mp3.meta
Normal file
14
assets/bundle1/music/Failed.mp3.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "audio-clip",
|
||||
"imported": true,
|
||||
"uuid": "863e3e99-2900-4c45-b170-a9a72611887b",
|
||||
"files": [
|
||||
".json",
|
||||
".mp3"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"downloadMode": 0
|
||||
}
|
||||
}
|
||||
BIN
assets/bundle1/music/Run.mp3
Normal file
BIN
assets/bundle1/music/Run.mp3
Normal file
Binary file not shown.
14
assets/bundle1/music/Run.mp3.meta
Normal file
14
assets/bundle1/music/Run.mp3.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "audio-clip",
|
||||
"imported": true,
|
||||
"uuid": "68342fce-3f17-4aa8-9598-fff07c731a54",
|
||||
"files": [
|
||||
".json",
|
||||
".mp3"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"downloadMode": 0
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
468
assets/scenes/start.scene
Normal file
468
assets/scenes/start.scene
Normal file
@@ -0,0 +1,468 @@
|
||||
[
|
||||
{
|
||||
"__type__": "cc.SceneAsset",
|
||||
"_name": "start",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_native": "",
|
||||
"scene": {
|
||||
"__id__": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Scene",
|
||||
"_name": "start",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": null,
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 2
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"autoReleaseAssets": false,
|
||||
"_globals": {
|
||||
"__id__": 9
|
||||
},
|
||||
"_id": "eccd00c2-333a-4c29-ae63-fd35cf9b87d1"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Canvas",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 3
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 5
|
||||
},
|
||||
{
|
||||
"__id__": 6
|
||||
},
|
||||
{
|
||||
"__id__": 7
|
||||
},
|
||||
{
|
||||
"__id__": 8
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 360,
|
||||
"y": 667,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 33554432,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_id": "beI88Z2HpFELqR4T5EMHpg"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Camera",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 4
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 1000
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_id": "ebFwiq8gBFaYpqYbdoDODe"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Camera",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 3
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_projection": 0,
|
||||
"_priority": 0,
|
||||
"_fov": 45,
|
||||
"_fovAxis": 0,
|
||||
"_orthoHeight": 667,
|
||||
"_near": 0,
|
||||
"_far": 2000,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"_depth": 1,
|
||||
"_stencil": 0,
|
||||
"_clearFlags": 7,
|
||||
"_rect": {
|
||||
"__type__": "cc.Rect",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"width": 1,
|
||||
"height": 1
|
||||
},
|
||||
"_aperture": 19,
|
||||
"_shutter": 7,
|
||||
"_iso": 0,
|
||||
"_screenScale": 1,
|
||||
"_visibility": 1108344832,
|
||||
"_targetTexture": null,
|
||||
"_postProcess": null,
|
||||
"_usePostProcess": false,
|
||||
"_cameraType": -1,
|
||||
"_trackingType": 0,
|
||||
"_id": "63WIch3o5BEYRlXzTT0oWc"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 720,
|
||||
"height": 1334
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_id": "d6rUX5yfhMlKoWX2bSbawx"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Canvas",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_cameraComponent": {
|
||||
"__id__": 4
|
||||
},
|
||||
"_alignCanvasWithScreen": true,
|
||||
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_alignFlags": 45,
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 5.684341886080802e-14,
|
||||
"_bottom": 5.684341886080802e-14,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 0,
|
||||
"_originalHeight": 0,
|
||||
"_alignMode": 2,
|
||||
"_lockFlags": 0,
|
||||
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
|
||||
},
|
||||
{
|
||||
"__type__": "e4e64bK2C9KxIsdCD5z8bBb",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"bundlesToLoad": [
|
||||
"bundle1"
|
||||
],
|
||||
"targetScene": "main",
|
||||
"_id": "d5tUALobRHR5p1X1I3XA07"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.SceneGlobals",
|
||||
"ambient": {
|
||||
"__id__": 10
|
||||
},
|
||||
"shadows": {
|
||||
"__id__": 11
|
||||
},
|
||||
"_skybox": {
|
||||
"__id__": 12
|
||||
},
|
||||
"fog": {
|
||||
"__id__": 13
|
||||
},
|
||||
"octree": {
|
||||
"__id__": 14
|
||||
},
|
||||
"skin": {
|
||||
"__id__": 15
|
||||
},
|
||||
"lightProbeInfo": {
|
||||
"__id__": 16
|
||||
},
|
||||
"postSettings": {
|
||||
"__id__": 17
|
||||
},
|
||||
"bakedWithStationaryMainLight": false,
|
||||
"bakedWithHighpLightmap": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.AmbientInfo",
|
||||
"_skyColorHDR": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 0.520833125
|
||||
},
|
||||
"_skyColor": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 0.520833125
|
||||
},
|
||||
"_skyIllumHDR": 20000,
|
||||
"_skyIllum": 20000,
|
||||
"_groundAlbedoHDR": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 0
|
||||
},
|
||||
"_groundAlbedo": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 0
|
||||
},
|
||||
"_skyColorLDR": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0.2,
|
||||
"y": 0.5,
|
||||
"z": 0.8,
|
||||
"w": 1
|
||||
},
|
||||
"_skyIllumLDR": 20000,
|
||||
"_groundAlbedoLDR": {
|
||||
"__type__": "cc.Vec4",
|
||||
"x": 0.2,
|
||||
"y": 0.2,
|
||||
"z": 0.2,
|
||||
"w": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.ShadowsInfo",
|
||||
"_enabled": false,
|
||||
"_type": 0,
|
||||
"_normal": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 1,
|
||||
"z": 0
|
||||
},
|
||||
"_distance": 0,
|
||||
"_planeBias": 1,
|
||||
"_shadowColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 76,
|
||||
"g": 76,
|
||||
"b": 76,
|
||||
"a": 255
|
||||
},
|
||||
"_maxReceived": 4,
|
||||
"_size": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 512,
|
||||
"y": 512
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.SkyboxInfo",
|
||||
"_envLightingType": 0,
|
||||
"_envmapHDR": null,
|
||||
"_envmap": null,
|
||||
"_envmapLDR": null,
|
||||
"_diffuseMapHDR": null,
|
||||
"_diffuseMapLDR": null,
|
||||
"_enabled": false,
|
||||
"_useHDR": true,
|
||||
"_editableMaterial": null,
|
||||
"_reflectionHDR": null,
|
||||
"_reflectionLDR": null,
|
||||
"_rotationAngle": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.FogInfo",
|
||||
"_type": 0,
|
||||
"_fogColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 200,
|
||||
"g": 200,
|
||||
"b": 200,
|
||||
"a": 255
|
||||
},
|
||||
"_enabled": false,
|
||||
"_fogDensity": 0.3,
|
||||
"_fogStart": 0.5,
|
||||
"_fogEnd": 300,
|
||||
"_fogAtten": 5,
|
||||
"_fogTop": 1.5,
|
||||
"_fogRange": 1.2,
|
||||
"_accurate": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.OctreeInfo",
|
||||
"_enabled": false,
|
||||
"_minPos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": -1024,
|
||||
"y": -1024,
|
||||
"z": -1024
|
||||
},
|
||||
"_maxPos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1024,
|
||||
"y": 1024,
|
||||
"z": 1024
|
||||
},
|
||||
"_depth": 8
|
||||
},
|
||||
{
|
||||
"__type__": "cc.SkinInfo",
|
||||
"_enabled": false,
|
||||
"_blurRadius": 0.01,
|
||||
"_sssIntensity": 3
|
||||
},
|
||||
{
|
||||
"__type__": "cc.LightProbeInfo",
|
||||
"_giScale": 1,
|
||||
"_giSamples": 1024,
|
||||
"_bounces": 2,
|
||||
"_reduceRinging": 0,
|
||||
"_showProbe": true,
|
||||
"_showWireframe": true,
|
||||
"_showConvex": false,
|
||||
"_data": null,
|
||||
"_lightProbeSphereVolume": 1
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PostSettingsInfo",
|
||||
"_toneMappingType": 0
|
||||
}
|
||||
]
|
||||
11
assets/scenes/start.scene.meta
Normal file
11
assets/scenes/start.scene.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "scene",
|
||||
"imported": true,
|
||||
"uuid": "eccd00c2-333a-4c29-ae63-fd35cf9b87d1",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { _decorator, Component, Node, Vec3, input, Input, EventTouch, Camera, view, tween, Animation, Collider2D, Contact2DType, Label, Color, Canvas, UITransform } from 'cc';
|
||||
import { _decorator, Component, Node, Vec3, input, Input, EventTouch, Camera, view, tween, Animation, Collider2D, Contact2DType, Label, Color, Canvas, UITransform, AudioSource } from 'cc';
|
||||
import { TiledMapPathfinder } from './TiledMapPathfinder';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -19,6 +19,9 @@ export class PlayerController extends Component {
|
||||
@property(TiledMapPathfinder)
|
||||
pathfinder: TiledMapPathfinder | null = null; // 寻路组件
|
||||
|
||||
@property(Node)
|
||||
attackAudio: Node | null = null; // 攻击音效节点
|
||||
|
||||
@property({ range: [1, 300] })
|
||||
moveSpeed: number = 300; // 移动速度(像素/秒)
|
||||
|
||||
@@ -400,6 +403,15 @@ export class PlayerController extends Component {
|
||||
const monsterHp = parseInt(monsterLabel.string) || 0;
|
||||
console.log('玩家生命值:', playerHp, '怪物生命值:', monsterHp);
|
||||
|
||||
// 播放攻击音效
|
||||
if (this.attackAudio) {
|
||||
const audioSource = this.attackAudio.getComponent(AudioSource);
|
||||
if (audioSource) {
|
||||
audioSource.play();
|
||||
console.log('播放攻击音效');
|
||||
}
|
||||
}
|
||||
|
||||
// 播放攻击动画
|
||||
const monsterAnimation = otherCollider.node.getComponent(Animation);
|
||||
if (monsterAnimation) {
|
||||
@@ -469,6 +481,15 @@ export class PlayerController extends Component {
|
||||
}
|
||||
|
||||
this.isAttacking = false;
|
||||
|
||||
// 停止攻击音效
|
||||
if (this.attackAudio) {
|
||||
const audioSource = this.attackAudio.getComponent(AudioSource);
|
||||
if (audioSource) {
|
||||
audioSource.stop();
|
||||
console.log('停止攻击音效');
|
||||
}
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
|
||||
|
||||
111
assets/scripts/Start.ts
Normal file
111
assets/scripts/Start.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { _decorator, Component, Node, assetManager, AssetManager, director, Scene } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('Start')
|
||||
export class Start extends Component {
|
||||
// 需要加载的 bundle 列表 - 可以根据实际情况修改
|
||||
@property({ type: [String], tooltip: '需要加载的 bundle 名称列表' })
|
||||
private bundlesToLoad: string[] = ['bundle1'];
|
||||
|
||||
// 目标场景名称
|
||||
@property({ type: String, tooltip: '加载完成后跳转的场景名称' })
|
||||
private targetScene: string = 'main';
|
||||
|
||||
// 已加载的 bundle 数量
|
||||
private loadedBundleCount: number = 0;
|
||||
|
||||
// 存储已加载的 bundle
|
||||
private loadedBundles: Map<string, AssetManager.Bundle> = new Map();
|
||||
|
||||
protected onLoad(): void {
|
||||
// 加载所有 bundle
|
||||
this.loadAllBundles();
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载所有 bundle
|
||||
*/
|
||||
private loadAllBundles(): void {
|
||||
if (this.bundlesToLoad.length === 0) {
|
||||
console.log('没有需要加载的 bundle,直接跳转到目标场景');
|
||||
this.loadTargetScene();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`开始加载 ${this.bundlesToLoad.length} 个 bundle:`, this.bundlesToLoad);
|
||||
|
||||
for (const bundleName of this.bundlesToLoad) {
|
||||
this.loadBundle(bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载单个 bundle
|
||||
*/
|
||||
private loadBundle(bundleName: string): void {
|
||||
assetManager.loadBundle(bundleName, (err: Error | null, bundle: AssetManager.Bundle | null) => {
|
||||
if (err) {
|
||||
console.error(`加载 ${bundleName} 分包失败:`, err);
|
||||
// 即使加载失败也继续,确保不会因为一个 bundle 失败而卡住
|
||||
this.onBundleLoadComplete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (bundle) {
|
||||
console.log(`${bundleName} 分包加载成功`);
|
||||
this.loadedBundles.set(bundleName, bundle);
|
||||
this.onBundleLoadComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* bundle 加载完成后的处理
|
||||
*/
|
||||
private onBundleLoadComplete(): void {
|
||||
this.loadedBundleCount++;
|
||||
console.log(`已加载 ${this.loadedBundleCount}/${this.bundlesToLoad.length} 个 bundle`);
|
||||
|
||||
// 检查是否所有 bundle 都已加载完成
|
||||
if (this.loadedBundleCount >= this.bundlesToLoad.length) {
|
||||
this.onAllBundlesLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有 bundle 加载完成后的回调
|
||||
*/
|
||||
private onAllBundlesLoaded(): void {
|
||||
console.log('所有 bundle 加载完成!');
|
||||
console.log('成功加载的 bundles:', Array.from(this.loadedBundles.keys()));
|
||||
|
||||
// 所有 bundle 加载完成后,跳转到目标场景
|
||||
this.loadTargetScene();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载目标场景
|
||||
*/
|
||||
private loadTargetScene(): void {
|
||||
console.log(`开始加载 ${this.targetScene} 场景...`);
|
||||
|
||||
director.loadScene(this.targetScene, (err: Error | null, scene: Scene | null) => {
|
||||
if (err) {
|
||||
console.error(`加载 ${this.targetScene} 场景失败:`, err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (scene) {
|
||||
console.log(`${this.targetScene} 场景加载成功!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
9
assets/scripts/Start.ts.meta
Normal file
9
assets/scripts/Start.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e4e646ca-d82f-4ac4-8b1d-083e73f1b05b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,3 +1,39 @@
|
||||
{
|
||||
"__version__": "1.3.9"
|
||||
"__version__": "1.3.9",
|
||||
"bundleConfig": {
|
||||
"custom": {
|
||||
"default": {
|
||||
"displayName": "i18n:builder.asset_bundle.defaultConfig",
|
||||
"configs": {
|
||||
"native": {
|
||||
"preferredOptions": {
|
||||
"isRemote": false,
|
||||
"compressionType": "merge_dep"
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"preferredOptions": {
|
||||
"isRemote": false,
|
||||
"compressionType": "merge_dep"
|
||||
},
|
||||
"fallbackOptions": {
|
||||
"compressionType": "merge_dep"
|
||||
}
|
||||
},
|
||||
"miniGame": {
|
||||
"fallbackOptions": {
|
||||
"isRemote": false,
|
||||
"compressionType": "merge_dep"
|
||||
},
|
||||
"configMode": "fallback",
|
||||
"overwriteSettings": {
|
||||
"wechatgame": {
|
||||
"compressionType": "subpackage"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user