import * as THREE from 'three' import { FollowMotionHelper, System, VirtualEntity } from '../../src' import { ExampleEntity } from './example-entity' export class ExampleSystem extends System { async addEntities() { // 创建一个实体并添加到系统中 const entity = new ExampleEntity({ name: 'example-entity', // 名称 position: new THREE.Vector3(0, 0, 0), // 位置 rotation: new THREE.Euler(0, 0, 0) // 旋转 }) await this.addEntity(entity) // 创建另一个实体并添加到系统中 const entity1 = new ExampleEntity({ name: 'example-entity1', // 名称 position: new THREE.Vector3(0, 0, 1000), // 位置 rotation: new THREE.Euler(0, 0, 0) // 旋转 }) await this.addEntity(entity1) } async addHelpers() { // 创建一个跟随运动助手并添加到系统中 const helper = new FollowMotionHelper() await this.addHelper('follow-motion', helper) } registerEvents() { // 注册事件监听 const { EventManager } = this._app EventManager.subscribe( 'move', // 事件名称 (data: any) => { // 事件处理函数 const entity = this.getEntity('example-entity') // 如果实体存在,则更新其姿态 entity && entity.updatePose(data.position, entity.Quaternion, data.animateTime) }, 'example-system' // 事件作用域 ) } async onAdded() { // 当系统被添加时执行的操作 await this.addEntities() this.addHelpers() this.registerEvents() // 获取跟随运动助手并附加配置 const helper: FollowMotionHelper = this.getHelper('follow-motion') helper.attach('follow1', { entity: this.getEntity('example-entity1'), // 要跟随的实体 followObject: this.getEntity('example-entity')?.group // 跟随的目标对象 }) } onRemoved(): void { // 当系统被移除时执行的操作 const { EventManager } = this._app EventManager.unsubscribeInScope('move', 'example-system') } onUpdating(deltaTime: number): void { // 系统更新时执行的操作 } }