feat: 添加页面管理系统和首页/关卡页面
- 实现 ViewManager 单例页面管理器,支持页面注册、打开、关闭、缓存 - 实现 BaseView 页面基类,提供统一的页面生命周期 - 添加 PageHome 首页,包含开始游戏按钮跳转功能 - 添加 PageLevel 关卡页面,继承 BaseView - 更新 PageLoading 支持进度条显示和页面预加载 - 添加相关图片资源和预制体 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,10 +32,13 @@
|
||||
},
|
||||
{
|
||||
"__id__": 26
|
||||
},
|
||||
{
|
||||
"__id__": 28
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 28
|
||||
"__id__": 30
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -567,12 +570,51 @@
|
||||
"__prefab": {
|
||||
"__id__": 27
|
||||
},
|
||||
"progressBar": {
|
||||
"__id__": 21
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "035jtIcBFAXpr+rMnkwU6G"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 29
|
||||
},
|
||||
"_alignFlags": 45,
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 1080,
|
||||
"_originalHeight": 2160,
|
||||
"_alignMode": 2,
|
||||
"_lockFlags": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "08Ke4fRRVPz6x9lHDiuWL/"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
|
||||
@@ -1,14 +1,62 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import { _decorator, Component, ProgressBar } from 'cc';
|
||||
import { ViewManager } from './scripts/core/ViewManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* 页面加载组件
|
||||
* 负责预加载资源并显示加载进度
|
||||
*/
|
||||
@ccclass('PageLoading')
|
||||
export class PageLoading extends Component {
|
||||
start() {
|
||||
@property(ProgressBar)
|
||||
progressBar: ProgressBar | null = null;
|
||||
|
||||
start() {
|
||||
this._startPreload();
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
/**
|
||||
* 开始预加载
|
||||
*/
|
||||
private _startPreload(): void {
|
||||
// 初始化进度条
|
||||
if (this.progressBar) {
|
||||
this.progressBar.progress = 0;
|
||||
}
|
||||
|
||||
// 预加载 PageHome
|
||||
ViewManager.instance.preload('PageHome',
|
||||
(progress) => {
|
||||
this._updateProgress(progress);
|
||||
},
|
||||
() => {
|
||||
this._onPreloadComplete();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新进度条
|
||||
*/
|
||||
private _updateProgress(progress: number): void {
|
||||
if (this.progressBar) {
|
||||
this.progressBar.progress = progress;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载完成回调
|
||||
*/
|
||||
private _onPreloadComplete(): void {
|
||||
// 确保进度条显示完成
|
||||
this._updateProgress(1);
|
||||
|
||||
// 打开 PageHome
|
||||
ViewManager.instance.open('PageHome', {
|
||||
onComplete: () => {
|
||||
// PageHome 打开成功后,销毁自身
|
||||
this.node.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"__type__": "cc.SceneAsset",
|
||||
"_name": "main",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_native": "",
|
||||
"scene": {
|
||||
"__id__": 1
|
||||
@@ -10,8 +11,9 @@
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Scene",
|
||||
"_name": "scene-2d",
|
||||
"_name": "main",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": null,
|
||||
"_children": [
|
||||
{
|
||||
@@ -20,42 +22,13 @@
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [],
|
||||
"_prefab": null,
|
||||
"autoReleaseAssets": false,
|
||||
"_globals": {
|
||||
"__id__": 8
|
||||
"_prefab": {
|
||||
"__id__": 17
|
||||
},
|
||||
"_id": "d60530e8-06be-4ac4-8613-9cc604c77f32"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Canvas",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 3
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 5
|
||||
},
|
||||
{
|
||||
"__id__": 6
|
||||
},
|
||||
{
|
||||
"__id__": 7
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 480,
|
||||
"y": 320.00000000000006,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
@@ -71,6 +44,72 @@
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"autoReleaseAssets": false,
|
||||
"_globals": {
|
||||
"__id__": 18
|
||||
},
|
||||
"_id": "d60530e8-06be-4ac4-8613-9cc604c77f32"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Canvas",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 3
|
||||
},
|
||||
{
|
||||
"__id__": 5
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 13
|
||||
},
|
||||
{
|
||||
"__id__": 14
|
||||
},
|
||||
{
|
||||
"__id__": 15
|
||||
},
|
||||
{
|
||||
"__id__": 16
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 540,
|
||||
"y": 1080,
|
||||
"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",
|
||||
@@ -84,6 +123,7 @@
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Camera",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
@@ -99,7 +139,7 @@
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
"z": 1000
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
@@ -114,6 +154,7 @@
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
@@ -127,6 +168,7 @@
|
||||
"__type__": "cc.Camera",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 3
|
||||
},
|
||||
@@ -136,7 +178,7 @@
|
||||
"_priority": 0,
|
||||
"_fov": 45,
|
||||
"_fovAxis": 0,
|
||||
"_orthoHeight": 10,
|
||||
"_orthoHeight": 1080,
|
||||
"_near": 0,
|
||||
"_far": 2000,
|
||||
"_color": {
|
||||
@@ -162,12 +204,128 @@
|
||||
"_screenScale": 1,
|
||||
"_visibility": 1108344832,
|
||||
"_targetTexture": null,
|
||||
"_postProcess": null,
|
||||
"_usePostProcess": false,
|
||||
"_cameraType": -1,
|
||||
"_trackingType": 0,
|
||||
"_id": "63WIch3o5BEYRlXzTT0oWc"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_prefab": {
|
||||
"__id__": 6
|
||||
},
|
||||
"__editorExtras__": {}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 5
|
||||
},
|
||||
"asset": {
|
||||
"__uuid__": "79949d26-c169-4e68-ad10-a1242a9679a8",
|
||||
"__expectedType__": "cc.Prefab"
|
||||
},
|
||||
"fileId": "c46/YsCPVOJYA4mWEpNYRx",
|
||||
"instance": {
|
||||
"__id__": 7
|
||||
},
|
||||
"targetOverrides": null,
|
||||
"nestedPrefabInstanceRoots": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInstance",
|
||||
"fileId": "895CV8V5xCQYBK4UFRhlwD",
|
||||
"prefabRootNode": null,
|
||||
"mountedChildren": [],
|
||||
"mountedComponents": [],
|
||||
"propertyOverrides": [
|
||||
{
|
||||
"__id__": 8
|
||||
},
|
||||
{
|
||||
"__id__": 10
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
},
|
||||
{
|
||||
"__id__": 12
|
||||
}
|
||||
],
|
||||
"removedComponents": []
|
||||
},
|
||||
{
|
||||
"__type__": "CCPropertyOverrideInfo",
|
||||
"targetInfo": {
|
||||
"__id__": 9
|
||||
},
|
||||
"propertyPath": [
|
||||
"_name"
|
||||
],
|
||||
"value": "PageLoading"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.TargetInfo",
|
||||
"localID": [
|
||||
"c46/YsCPVOJYA4mWEpNYRx"
|
||||
]
|
||||
},
|
||||
{
|
||||
"__type__": "CCPropertyOverrideInfo",
|
||||
"targetInfo": {
|
||||
"__id__": 9
|
||||
},
|
||||
"propertyPath": [
|
||||
"_lpos"
|
||||
],
|
||||
"value": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "CCPropertyOverrideInfo",
|
||||
"targetInfo": {
|
||||
"__id__": 9
|
||||
},
|
||||
"propertyPath": [
|
||||
"_lrot"
|
||||
],
|
||||
"value": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "CCPropertyOverrideInfo",
|
||||
"targetInfo": {
|
||||
"__id__": 9
|
||||
},
|
||||
"propertyPath": [
|
||||
"_euler"
|
||||
],
|
||||
"value": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
@@ -175,8 +333,8 @@
|
||||
"__prefab": null,
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 960,
|
||||
"height": 640
|
||||
"width": 1080,
|
||||
"height": 2160
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -189,6 +347,7 @@
|
||||
"__type__": "cc.Canvas",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
@@ -204,6 +363,7 @@
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
@@ -229,26 +389,59 @@
|
||||
"_lockFlags": 0,
|
||||
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
|
||||
},
|
||||
{
|
||||
"__type__": "66d6c15rzdAT4lpaFk0+5gx",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": null,
|
||||
"_id": "c2b3nbzv9JuZmP2jxQyN72"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": null,
|
||||
"asset": null,
|
||||
"fileId": "d60530e8-06be-4ac4-8613-9cc604c77f32",
|
||||
"instance": null,
|
||||
"targetOverrides": null,
|
||||
"nestedPrefabInstanceRoots": [
|
||||
{
|
||||
"__id__": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"__type__": "cc.SceneGlobals",
|
||||
"ambient": {
|
||||
"__id__": 9
|
||||
"__id__": 19
|
||||
},
|
||||
"shadows": {
|
||||
"__id__": 10
|
||||
"__id__": 20
|
||||
},
|
||||
"_skybox": {
|
||||
"__id__": 11
|
||||
"__id__": 21
|
||||
},
|
||||
"fog": {
|
||||
"__id__": 12
|
||||
"__id__": 22
|
||||
},
|
||||
"octree": {
|
||||
"__id__": 13
|
||||
"__id__": 23
|
||||
},
|
||||
"skin": {
|
||||
"__id__": 14
|
||||
}
|
||||
"__id__": 24
|
||||
},
|
||||
"lightProbeInfo": {
|
||||
"__id__": 25
|
||||
},
|
||||
"postSettings": {
|
||||
"__id__": 26
|
||||
},
|
||||
"bakedWithStationaryMainLight": false,
|
||||
"bakedWithHighpLightmap": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.AmbientInfo",
|
||||
@@ -309,6 +502,7 @@
|
||||
"z": 0
|
||||
},
|
||||
"_distance": 0,
|
||||
"_planeBias": 1,
|
||||
"_shadowColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 76,
|
||||
@@ -332,7 +526,11 @@
|
||||
"_diffuseMapHDR": null,
|
||||
"_diffuseMapLDR": null,
|
||||
"_enabled": false,
|
||||
"_useHDR": true
|
||||
"_useHDR": true,
|
||||
"_editableMaterial": null,
|
||||
"_reflectionHDR": null,
|
||||
"_reflectionLDR": null,
|
||||
"_rotationAngle": 0
|
||||
},
|
||||
{
|
||||
"__type__": "cc.FogInfo",
|
||||
@@ -373,6 +571,23 @@
|
||||
{
|
||||
"__type__": "cc.SkinInfo",
|
||||
"_enabled": false,
|
||||
"_scale": 5
|
||||
"_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
|
||||
}
|
||||
]
|
||||
@@ -1,14 +1,40 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
import { _decorator, Component } from 'cc';
|
||||
import { ViewManager } from './scripts/core/ViewManager';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/**
|
||||
* 主入口脚本
|
||||
* 负责初始化 ViewManager 并注册页面
|
||||
*/
|
||||
@ccclass('main')
|
||||
export class main extends Component {
|
||||
start() {
|
||||
|
||||
/**
|
||||
* onLoad 比 start 更早执行
|
||||
* 确保 ViewManager 在 PageLoading.start() 之前初始化
|
||||
*/
|
||||
onLoad() {
|
||||
this._initViewManager();
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
/**
|
||||
* 初始化页面管理器
|
||||
*/
|
||||
private _initViewManager(): void {
|
||||
// 初始化 ViewManager,绑定 Canvas 作为页面容器
|
||||
ViewManager.instance.init(this.node);
|
||||
|
||||
// 注册页面配置
|
||||
ViewManager.instance.register('PageHome', {
|
||||
prefabPath: 'prefabs/PageHome',
|
||||
cache: true,
|
||||
zIndex: 0
|
||||
});
|
||||
|
||||
// 注册关卡页面
|
||||
ViewManager.instance.register('PageLevel', {
|
||||
prefabPath: 'prefabs/PageLevel',
|
||||
cache: true,
|
||||
zIndex: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
assets/resources/images/IconSetting.png
Normal file
BIN
assets/resources/images/IconSetting.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
134
assets/resources/images/IconSetting.png.meta
Normal file
134
assets/resources/images/IconSetting.png.meta
Normal file
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "9c27734d-854f-476b-961d-d1b92c75f8c0",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "9c27734d-854f-476b-961d-d1b92c75f8c0@6c48a",
|
||||
"displayName": "IconSetting",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "9c27734d-854f-476b-961d-d1b92c75f8c0",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "9c27734d-854f-476b-961d-d1b92c75f8c0@f9941",
|
||||
"displayName": "IconSetting",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 108,
|
||||
"height": 108,
|
||||
"rawWidth": 108,
|
||||
"rawHeight": 108,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-54,
|
||||
-54,
|
||||
0,
|
||||
54,
|
||||
-54,
|
||||
0,
|
||||
-54,
|
||||
54,
|
||||
0,
|
||||
54,
|
||||
54,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
108,
|
||||
108,
|
||||
108,
|
||||
0,
|
||||
0,
|
||||
108,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-54,
|
||||
-54,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
54,
|
||||
54,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "9c27734d-854f-476b-961d-d1b92c75f8c0@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "auto"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"hasAlpha": true,
|
||||
"redirect": "9c27734d-854f-476b-961d-d1b92c75f8c0@6c48a"
|
||||
}
|
||||
}
|
||||
9
assets/resources/images/pageHome.meta
Normal file
9
assets/resources/images/pageHome.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "aa456c3f-1dcf-4937-a285-c5a9562d0ea1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
assets/resources/images/pageHome/startGame.png
Normal file
BIN
assets/resources/images/pageHome/startGame.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
134
assets/resources/images/pageHome/startGame.png.meta
Normal file
134
assets/resources/images/pageHome/startGame.png.meta
Normal file
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "010e6809-3636-4c23-8403-1424c771f0f8",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "010e6809-3636-4c23-8403-1424c771f0f8@6c48a",
|
||||
"displayName": "startGame",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "010e6809-3636-4c23-8403-1424c771f0f8",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "010e6809-3636-4c23-8403-1424c771f0f8@f9941",
|
||||
"displayName": "startGame",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 216,
|
||||
"height": 107,
|
||||
"rawWidth": 216,
|
||||
"rawHeight": 107,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-108,
|
||||
-53.5,
|
||||
0,
|
||||
108,
|
||||
-53.5,
|
||||
0,
|
||||
-108,
|
||||
53.5,
|
||||
0,
|
||||
108,
|
||||
53.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
107,
|
||||
216,
|
||||
107,
|
||||
0,
|
||||
0,
|
||||
216,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-108,
|
||||
-53.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
108,
|
||||
53.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "010e6809-3636-4c23-8403-1424c771f0f8@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "auto"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"hasAlpha": true,
|
||||
"redirect": "010e6809-3636-4c23-8403-1424c771f0f8@6c48a"
|
||||
}
|
||||
}
|
||||
BIN
assets/resources/images/pageHome/test.png
Normal file
BIN
assets/resources/images/pageHome/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 197 KiB |
134
assets/resources/images/pageHome/test.png.meta
Normal file
134
assets/resources/images/pageHome/test.png.meta
Normal file
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "fa1861ef-84d3-4347-9bf0-7627f54b05de",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "fa1861ef-84d3-4347-9bf0-7627f54b05de@6c48a",
|
||||
"displayName": "test",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "fa1861ef-84d3-4347-9bf0-7627f54b05de",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "fa1861ef-84d3-4347-9bf0-7627f54b05de@f9941",
|
||||
"displayName": "test",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 352,
|
||||
"height": 776,
|
||||
"rawWidth": 352,
|
||||
"rawHeight": 776,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-176,
|
||||
-388,
|
||||
0,
|
||||
176,
|
||||
-388,
|
||||
0,
|
||||
-176,
|
||||
388,
|
||||
0,
|
||||
176,
|
||||
388,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
776,
|
||||
352,
|
||||
776,
|
||||
0,
|
||||
0,
|
||||
352,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-176,
|
||||
-388,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
176,
|
||||
388,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "fa1861ef-84d3-4347-9bf0-7627f54b05de@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "auto"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"hasAlpha": true,
|
||||
"redirect": "fa1861ef-84d3-4347-9bf0-7627f54b05de@6c48a"
|
||||
}
|
||||
}
|
||||
9
assets/resources/images/pageLevel.meta
Normal file
9
assets/resources/images/pageLevel.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "6e13548b-e5a3-4b8d-b6c0-2a5f394f1487",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
BIN
assets/resources/images/pageLevel/AdButton.png
Normal file
BIN
assets/resources/images/pageLevel/AdButton.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
134
assets/resources/images/pageLevel/AdButton.png.meta
Normal file
134
assets/resources/images/pageLevel/AdButton.png.meta
Normal file
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "d264bb8e-0d8c-48a5-a720-31c10e358a7d",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "d264bb8e-0d8c-48a5-a720-31c10e358a7d@6c48a",
|
||||
"displayName": "AdButton",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "d264bb8e-0d8c-48a5-a720-31c10e358a7d",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "d264bb8e-0d8c-48a5-a720-31c10e358a7d@f9941",
|
||||
"displayName": "AdButton",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 417,
|
||||
"height": 142,
|
||||
"rawWidth": 417,
|
||||
"rawHeight": 142,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-208.5,
|
||||
-71,
|
||||
0,
|
||||
208.5,
|
||||
-71,
|
||||
0,
|
||||
-208.5,
|
||||
71,
|
||||
0,
|
||||
208.5,
|
||||
71,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
142,
|
||||
417,
|
||||
142,
|
||||
0,
|
||||
0,
|
||||
417,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-208.5,
|
||||
-71,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
208.5,
|
||||
71,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "d264bb8e-0d8c-48a5-a720-31c10e358a7d@6c48a",
|
||||
"atlasUuid": "",
|
||||
"trimType": "auto"
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"hasAlpha": true,
|
||||
"redirect": "d264bb8e-0d8c-48a5-a720-31c10e358a7d@6c48a"
|
||||
}
|
||||
}
|
||||
9
assets/resources/prefabs.meta
Normal file
9
assets/resources/prefabs.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "8c0aeae3-2147-4c02-a1d2-2694fbe4aacf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
560
assets/resources/prefabs/PageHome.prefab
Normal file
560
assets/resources/prefabs/PageHome.prefab
Normal file
@@ -0,0 +1,560 @@
|
||||
[
|
||||
{
|
||||
"__type__": "cc.Prefab",
|
||||
"_name": "PageHome",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_native": "",
|
||||
"data": {
|
||||
"__id__": 1
|
||||
},
|
||||
"optimizationPolicy": 0,
|
||||
"persistent": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "PageHome",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": null,
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 2
|
||||
},
|
||||
{
|
||||
"__id__": 10
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 20
|
||||
},
|
||||
{
|
||||
"__id__": 22
|
||||
},
|
||||
{
|
||||
"__id__": 24
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 26
|
||||
},
|
||||
"_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
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "Bg",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 3
|
||||
},
|
||||
{
|
||||
"__id__": 5
|
||||
},
|
||||
{
|
||||
"__id__": 7
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 9
|
||||
},
|
||||
"_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
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 4
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 1080,
|
||||
"height": 2160
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "516nXwOy1HyILEPLAixt3+"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "d532045e-55f8-47c2-9493-b918e18364b0@f9941",
|
||||
"__expectedType__": "cc.SpriteFrame"
|
||||
},
|
||||
"_type": 0,
|
||||
"_fillType": 0,
|
||||
"_sizeMode": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_useGrayscale": false,
|
||||
"_atlas": null,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "caSJymhl1EjYDJB5ONQknn"
|
||||
},
|
||||
{
|
||||
"__type__": "d33b0ZrKQJEaKZYN2Peg+C/",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 8
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "5fvoDQhtZHSaQ4OjsBm2R+"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "34DqITevxDppujuUM+M3Ep",
|
||||
"instance": null,
|
||||
"targetOverrides": null,
|
||||
"nestedPrefabInstanceRoots": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "startGame",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 11
|
||||
},
|
||||
{
|
||||
"__id__": 13
|
||||
},
|
||||
{
|
||||
"__id__": 15
|
||||
},
|
||||
{
|
||||
"__id__": 17
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 19
|
||||
},
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": -800.532,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_lscale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1.583,
|
||||
"y": 1.583,
|
||||
"z": 1.583
|
||||
},
|
||||
"_mobility": 0,
|
||||
"_layer": 1073741824,
|
||||
"_euler": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 10
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 12
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 216,
|
||||
"height": 107
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "35asQ5bFtJOr9Onmy9xZov"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 10
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 14
|
||||
},
|
||||
"_customMaterial": null,
|
||||
"_srcBlendFactor": 2,
|
||||
"_dstBlendFactor": 4,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "010e6809-3636-4c23-8403-1424c771f0f8@f9941",
|
||||
"__expectedType__": "cc.SpriteFrame"
|
||||
},
|
||||
"_type": 0,
|
||||
"_fillType": 0,
|
||||
"_sizeMode": 1,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_useGrayscale": false,
|
||||
"_atlas": null,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "bbY0DIwZZE564mJcuIqyL2"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 10
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 16
|
||||
},
|
||||
"_alignFlags": 4,
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 194.77749999999992,
|
||||
"_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": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "daRisiwm1PEKRk63d1ICPO"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Button",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 10
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 18
|
||||
},
|
||||
"clickEvents": [],
|
||||
"_interactable": true,
|
||||
"_transition": 3,
|
||||
"_normalColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_hoverColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 211,
|
||||
"g": 211,
|
||||
"b": 211,
|
||||
"a": 255
|
||||
},
|
||||
"_pressedColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_disabledColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 124,
|
||||
"g": 124,
|
||||
"b": 124,
|
||||
"a": 255
|
||||
},
|
||||
"_normalSprite": null,
|
||||
"_hoverSprite": null,
|
||||
"_pressedSprite": null,
|
||||
"_disabledSprite": null,
|
||||
"_duration": 0.1,
|
||||
"_zoomScale": 1.2,
|
||||
"_target": null,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "29dh3pT0tGe4UqoNypQFFz"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "24z1aCS5BGUoUcLzSowxMh",
|
||||
"instance": null,
|
||||
"targetOverrides": null,
|
||||
"nestedPrefabInstanceRoots": null
|
||||
},
|
||||
{
|
||||
"__type__": "cc.UITransform",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 21
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 1080,
|
||||
"height": 2160
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "3fh/GQw5BFtaWjY2iRXZNj"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 23
|
||||
},
|
||||
"_alignFlags": 45,
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_bottom": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 1080,
|
||||
"_originalHeight": 2160,
|
||||
"_alignMode": 2,
|
||||
"_lockFlags": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "adez9PYBlO+o5jJaEuv12a"
|
||||
},
|
||||
{
|
||||
"__type__": "ada67C1KJZGrIrj62ihFzBE",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"__prefab": {
|
||||
"__id__": 25
|
||||
},
|
||||
"startGameBtn": {
|
||||
"__id__": 10
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.CompPrefabInfo",
|
||||
"fileId": "59sKvUi4BJY43S8yX+l4bC"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "c46/YsCPVOJYA4mWEpNYRx",
|
||||
"instance": null,
|
||||
"targetOverrides": null
|
||||
}
|
||||
]
|
||||
13
assets/resources/prefabs/PageHome.prefab.meta
Normal file
13
assets/resources/prefabs/PageHome.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "ae6e1ab4-19be-4cb3-90e4-9a1f3204a0fd",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "PageHome"
|
||||
}
|
||||
}
|
||||
64
assets/resources/prefabs/PageHome.ts
Normal file
64
assets/resources/prefabs/PageHome.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { _decorator, Node, Button } from 'cc';
|
||||
import { BaseView } from '../../scripts/core/BaseView';
|
||||
import { ViewManager } from '../../scripts/core/ViewManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* 首页组件
|
||||
* 继承 BaseView,实现页面生命周期
|
||||
*/
|
||||
@ccclass('PageHome')
|
||||
export class PageHome extends BaseView {
|
||||
@property({ type: Node, tooltip: '开始游戏按钮' })
|
||||
startGameBtn: Node | null = null;
|
||||
|
||||
/**
|
||||
* 页面首次加载时调用
|
||||
*/
|
||||
onViewLoad(): void {
|
||||
console.log('[PageHome] onViewLoad');
|
||||
this._initButtons();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化按钮事件
|
||||
*/
|
||||
private _initButtons(): void {
|
||||
if (this.startGameBtn) {
|
||||
this.startGameBtn.on(Button.EventType.CLICK, this._onStartGameClick, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始游戏按钮点击回调
|
||||
*/
|
||||
private _onStartGameClick(): void {
|
||||
console.log('[PageHome] 开始游戏按钮点击');
|
||||
ViewManager.instance.open('PageLevel');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面每次显示时调用
|
||||
*/
|
||||
onViewShow(): void {
|
||||
console.log('[PageHome] onViewShow');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面隐藏时调用
|
||||
*/
|
||||
onViewHide(): void {
|
||||
console.log('[PageHome] onViewHide');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面销毁时调用
|
||||
*/
|
||||
onViewDestroy(): void {
|
||||
console.log('[PageHome] onViewDestroy');
|
||||
// 移除按钮事件监听
|
||||
if (this.startGameBtn) {
|
||||
this.startGameBtn.off(Button.EventType.CLICK, this._onStartGameClick, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
assets/resources/prefabs/PageHome.ts.meta
Normal file
9
assets/resources/prefabs/PageHome.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ada670b5-2896-46ac-8ae3-eb68a1173044",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
3276
assets/resources/prefabs/PageLevel.prefab
Normal file
3276
assets/resources/prefabs/PageLevel.prefab
Normal file
File diff suppressed because it is too large
Load Diff
13
assets/resources/prefabs/PageLevel.prefab.meta
Normal file
13
assets/resources/prefabs/PageLevel.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.50",
|
||||
"importer": "prefab",
|
||||
"imported": true,
|
||||
"uuid": "8611dbdc-4749-49f1-97ca-aedae3d16320",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"syncNodeName": "PageLevel"
|
||||
}
|
||||
}
|
||||
39
assets/resources/prefabs/PageLevel.ts
Normal file
39
assets/resources/prefabs/PageLevel.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { _decorator } from 'cc';
|
||||
import { BaseView } from '../../scripts/core/BaseView';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/**
|
||||
* 关卡页面组件
|
||||
* 继承 BaseView,实现页面生命周期
|
||||
*/
|
||||
@ccclass('PageLevel')
|
||||
export class PageLevel extends BaseView {
|
||||
/**
|
||||
* 页面首次加载时调用
|
||||
*/
|
||||
onViewLoad(): void {
|
||||
console.log('[PageLevel] onViewLoad');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面每次显示时调用
|
||||
*/
|
||||
onViewShow(): void {
|
||||
console.log('[PageLevel] onViewShow');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面隐藏时调用
|
||||
*/
|
||||
onViewHide(): void {
|
||||
console.log('[PageLevel] onViewHide');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面销毁时调用
|
||||
*/
|
||||
onViewDestroy(): void {
|
||||
console.log('[PageLevel] onViewDestroy');
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/resources/prefabs/PageLevel.ts.meta
Normal file
9
assets/resources/prefabs/PageLevel.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "14b235e0-e649-477a-beb1-7890db8d0c9a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/scripts/core.meta
Normal file
9
assets/scripts/core.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
131
assets/scripts/core/BaseView.ts
Normal file
131
assets/scripts/core/BaseView.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
import { _decorator, Component } from 'cc';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/**
|
||||
* 页面配置接口
|
||||
*/
|
||||
export interface ViewConfig {
|
||||
prefabPath: string; // 相对于 resources 的路径
|
||||
cache?: boolean; // 是否缓存页面,默认 true
|
||||
zIndex?: number; // 层级,默认 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面打开选项
|
||||
*/
|
||||
export interface ViewOptions {
|
||||
params?: any; // 传递给页面的参数
|
||||
onComplete?: (view: BaseView) => void;
|
||||
onError?: (err: Error) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面基类
|
||||
* 所有页面组件应继承此类,实现生命周期方法
|
||||
*/
|
||||
@ccclass('BaseView')
|
||||
export class BaseView extends Component {
|
||||
/** 页面唯一标识 */
|
||||
viewId: string = '';
|
||||
|
||||
/** 页面配置 */
|
||||
config: ViewConfig | null = null;
|
||||
|
||||
/** 是否正在显示 */
|
||||
isShowing: boolean = false;
|
||||
|
||||
/** 传递给页面的参数 */
|
||||
protected _params: any = null;
|
||||
|
||||
/**
|
||||
* 设置页面参数
|
||||
*/
|
||||
setParams(params: any): void {
|
||||
this._params = params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取页面参数
|
||||
*/
|
||||
getParams(): any {
|
||||
return this._params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面加载时调用(首次创建时)
|
||||
* 子类应重写此方法
|
||||
*/
|
||||
onViewLoad(): void {
|
||||
// 子类实现
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面显示时调用(每次打开时)
|
||||
* 子类应重写此方法
|
||||
*/
|
||||
onViewShow(): void {
|
||||
// 子类实现
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面隐藏时调用(关闭或被其他页面覆盖时)
|
||||
* 子类应重写此方法
|
||||
*/
|
||||
onViewHide(): void {
|
||||
// 子类实现
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面销毁时调用
|
||||
* 子类应重写此方法
|
||||
*/
|
||||
onViewDestroy(): void {
|
||||
// 子类实现
|
||||
}
|
||||
|
||||
// ========== 内部方法,由 ViewManager 调用 ==========
|
||||
|
||||
/**
|
||||
* 内部方法:执行显示逻辑
|
||||
*/
|
||||
_doShow(): void {
|
||||
if (this.isShowing) return;
|
||||
this.isShowing = true;
|
||||
this.node.active = true;
|
||||
this.onViewShow();
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部方法:执行隐藏逻辑
|
||||
*/
|
||||
_doHide(): void {
|
||||
if (!this.isShowing) return;
|
||||
this.isShowing = false;
|
||||
this.onViewHide();
|
||||
this.node.active = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部方法:执行销毁逻辑
|
||||
*/
|
||||
_doDestroy(): void {
|
||||
// 标记已销毁,防止 onDestroy 中重复调用
|
||||
this._destroyed = true;
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
/** 是否已标记销毁 */
|
||||
private _destroyed: boolean = false;
|
||||
|
||||
// ========== Cocos 生命周期 ==========
|
||||
|
||||
protected onDestroy(): void {
|
||||
// 仅在未被 _doDestroy 调用时执行生命周期
|
||||
if (!this._destroyed) {
|
||||
if (this.isShowing) {
|
||||
this.onViewHide();
|
||||
}
|
||||
}
|
||||
this.onViewDestroy();
|
||||
}
|
||||
}
|
||||
9
assets/scripts/core/BaseView.ts.meta
Normal file
9
assets/scripts/core/BaseView.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
350
assets/scripts/core/ViewManager.ts
Normal file
350
assets/scripts/core/ViewManager.ts
Normal file
@@ -0,0 +1,350 @@
|
||||
import { _decorator, Node, resources, Prefab, instantiate, error } from 'cc';
|
||||
import { BaseView, ViewConfig, ViewOptions } from './BaseView';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/**
|
||||
* 已注册的页面配置映射
|
||||
*/
|
||||
interface RegisteredView {
|
||||
config: ViewConfig;
|
||||
prefab: Prefab | null; // 缓存的预制体
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面管理器
|
||||
* 单例模式,统一管理页面的注册、打开、关闭、返回等操作
|
||||
*/
|
||||
@ccclass('ViewManager')
|
||||
export class ViewManager {
|
||||
/** 单例实例 */
|
||||
private static _instance: ViewManager | null = null;
|
||||
|
||||
/** 获取单例 */
|
||||
public static get instance(): ViewManager {
|
||||
if (!ViewManager._instance) {
|
||||
ViewManager._instance = new ViewManager();
|
||||
}
|
||||
return ViewManager._instance;
|
||||
}
|
||||
|
||||
/** 页面容器节点 */
|
||||
private _container: Node | null = null;
|
||||
|
||||
/** 已注册的页面配置 */
|
||||
private _registeredViews: Map<string, RegisteredView> = new Map();
|
||||
|
||||
/** 页面栈 */
|
||||
private _viewStack: BaseView[] = [];
|
||||
|
||||
/** 页面实例缓存(用于缓存模式的页面) */
|
||||
private _viewCache: Map<string, BaseView> = new Map();
|
||||
|
||||
/**
|
||||
* 初始化管理器
|
||||
* @param container 页面容器节点(通常是 Canvas)
|
||||
*/
|
||||
init(container: Node): void {
|
||||
this._container = container;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前容器
|
||||
*/
|
||||
getContainer(): Node | null {
|
||||
return this._container;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册页面
|
||||
* @param viewId 页面唯一标识
|
||||
* @param config 页面配置
|
||||
*/
|
||||
register(viewId: string, config: ViewConfig): void {
|
||||
if (this._registeredViews.has(viewId)) {
|
||||
error(`ViewManager: 页面 "${viewId}" 已注册`);
|
||||
return;
|
||||
}
|
||||
|
||||
this._registeredViews.set(viewId, {
|
||||
config: {
|
||||
cache: true, // 默认缓存
|
||||
zIndex: 0, // 默认层级
|
||||
...config
|
||||
},
|
||||
prefab: null
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量注册页面
|
||||
* @param views 页面配置映射
|
||||
*/
|
||||
registerAll(views: Record<string, ViewConfig>): void {
|
||||
for (const [viewId, config] of Object.entries(views)) {
|
||||
this.register(viewId, config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面
|
||||
* @param viewId 页面唯一标识
|
||||
* @param options 打开选项
|
||||
*/
|
||||
open(viewId: string, options?: ViewOptions): void {
|
||||
if (!this._container) {
|
||||
const err = new Error('ViewManager: 未初始化,请先调用 init()');
|
||||
options?.onError?.(err);
|
||||
return;
|
||||
}
|
||||
|
||||
const registered = this._registeredViews.get(viewId);
|
||||
if (!registered) {
|
||||
const err = new Error(`ViewManager: 页面 "${viewId}" 未注册`);
|
||||
options?.onError?.(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否有缓存的实例
|
||||
const cachedView = this._viewCache.get(viewId);
|
||||
if (cachedView && cachedView.node.isValid) {
|
||||
this._showView(cachedView, options);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否有缓存的预制体
|
||||
if (registered.prefab) {
|
||||
this._instantiateView(viewId, registered.prefab, options);
|
||||
return;
|
||||
}
|
||||
|
||||
// 动态加载预制体
|
||||
resources.load(registered.config.prefabPath, Prefab, (err, prefab) => {
|
||||
if (err) {
|
||||
error(`ViewManager: 加载预制体失败 "${registered.config.prefabPath}"`, err);
|
||||
options?.onError?.(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// 缓存预制体
|
||||
registered.prefab = prefab;
|
||||
this._instantiateView(viewId, prefab!, options);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化视图
|
||||
*/
|
||||
private _instantiateView(viewId: string, prefab: Prefab, options?: ViewOptions): void {
|
||||
if (!this._container) return;
|
||||
|
||||
const registered = this._registeredViews.get(viewId);
|
||||
if (!registered) return;
|
||||
|
||||
const node = instantiate(prefab);
|
||||
const view = node.getComponent(BaseView);
|
||||
|
||||
if (!view) {
|
||||
error(`ViewManager: 预制体 "${registered.config.prefabPath}" 缺少 BaseView 组件`);
|
||||
node.destroy();
|
||||
options?.onError?.(new Error('缺少 BaseView 组件'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置视图属性
|
||||
view.viewId = viewId;
|
||||
view.config = registered.config;
|
||||
view.setParams(options?.params);
|
||||
|
||||
// 设置层级
|
||||
node.setSiblingIndex(registered.config.zIndex || 0);
|
||||
|
||||
// 添加到容器
|
||||
this._container.addChild(node);
|
||||
|
||||
// 调用加载回调
|
||||
view.onViewLoad();
|
||||
|
||||
// 缓存视图实例
|
||||
if (registered.config.cache) {
|
||||
this._viewCache.set(viewId, view);
|
||||
}
|
||||
|
||||
// 显示视图
|
||||
this._showView(view, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示视图
|
||||
*/
|
||||
private _showView(view: BaseView, options?: ViewOptions): void {
|
||||
// 隐藏当前页面
|
||||
const currentView = this.getCurrentView();
|
||||
if (currentView && currentView !== view) {
|
||||
currentView._doHide();
|
||||
}
|
||||
|
||||
// 设置参数
|
||||
if (options?.params !== undefined) {
|
||||
view.setParams(options?.params);
|
||||
}
|
||||
|
||||
// 入栈
|
||||
if (!this._viewStack.includes(view)) {
|
||||
this._viewStack.push(view);
|
||||
}
|
||||
|
||||
// 显示
|
||||
view._doShow();
|
||||
|
||||
// 回调
|
||||
options?.onComplete?.(view);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭当前页面
|
||||
* @param options 关闭选项
|
||||
*/
|
||||
close(options?: { destroy?: boolean }): void {
|
||||
const currentView = this._viewStack.pop();
|
||||
if (!currentView) return;
|
||||
|
||||
const shouldDestroy = options?.destroy ?? !currentView.config?.cache;
|
||||
this._hideAndDestroyView(currentView, shouldDestroy);
|
||||
|
||||
// 显示上一页
|
||||
const prevView = this.getCurrentView();
|
||||
if (prevView) {
|
||||
prevView._doShow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上一页(close 的别名)
|
||||
*/
|
||||
back(): void {
|
||||
this.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换当前页面
|
||||
* @param viewId 新页面标识
|
||||
* @param options 打开选项
|
||||
*/
|
||||
replace(viewId: string, options?: ViewOptions): void {
|
||||
const currentView = this.getCurrentView();
|
||||
if (currentView) {
|
||||
this._viewStack.pop();
|
||||
const shouldDestroy = !currentView.config?.cache;
|
||||
this._hideAndDestroyView(currentView, shouldDestroy);
|
||||
}
|
||||
|
||||
this.open(viewId, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏并销毁视图(内部方法)
|
||||
*/
|
||||
private _hideAndDestroyView(view: BaseView, shouldDestroy: boolean): void {
|
||||
view._doHide();
|
||||
if (shouldDestroy) {
|
||||
this._viewCache.delete(view.viewId);
|
||||
view._doDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面
|
||||
*/
|
||||
getCurrentView(): BaseView | null {
|
||||
return this._viewStack.length > 0
|
||||
? this._viewStack[this._viewStack.length - 1]
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取页面栈
|
||||
*/
|
||||
getViewStack(): BaseView[] {
|
||||
return [...this._viewStack];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有页面
|
||||
*/
|
||||
clearAll(): void {
|
||||
// 从栈顶开始销毁
|
||||
while (this._viewStack.length > 0) {
|
||||
const view = this._viewStack.pop()!;
|
||||
const shouldDestroy = !view.config?.cache;
|
||||
this._hideAndDestroyView(view, shouldDestroy);
|
||||
}
|
||||
|
||||
// 销毁缓存的页面
|
||||
for (const view of this._viewCache.values()) {
|
||||
if (view.node.isValid) {
|
||||
view._doDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
this._viewCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载页面预制体
|
||||
* @param viewId 页面标识
|
||||
* @param onProgress 进度回调
|
||||
* @param onComplete 完成回调
|
||||
*/
|
||||
preload(viewId: string, onProgress?: (progress: number) => void, onComplete?: () => void): void {
|
||||
const registered = this._registeredViews.get(viewId);
|
||||
if (!registered) {
|
||||
error(`ViewManager: 页面 "${viewId}" 未注册`);
|
||||
onComplete?.();
|
||||
return;
|
||||
}
|
||||
|
||||
// 已缓存
|
||||
if (registered.prefab) {
|
||||
onProgress?.(1);
|
||||
onComplete?.();
|
||||
return;
|
||||
}
|
||||
|
||||
resources.load(registered.config.prefabPath, Prefab, (err, prefab) => {
|
||||
if (err) {
|
||||
error(`ViewManager: 预加载失败 "${registered.config.prefabPath}"`, err);
|
||||
} else {
|
||||
registered.prefab = prefab;
|
||||
onProgress?.(1);
|
||||
}
|
||||
onComplete?.();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量预加载页面
|
||||
* @param viewIds 页面标识数组
|
||||
* @param onProgress 总进度回调 (0-1)
|
||||
* @param onComplete 完成回调
|
||||
*/
|
||||
preloadAll(viewIds: string[], onProgress?: (progress: number) => void, onComplete?: () => void): void {
|
||||
if (viewIds.length === 0) {
|
||||
onProgress?.(1);
|
||||
onComplete?.();
|
||||
return;
|
||||
}
|
||||
|
||||
let completed = 0;
|
||||
const total = viewIds.length;
|
||||
|
||||
for (const viewId of viewIds) {
|
||||
this.preload(viewId, () => {
|
||||
completed++;
|
||||
onProgress?.(completed / total);
|
||||
if (completed === total) {
|
||||
onComplete?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
9
assets/scripts/core/ViewManager.ts.meta
Normal file
9
assets/scripts/core/ViewManager.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c2d3e4f5-a6b7-7890-cdef-123456789012",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user