2022-03-21 09:27:37 +00:00
|
|
|
import { ECSController } from "./Core/ECSController";
|
|
|
|
import { ECSWorld } from "./ECS/lib/ECSWorld";
|
|
|
|
import { SysAttack } from "./ECS/systems/SysAttack";
|
|
|
|
import { SysBehaviorTree } from "./ECS/systems/SysBehaviorTree";
|
|
|
|
import { ITouchProcessor, SysCocosView } from "./ECS/systems/SysCocosView";
|
|
|
|
import { SysMonitor } from "./ECS/systems/SysMonitor";
|
|
|
|
import { SysMovable } from "./ECS/systems/SysMovable";
|
|
|
|
import { SysRoleState } from "./ECS/systems/SysRoleState";
|
|
|
|
import { WorldCocosView } from "./ECS/worlds/WorldCocosView";
|
|
|
|
|
|
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
|
|
|
|
@ccclass
|
|
|
|
export default class Main extends cc.Component {
|
|
|
|
private _world: ECSWorld = null;
|
|
|
|
private _touchHandler: ITouchProcessor[] = [];
|
|
|
|
|
|
|
|
private ecsController = new ECSController();
|
2022-05-15 03:30:36 +00:00
|
|
|
|
|
|
|
protected onLoad(): void {
|
|
|
|
cc.dynamicAtlasManager.enabled = true;
|
|
|
|
}
|
|
|
|
|
2022-03-21 09:27:37 +00:00
|
|
|
start () {
|
|
|
|
this.ecsController.world = this._world = new WorldCocosView();
|
|
|
|
this._world.createEntity(); // 创建0号实体
|
|
|
|
this._world.addSystem(new SysBehaviorTree()); // 行为树
|
|
|
|
this._world.addSystem(new SysMovable()); // 移动
|
|
|
|
this._world.addSystem(new SysMonitor()); // 监视
|
|
|
|
this._world.addSystem(new SysAttack()); // 攻击系统
|
|
|
|
this._world.addSystem(new SysRoleState()); // role state
|
|
|
|
this._world.addSystem(new SysCocosView()); // cocos view
|
|
|
|
|
|
|
|
this.regiestTouchEvent();
|
|
|
|
|
2022-03-30 02:57:19 +00:00
|
|
|
//this.regiestTouchHandler();
|
|
|
|
|
2022-05-15 03:30:36 +00:00
|
|
|
|
|
|
|
|
2022-03-21 09:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onClick1() {
|
2022-10-22 02:43:38 +00:00
|
|
|
for(let i=0; i<1; i++) {
|
2022-05-15 03:30:36 +00:00
|
|
|
this.ecsController.createRoleEntity("Biker");
|
|
|
|
}
|
2022-03-21 09:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onClick2() {
|
2022-10-22 02:43:38 +00:00
|
|
|
for(let i=0; i<1; i++) {
|
2022-05-15 03:30:36 +00:00
|
|
|
this.ecsController.createRoleEntity("Cyborg");
|
|
|
|
}
|
2022-03-21 09:27:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 02:57:19 +00:00
|
|
|
onClick3() {
|
|
|
|
cc.debug.setDisplayStats(!cc.debug.isDisplayStats());
|
|
|
|
}
|
|
|
|
|
2022-03-21 09:27:37 +00:00
|
|
|
protected update(dt: number): void {
|
|
|
|
if(this._world) this._world.update(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
private regiestTouchEvent() {
|
|
|
|
this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchStart, this);
|
|
|
|
this.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
|
|
|
this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
|
|
|
|
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _onTouchStart(e: cc.Event.EventTouch) {
|
|
|
|
for(let i = 0; i < this._touchHandler.length; i++) {
|
|
|
|
this._touchHandler[i].onTouchStart(e.getLocation(), this._world);
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 02:57:19 +00:00
|
|
|
private _onTouchMove(e: cc.Event.EventTouch) {
|
|
|
|
for(let i = 0; i < this._touchHandler.length; i++) {
|
|
|
|
this._touchHandler[i].onTouchMove(e.getLocation(), this._world);
|
|
|
|
}
|
2022-03-21 09:27:37 +00:00
|
|
|
}
|
2022-03-30 02:57:19 +00:00
|
|
|
private _onTouchEnd(e: cc.Event.EventTouch) {
|
|
|
|
for(let i = 0; i < this._touchHandler.length; i++) {
|
|
|
|
this._touchHandler[i].onTouchEnd(e.getLocation(), this._world);
|
|
|
|
}
|
2022-03-21 09:27:37 +00:00
|
|
|
}
|
2022-03-30 02:57:19 +00:00
|
|
|
private _onTouchCancel(e: cc.Event.EventTouch) {
|
|
|
|
for(let i = 0; i < this._touchHandler.length; i++) {
|
|
|
|
this._touchHandler[i].onTouchCancel(e.getLocation(), this._world);
|
|
|
|
}
|
2022-03-21 09:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public regiestTouchHandler(handler: ITouchProcessor) {
|
|
|
|
this._touchHandler.push(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
public unRegiestTouchHandler(handler:ITouchProcessor) {
|
|
|
|
for(let i = this._touchHandler.length - 1; i >= 0; i--) {
|
|
|
|
if(this._touchHandler[i] == handler) {
|
|
|
|
this._touchHandler.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|