1. 升级cc3.8.4

2. 添加加载zip资源演示
This commit is contained in:
dgflash
2024-10-15 08:10:46 +08:00
parent 4586764cea
commit 3a29bce67f
26 changed files with 20 additions and 459 deletions

View File

@@ -265,7 +265,7 @@
"_priority": 1073741824,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 360,
"_orthoHeight": 362.993762993763,
"_near": 1,
"_far": 2000,
"_color": {

View File

@@ -1,12 +0,0 @@
{
"ver": "1.0.1",
"importer": "ttf-font",
"imported": true,
"uuid": "859314dc-c952-48fc-84a7-bba774e1f873",
"files": [
".json",
"en.ttf"
],
"subMetas": {},
"userData": {}
}

View File

@@ -1,12 +0,0 @@
{
"ver": "1.0.1",
"importer": "ttf-font",
"imported": true,
"uuid": "d06fcc91-daf7-4f73-9c6f-84054f48cf5c",
"files": [
".json",
"zh.ttf"
],
"subMetas": {},
"userData": {}
}

View File

@@ -2,11 +2,8 @@
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "290b1e09-c538-41d7-8b27-c70a15a0d9b7",
"uuid": "3e109e69-ce72-4e85-9ae2-ed780ac41032",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
"userData": {}
}

View File

@@ -9,7 +9,6 @@ import { v3 } from "cc";
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { GameEvent } from "../../common/config/GameEvent";
import { netConfig } from "../../common/net/NetConfig";
import { Role } from "../../role/Role";
import { Account } from "../Account";
import { AccountModelComp } from "../model/AccountModelComp";
@@ -28,11 +27,6 @@ export class AccountNetDataSystem extends ecs.ComblockSystem implements ecs.IEnt
}
entityEnter(e: Account): void {
var params: any = {
playerId: netConfig.dbid,
sessionKey: netConfig.sessionKey,
}
let onComplete = {
target: this,
callback: (data: any) => {
@@ -46,8 +40,6 @@ export class AccountNetDataSystem extends ecs.ComblockSystem implements ecs.IEnt
oops.message.dispatchEvent(GameEvent.LoginSuccess);
}
}
// 请求登录游戏获取角色数据
// netChannel.game.req("LoginAction", "loadPlayer", params, onComplete);
// 离线测试代码开始
var data = {

View File

@@ -1,12 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "1811a053-d019-4c61-849b-6159eebb591f",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,40 +0,0 @@
export default class BundleConfig {
private static _instance: BundleConfig = null!;
static get instance(): BundleConfig {
return (BundleConfig._instance ? BundleConfig._instance : (BundleConfig._instance = new BundleConfig()));
}
// start >>>>>>
BundleName = {
game: {
prefab: {
"game1": 'prefab/game1',
"game2": 'prefab/game2',
},
sound: {
"music1": 'sound/music1',
"music2": 'sound/music2',
},
texture: {
"game1": 'texture/game1',
"game2": 'texture/game2',
},
},
home: {
prefab: {
"home1": 'prefab/home1',
"home2": 'prefab/home2',
},
sound: {
"music1": 'sound/music1',
"music2": 'sound/music2',
},
texture: {
"home1": 'texture/home1',
"home2": 'texture/home2',
},
},
}
// end >>>>>>
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a9ca4276-d7a3-44c1-9da5-95bf8f9de35c",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,131 +0,0 @@
import { Asset, AudioClip, Font, ImageAsset, JsonAsset, Material, Prefab, Sprite, SpriteFrame, Texture2D } from "cc";
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import BundleConfig from "./BundleConfig";
export type NoInfer<A extends any> = [A][A extends any ? 0 : never];
export type BundleName = keyof BundleConfig["BundleName"];
/** 资源模块化工具 */
export class BundleManager {
/**
* 根据资源类型获得对应文件
* @param assetType 资源类型
*/
private static getAssetUrl<T extends typeof Asset>(assetType: T) {
let typeUrl = "";
switch (assetType as any) {
case Prefab:
typeUrl = "prefab";
break;
case Material:
typeUrl = "shader";
break;
case AudioClip:
typeUrl = "sound";
break;
case ImageAsset:
case Texture2D:
case Sprite:
case SpriteFrame:
typeUrl = "texture";
break;
case JsonAsset:
typeUrl = "data";
break;
case Font:
typeUrl = "font";
break;
default:
console.error("没有该资源类型", assetType);
break;
}
return typeUrl;
}
/**
* 加载指定类型资源
* @param bundleName 外部资源包名
* @param assetName 目标加载资源名
*/
public static loadAsset<T extends typeof Asset,
TBundleName extends BundleName,
TAssetName = keyof BundleConfig['BundleName'][TBundleName]['prefab'] | keyof BundleConfig['BundleName'][TBundleName]['sound'] | keyof BundleConfig['BundleName'][TBundleName]['texture']>
(bundleName: TBundleName, assetName: NoInfer<TAssetName>, assetType: T): Promise<InstanceType<T>> {
let str = this.getAssetUrl(assetType);
// @ts-ignore
let url: string = BundleConfig.instance.BundleName[bundleName][str][assetName];
// 兼容3.x ,加载 SpriteFrame 路径需要添加后缀
if (assetType as any === SpriteFrame) {
url += "/spriteFrame";
}
else if (assetType as any === Texture2D) {
url += "/texture";
}
return new Promise(async (resolve, reject) => {
// @ts-ignore
oops.res.load(bundleName, url, (err: Error, res: any) => {
if (!err) {
// 加载成功
resolve(res);
}
else {
//加载失败
reject(err);
console.error(`外部资源包${bundleName},路径${url},加载失败`, err);
}
});
});
}
/**
* 加载预制体
* @param bundleName ab包名模块名
* @param assetName 资源名
*/
public static loadPrefab<TBundleName extends BundleName, TAssetName = keyof BundleConfig['BundleName'][TBundleName]['prefab']>
(bundleName: TBundleName, assetName: NoInfer<TAssetName>): Promise<Prefab> {
return this.loadAsset(bundleName, assetName, Prefab);
}
/**
* 加载音频
* @param bundleName ab包名模块名
* @param assetName 资源名
*/
public static loadAudio<TBundleName extends BundleName, TAssetName = keyof BundleConfig['BundleName'][TBundleName]['sound']>
(bundleName: TBundleName, assetName: NoInfer<TAssetName>): Promise<AudioClip> {
return this.loadAsset(bundleName, assetName, AudioClip);
}
/**
* 加载图片
* @param bundleName ab包名模块名
* @param assetName 资源名
*/
public static loadTextre<TBundleName extends BundleName, TAssetName = keyof BundleConfig['BundleName'][TBundleName]['texture']>
(bundleName: TBundleName, assetName: NoInfer<TAssetName>): Promise<SpriteFrame> {
return this.loadAsset(bundleName, assetName, SpriteFrame);
}
/**
* 通过资源相对路径释放资源
* @param bundleName ab包名模块名
* @param assetName 资源名
*/
public static release<T extends typeof Asset, TBundleName extends BundleName, TAssetName = keyof BundleConfig['BundleName'][TBundleName]['prefab'] | keyof BundleConfig['BundleName'][TBundleName]['sound'] | keyof BundleConfig['BundleName'][TBundleName]['texture']>
(bundleName: TBundleName, assetName: TAssetName, assetType: T) {
let str = this.getAssetUrl(assetType);
// @ts-ignore
let url: string = BundleConfig.BundleName[bundleName][str][assetName];
// 兼容3.x ,加载 SpriteFrame 路径需要添加后缀
if (assetType as any === SpriteFrame) {
url += "/spriteFrame";
}
else if (assetType as any === Texture2D) {
url += "/texture";
}
oops.res.release(url, bundleName);
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d4690e73-4043-47bc-9a21-199e4dd61cd6",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,12 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a4a97126-893b-4e9b-91f6-46cc5031563b",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,52 +0,0 @@
/*
* @Date: 2021-08-12 09:33:37
* @LastEditors: dgflash
* @LastEditTime: 2022-06-14 17:53:02
*/
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { NetData } from "../../../../../extensions/oops-plugin-framework/assets/libs/network/NetInterface";
import { NetProtocolPako } from "../../../../../extensions/oops-plugin-framework/assets/libs/network/NetProtocolPako";
import { WebSock } from "../../../../../extensions/oops-plugin-framework/assets/libs/network/WebSock";
import { netConfig } from "./NetConfig";
import { NetGameTips } from "./NetGameTips";
import { NetNodeGame } from "./NetNodeGame";
export enum NetChannelType {
/** 游戏服务器 */
Game = 0,
}
/** 游戏服务器心跳协议 */
class GameProtocol extends NetProtocolPako {
/** 心跳协议 */
getHearbeat(): NetData {
return `{"action":"LoginAction","method":"heart","data":"null","isCompress":false,"channelid":${netConfig.channelid},"callback":"LoginAction_heart"}`;
}
}
export class NetChannelManager {
public game!: NetNodeGame;
/** 创建游戏服务器 */
gameCreate() {
this.game = new NetNodeGame();
// 游戏网络事件逻辑统一在 NetGameTips 里写
this.game.init(new WebSock(), new GameProtocol(), new NetGameTips());
oops.tcp.setNetNode(this.game, NetChannelType.Game);
}
/** 连接游戏服务器 */
gameConnect() {
oops.tcp.connect({
url: `ws://${netConfig.gameIp}:${netConfig.gamePort}`,
autoReconnect: 0 // 手动重连接
}, NetChannelType.Game);
}
/** 断开游戏服务器 */
gameClose() {
oops.tcp.close(undefined, undefined, NetChannelType.Game);
}
}
export var netChannel = new NetChannelManager();

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "ac861aa1-8743-466a-9fc6-d36e1b13ad94",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,18 +0,0 @@
/*
* @Date: 2021-08-12 09:33:37
* @LastEditors: dgflash
* @LastEditTime: 2022-01-24 15:15:30
*/
/** 网络配置 */
class NetConfig {
public gameIp: string = "192.168.1.150";
public gamePort: string = "9587";
public dbid!: number;
public sdkUid!: string;
public serverId!: number;
public sessionKey!: string;
public channelid!: number;
}
export var netConfig = new NetConfig();

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "de66c7dd-a7e3-4f76-84ea-97c4cafc43cf",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,53 +0,0 @@
/*
* @Date: 2021-08-12 09:33:37
* @LastEditors: dgflash
* @LastEditTime: 2022-07-22 18:09:52
*/
import { Logger } from "../../../../../extensions/oops-plugin-framework/assets/core/common/log/Logger";
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { INetworkTips } from "../../../../../extensions/oops-plugin-framework/assets/libs/network/NetInterface";
import { GameEvent } from "../config/GameEvent";
import { tips } from "../prompt/TipsManager";
/** 游戏服务器提示 */
export class NetGameTips implements INetworkTips {
/** 连接提示 */
connectTips(isShow: boolean): void {
if (isShow) {
Logger.logNet("游戏服务器正在连接");
tips.netInstableOpen();
}
else {
Logger.logNet("游戏服务器连接成功");
tips.netInstableClose();
oops.message.dispatchEvent(GameEvent.GameServerConnected);
}
}
/** 重连接提示 */
reconnectTips(isShow: boolean): void { }
/** 请求提示 */
requestTips(isShow: boolean): void {
if (isShow) {
}
else {
}
}
/** 响应错误码提示 */
responseErrorCode(code: number): void {
console.log("游戏服务器错误码", code);
if (code < 0) {
tips.alert("netcode_" + code, () => {
// SDKPlatform.restartGame(;)
});
}
else {
tips.alert("netcode_" + code);
}
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "446e8905-8cfa-49c2-af78-5c60459754dc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,35 +0,0 @@
/*
* @Author: dgflash
* @Date: 2022-06-02 09:38:48
* @LastEditors: dgflash
* @LastEditTime: 2022-06-14 17:52:54
*/
import { CallbackObject, IRequestProtocol } from "../../../../../extensions/oops-plugin-framework/assets/libs/network/NetInterface";
import { NetNode } from "../../../../../extensions/oops-plugin-framework/assets/libs/network/NetNode";
import { netConfig } from "./NetConfig";
/** 网络节点扩展 */
export class NetNodeGame extends NetNode {
private isCompress: boolean = false;
public req(action: string, method: string, data: any, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false) {
let protocol: IRequestProtocol = {
cmd: action,
data: JSON.stringify(data),
isCompress: this.isCompress,
channelid: netConfig.channelid
}
return this.request(protocol, rspObject, showTips, force);
}
public reqUnique(action: string, method: string, data: any, rspObject: CallbackObject, showTips: boolean = true, force: boolean = false): boolean {
let protocol: IRequestProtocol = {
cmd: action,
data: JSON.stringify(data),
isCompress: this.isCompress,
channelid: netConfig.channelid
}
return super.requestUnique(protocol, rspObject, showTips, force);
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "bcdefa1e-679e-4d17-96f4-f5c25417a5e2",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -74,7 +74,9 @@ class TipsManager {
onBeforeRemove: (node, next) => {
tween(node)
.to(0.2, { scale: new Vec3(0.1, 0.1, 0.1) })
.call(next)
.call((target, data) => {
next();
})
.start();
},
}

View File

@@ -5,6 +5,7 @@
* @LastEditTime: 2023-08-28 17:23:59
*/
import { Component, EventTouch, _decorator } from "cc";
import { ZipLoader } from "../../../../extensions/oops-plugin-framework/assets/core/common/loader/ZipLoader";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { LabelChange } from "../../../../extensions/oops-plugin-framework/assets/libs/gui/label/LabelChange";
import { UIID } from "../common/config/GameUIConfig";
@@ -55,18 +56,18 @@ export class Demo extends Component {
})
// this.test_zip();
this.test_zip();
}
// private async test_zip() {
// var z = new ZipLoader();
// var zip_path = "zip/data";
// await z.load(zip_path);
// var a = await z.getJson(zip_path, "data/a.json");
// console.log(a);
// var s = await z.getSpriteFrame(zip_path, "data/Dungeon.png");
// console.log(s);
// }
private async test_zip() {
var z = new ZipLoader();
var zip_path = "zip/data";
await z.load(zip_path);
var a = await z.getJson(zip_path, "data/a.json");
console.log(a);
var s = await z.getSpriteFrame(zip_path, "data/Dungeon.png");
console.log(s);
}
private btn_long(event: EventTouch, data: any) {
oops.gui.toast(data, true);

View File

@@ -1,6 +1,6 @@
{
"creator": {
"version": "3.8.3"
"version": "3.8.4"
},
"dependencies": {
"crypto-es": "^1.2.7"

View File

@@ -1,3 +1,3 @@
{
"__version__": "1.0.9"
"__version__": "1.0.10"
}

View File

@@ -1,4 +1,4 @@
{
"__version__": "1.0.0",
"__version__": "1.0.1",
"current-scene": "840b2f07-d39c-49eb-9b34-ad0a077bf561"
}