mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-07 01:01:09 +08:00
优化
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
* @LastEditTime: 2022-09-02 12:09:55
|
||||
*/
|
||||
import { Node, director } from 'cc';
|
||||
import { ViewUtil } from '../utils/ViewUtil';
|
||||
import { resLoader } from '../common/loader/ResLoader';
|
||||
import { GameComponent } from '../../module/common/GameComponent';
|
||||
import { resLoader } from '../common/loader/ResLoader';
|
||||
import { ViewUtil } from '../utils/ViewUtil';
|
||||
|
||||
/** 游戏元素打开参数 */
|
||||
export interface ElementParams {
|
||||
@@ -45,8 +45,7 @@ export class GameManager {
|
||||
let node: Node = null!;
|
||||
// 自动内存管理
|
||||
if (parent instanceof GameComponent) {
|
||||
await parent.load(bundleName, prefabPath);
|
||||
node = parent.createPrefabNode(prefabPath, bundleName);
|
||||
node = await parent.createPrefabNode(prefabPath, bundleName);
|
||||
node.parent = parent.node;
|
||||
}
|
||||
// 手动内存管理
|
||||
|
||||
@@ -99,7 +99,7 @@ export class LayerGame extends Node {
|
||||
resLoader.release(lge.params.config.prefab!, lge.params.config.bundle);
|
||||
}
|
||||
}
|
||||
node.removeFromParent();
|
||||
node.destroy();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { CompType } from "../../libs/ecs/ECSModel";
|
||||
import { CCBusiness } from "./CCBusiness";
|
||||
import { CCView } from "./CCView";
|
||||
import { CCViewVM } from "./CCViewVM";
|
||||
import { GameComponent } from "./GameComponent";
|
||||
|
||||
export type ECSCtor<T extends ecs.Comp> = __private.__types_globals__Constructor<T> | __private.__types_globals__AbstractedConstructor<T>;
|
||||
export type ECSView = CCViewVM<CCEntity> | CCView<CCEntity>;
|
||||
@@ -74,12 +75,25 @@ export abstract class CCEntity extends ecs.Entity {
|
||||
* @param path 显示资源地址
|
||||
* @param bundleName 资源包名称
|
||||
*/
|
||||
addPrefab<T extends ECSView>(ctor: ECSCtor<T>, parent: Node, path: string, bundleName: string = resLoader.defaultBundleName): Node {
|
||||
const node = ViewUtil.createPrefabNode(path, bundleName);
|
||||
const comp = node.getComponent(ctor)!;
|
||||
this.add(comp);
|
||||
node.parent = parent;
|
||||
return node;
|
||||
addPrefab<T extends ECSView>(ctor: ECSCtor<T>, parent: Node | GameComponent, path: string, bundleName: string = resLoader.defaultBundleName): Promise<Node> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let node: Node = null!;
|
||||
// 跟随父节点施放自动释放当前资源
|
||||
if (parent instanceof GameComponent) {
|
||||
node = await parent.createPrefabNode(path, bundleName);
|
||||
const comp = node.getComponent(ctor)!;
|
||||
this.add(comp);
|
||||
node.parent = parent.node;
|
||||
}
|
||||
// 手动内存管理
|
||||
else {
|
||||
node = await ViewUtil.createPrefabNodeAsync(path, bundleName);
|
||||
const comp = node.getComponent(ctor)!;
|
||||
this.add(comp);
|
||||
node.parent = parent;
|
||||
}
|
||||
resolve(node);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-12-13 11:36:00
|
||||
*/
|
||||
import { Asset, Button, Component, EventHandler, EventKeyboard, EventTouch, Input, Node, Sprite, SpriteFrame, __private, _decorator, input, isValid } from "cc";
|
||||
import { Asset, Button, Component, EventHandler, EventKeyboard, EventTouch, Input, Node, Prefab, Sprite, SpriteFrame, __private, _decorator, input, instantiate, isValid } from "cc";
|
||||
import { oops } from "../../core/Oops";
|
||||
import { AudioEffect } from "../../core/common/audio/AudioEffect";
|
||||
import { IAudioParams } from "../../core/common/audio/IAudio";
|
||||
@@ -99,8 +99,12 @@ export class GameComponent extends Component {
|
||||
* 从资源缓存中找到预制资源名并创建一个显示对象
|
||||
* @param path 资源路径
|
||||
*/
|
||||
createPrefabNode(path: string, bundleName: string = oops.res.defaultBundleName): Node {
|
||||
return ViewUtil.createPrefabNode(path, bundleName);
|
||||
createPrefabNode(path: string, bundleName: string = oops.res.defaultBundleName): Promise<Node> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const prefab = await this.load(bundleName, path, Prefab);
|
||||
const node = instantiate(prefab);
|
||||
resolve(node);
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user