1.find
find(path: string, referenceNode?: Node): Node | null
// 通过路径从节点树中查找节点的方法,路径是大小写敏感的,并且通过 `/` 来分隔节点层级。 即使节点的状态是未启用的也可以找到.
参数:
名称 | 类型 | 描述 |
---|---|---|
path | string | 查找路径 |
referenceNode | Node | 如果给定,搜索将限制在参考节点的子节点树中 |
2.Node 类
2.1 属性
- active
当前节点的自身激活状态,只跟自身有关 - activeInHierarchy
表示此节点是否在场景中激活,跟自身和父物体有关 - parent
父节点 - worldPosition, worldRotation, worldScale
世界坐标系下的坐标, 旋转, 缩放 - position, rotation, scale
本地坐标系下的坐标, 旋转(四元数表示), 缩放 - children
节点下的所有子节点 - components
获取此节点下的所有组件
2.2 方法
-
walk
walk(preFunc: (target: Node) => void, postFunc ?: (target: Node) => void): void // 遍历该节点的子树里的所有节点并按规则执行回调函数。preFunc 会在访问它的子节点之前调用,postFunc 会在访问所有子节点之后调用
-
on
在节点上注册指定类型的回调函数
-
getComponent, getComponentInChildren
获取 节点/节点和子节点 上指定类型的组件,存在则返回,不存在返回 null。
-
getComponents, getComponentsInChildren
递归查找 自身/自身和所有子节点 中指定类型的所有组件 -
getChildByPath, getChildByName
通过 路径/名称 获取节点的子节点, -
getParent, setParent
取/设 父节点 -
addCompontent, removeCompontent
添加/移除 组件 -
addChild, removeChild, removeAllChildren, destroyAllChildren
添加/移除/销毁 子节点 -
translate, rotate
移动/旋转 节点 -
lookAt
设置当前节点旋转为面向目标位置,默认前方为 -z 方向 -
getWorldPosition, getWorldRotation, getWorldScale, getPosition, getRotation, getScale
取得 世界/本地 坐标/旋转/缩放 -
setPosition, setRotation, setRotationFromEuler, setScale
设置本地 坐标/用四元数设置本地旋转/用欧拉角设置本地旋转/缩放 -
setWorldPosition, setWorldRotation, setWorldRotationFromEuler, setWorldScale
设置世界 坐标/用四元数设置世界 旋转/用欧拉角设置世界 旋转/缩放 -
setSiblingIndex, getSiblingIndex
设置/获取 当前节点在父节点的 children 数组中的位置