修复倒计时管理在时间结束时报错问题,扩展ECS获取有eid的实体方法

This commit is contained in:
dgflash
2022-02-22 21:56:46 +08:00
parent e6da83e2b3
commit c0fc10ef59
6 changed files with 53 additions and 95 deletions

View File

@@ -343,9 +343,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -508,9 +506,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -715,9 +711,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -880,9 +874,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -1087,9 +1079,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -1252,9 +1242,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -1459,9 +1447,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -1624,9 +1610,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -1831,9 +1815,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -1996,9 +1978,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -2203,9 +2183,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -2368,9 +2346,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -2480,9 +2456,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -2632,9 +2606,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -2768,9 +2740,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -3023,9 +2993,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -3188,9 +3156,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -3373,9 +3339,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -3538,9 +3502,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -3723,9 +3685,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -3888,9 +3848,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -4073,9 +4031,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -4238,9 +4194,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -4423,9 +4377,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -4588,9 +4540,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -4773,9 +4723,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -4938,9 +4886,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -5050,9 +4996,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},
@@ -5139,9 +5083,7 @@
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"root": null,
"asset": {
"__id__": 0
},

View File

@@ -26,7 +26,7 @@ export class TimerManager extends EventDispatcher {
constructor(component: Component) {
super();
this.component = component;
this.schedule(this.onUpdate, 1);
this.schedule(this.onUpdate.bind(this), 1);
}
/**
* 设置服务器时间与本地时间间隔
@@ -154,7 +154,7 @@ export class TimerManager extends EventDispatcher {
/** 触发倒计时完成事件 */
private timerComplete(data: any) {
if (data.onComplete) data.onComplete.call(data.object);
if (data.event) this.dispatchEvent(data.event);
if (data.event) this.dispatchEvent(data.event);
}
/** 注册指定对象的倒计时属性更新 */

View File

@@ -130,6 +130,7 @@ export default class LabelTime extends Label {
}
private onComplete() {
this.format();
if (this.complete) this.complete(this.node);
}
}

View File

@@ -148,6 +148,23 @@ export module ecs {
*/
let eid = 1;
/** 扩展:获取带 eid 自增量的实体继承Entity方式的编码风格可减少一定代码量 */
export function getEntity<T extends Entity>(ctor: any): T {
let entity: any = entityPool.pop();
if (!entity) {
entity = new ctor();
entity.eid = eid++; // 实体id也是有限的资源
}
if (entity.init)
entity.init();
else
console.error(`${ctor.name} 实体缺少 init 方法初始化默认组件`);
eid2Entity.set(entity.eid, entity);
return entity as T;
}
/**
* 创建实体
*/
@@ -592,7 +609,7 @@ export module ecs {
}
/**
* 销毁实体,实体会被回收到实体缓存池中。
* 销毁实体,实体会被回收到实体缓存池中。 扩展isClearData参数
* @param isClearData 是否清除组件上的数据
*/
destroy(isClearData: boolean = true) {

View File

@@ -7,9 +7,9 @@
import { Message } from "../../../core/common/event/MessageManager";
import { storage } from "../../../core/common/storage/SqlUtil";
import { oops } from "../../../core/Oops";
import { ecs } from "../../../core/libs/ECS";
import { VM } from "../../../core/libs/model-view/ViewModel";
import { oops } from "../../../core/Oops";
import { GameEvent } from "../../common/config/GameEvent";
import { netConfig } from "../../common/net/NetConfig";
import { Role } from "../../role/Role";
@@ -70,7 +70,7 @@ export class AccountNetDataSystem extends ecs.ComblockSystem implements ecs.IEnt
/** 创建角色对象(自定义逻辑) */
private createRole(e: Account, data: any) {
var role = new Role();
var role = ecs.getEntity<Role>(Role);
// 角色数据
role.RoleModel.id = data.id;

View File

@@ -44,9 +44,7 @@ export class Role extends ecs.Entity {
RoleView!: RoleViewComp;
RoleViewInfo!: RoleViewInfoComp;
constructor() {
super();
protected init() {
// 初始化实体常住 ECS 组件,定义实体特性
this.addComponents<ecs.Comp>(
RoleModelComp,