package system import ( "fmt" "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/components" "joylink.club/rtsssimulation/umi" ) func FindEntityById(world ecs.World, id string) *ecs.Entry { query := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent)) return QueryEntityById(world, query, id) } func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry { var entry *ecs.Entry = nil func() { defer simpleRecover() q.Each(world, func(e *ecs.Entry) { if id == components.DeviceIdentityComponent.Get(e).Id { entry = e panic(fmt.Sprintf("找到实体[%s],结束查找", id)) } }) }() // return entry } // 捕获panic并恢复执行 func simpleRecover() { recover() } /////////////////////////////////////////////////////////////////////////// var worldModelStorageQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ModelStorageRefComponent)) func WorldModelStorage(world ecs.World) umi.IModelManager { e, ok := worldModelStorageQuery.First(world) if ok { return components.ModelStorageRefComponent.Get(e).ModelManager } else { return nil } }