feat: 添加微信SDK和关卡页面,重构预制体结构

- 新增 WxSDK 微信SDK工具类
- 新增 PageLevel 关卡选择页面组件
- 将 prefabs 目录从 resources 移至根目录
- 更新 ViewManager 支持预制体属性引用
- 添加 BaseView 页面基类

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
richarjiang
2026-03-11 10:35:21 +08:00
parent 8986d8d8f2
commit 0bda6904fa
18 changed files with 1149 additions and 1646 deletions

View File

@@ -1,11 +1,11 @@
import { _decorator, Component } from 'cc';
import { _decorator, Component, Prefab } from 'cc';
const { ccclass } = _decorator;
/**
* 页面配置接口
*/
export interface ViewConfig {
prefabPath: string; // 相对于 resources 的路径
prefab: Prefab; // 预制体引用(主包资源)
cache?: boolean; // 是否缓存页面,默认 true
zIndex?: number; // 层级,默认 0
}

View File

@@ -1,4 +1,4 @@
import { _decorator, Node, resources, Prefab, instantiate, error } from 'cc';
import { _decorator, Node, Prefab, instantiate, error } from 'cc';
import { BaseView, ViewConfig, ViewOptions } from './BaseView';
const { ccclass } = _decorator;
@@ -7,7 +7,6 @@ const { ccclass } = _decorator;
*/
interface RegisteredView {
config: ViewConfig;
prefab: Prefab | null; // 缓存的预制体
}
/**
@@ -70,8 +69,7 @@ export class ViewManager {
cache: true, // 默认缓存
zIndex: 0, // 默认层级
...config
},
prefab: null
}
});
}
@@ -111,24 +109,8 @@ export class ViewManager {
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);
});
// 直接使用预制体引用实例化
this._instantiateView(viewId, registered.config.prefab, options);
}
/**
@@ -144,7 +126,7 @@ export class ViewManager {
const view = node.getComponent(BaseView);
if (!view) {
error(`ViewManager: 预制体 "${registered.config.prefabPath}" 缺少 BaseView 组件`);
error(`ViewManager: 预制体 "${viewId}" 缺少 BaseView 组件`);
node.destroy();
options?.onError?.(new Error('缺少 BaseView 组件'));
return;
@@ -290,7 +272,7 @@ export class ViewManager {
}
/**
* 预加载页面预制体
* 预加载页面预制体(主包资源已随游戏加载,此方法仅为兼容性保留)
* @param viewId 页面标识
* @param onProgress 进度回调
* @param onComplete 完成回调
@@ -303,22 +285,9 @@ export class ViewManager {
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?.();
});
// 主包资源已加载,直接回调
onProgress?.(1);
onComplete?.();
}
/**