跳到主要内容

getTargetRandom 获取目标角色 - 随机

getTargetRandom

类型: MethodDeclaration

所属类: TargetManager

定义位置: actor.ts

描述

获取目标角色 - 随机

参数 selector: 目标角色选择器

返回值:目标池中符合条件的角色实例

参数

参数名类型描述默认值
selectorActorSelector--

返回值

类型: Actor \| undefined

目标池中符合条件的角色实例

源代码

位置: 第 5462 行

public getTargetRandom(selector: ActorSelector): Actor | undefined {
let target: Actor | undefined
let count = 0
const inspector = Actor.inspectors[selector]
const owner = this.actor
const targets = this.targets
const indices = GL.arrays[0].uint32
const length = targets.length
for (let i = 0; i < length; i++) {
// 检查角色关系,把索引保存在indices中
if (inspector(owner, targets[i])) {
indices[count++] = i
}
}
if (count !== 0) {
// 获取随机索引指向的角色
target = targets[indices[Math.floor(Math.random() * count)]]
}
return target
}

文档生成时间:2025/7/7 12:07:06