import { v3, Vec3, _decorator ,Prefab,instantiate} from "cc"; import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { smc } from "../../common/SingletonModuleComp"; import { Role } from "../../role/Role"; import { Monster } from "../../monster/Monster"; import { Hero } from "../../heros/Hero"; // import MapRoadUtils from "./map/road/MapRoadUtils"; import { MapViewScene } from "./MapViewScene"; import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops"; const { ccclass, property } = _decorator; @ccclass('MapViewComp') @ecs.register('MapView', false) export class MapViewComp extends CCComp { scene: MapViewScene = null!; /** 是否正在转场 */ /** 当前地图数据 */ current_map: any; /** 转场碰撞点对象集合 */ private timer: Timer = new Timer(2); onLoad(){ // 监听全局事件 oops.message.on("monster_load", this.onMonsterLoaded, this); } private onMonsterLoaded(event: string, args: any) { console.log('on_monster_load'); } reset(): void { } start() { this.scene = this.getComponent(MapViewScene); } /** 转场 */ protected update(dt: number): void { if (this.timer.update(dt)) { // console.log('每2秒触发一次'); this.addHero(); } } private mapLoaded() { } /** 添加玩家 */ private addHero() { this.scene.node.active = true if (smc.heros.length>0){ let hero = ecs.getEntity(Hero); hero.load(v3(-360,-60), smc.heros[0].profession); smc.heros.splice(0,1) } if (smc.monsters.length>0){ var path = "game/monster/monster"; var prefab: Prefab = oops.res.get(path, Prefab)!; var node = instantiate(prefab); var scene = smc.map.MapView.scene; node.parent = scene.entityLayer!.node!; node.setPosition(v3(360,-60)) this.node.addChild(node); // let monster = ecs.getEntity(Monster); // monster.load(v3(360,-60),smc.monsters[0].speed); // monster.move(v3(0,-60)); // smc.monsters.splice(0,1) } } private getRandomInt(min: number, max: number): number { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } }