玩法 / Spline
Spline Class
样条线
Hierarchy
↳
Spline
Table of contents
Properties
click
Properties
onBeforeDestroyDelegate: MulticastDelegate<() => void> |
|---|
| 物体销毁前事件回调 |
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other |
| 监听自定义属性同步事件 |
onDestroyDelegate: MulticastDelegate<() => void> |
| 物体销毁后事件回调 |
Accessors
color(): LinearColor |
|---|
| 获取样条线颜色 |
loop(): boolean |
| 获取是否自动闭合,起点和终点生成一条连接线 |
pointCount(): number |
| 获取样条线点的数量 |
width(): number |
| 获取样条线的宽度 |
click
Accessors
assetId(): string |
|---|
| 获取当前物体使用资源的GUID |
gameObjectId(): string |
| 获取物体的唯一标识(唯一标识一个对象的字符串)。 |
isDestroyed(): boolean |
| 当前物体是否被销毁 |
isReady(): boolean |
| 当前物体状态 |
localTransform(): Transform |
| 当前物体本地变换 |
name(): string |
| 返回当前物体名称 |
netStatus(): NetStatus |
| 获取当前物体同步状态 |
parent(): GameObject |
| 获取当前父物体 |
prefabAssetId(): string |
| 返回当前物体使用的预制体资源ID,如果当前物体不是预制体,则返回空 |
sceneCaptureTag(): string |
| 获取当前物体的捕捉标签 |
tag(): string |
| 获取当前物体的标签 |
worldTransform(): Transform |
| 当前物体世界变换 |
Methods
clearLinePoints(): void |
|---|
| 清空线条点 |
getArriveTangent(index: number): Vector |
| 获取到达切线 |
getLeaveTangent(index: number): Vector |
| 获取离开切线 |
getPointPosition(index: number): Vector |
| 获取线条中指定索引处的顶点位置 |
getPointRotation(index: number): Rotation |
| 获取线条中指定索引处的顶点旋转 |
getPointType(index: number): PointType |
| 获取线条类型 |
getPointXScale(index: number): number |
| 获取线条中指定索引处的顶点X轴缩放 |
setArriveTangent(index: number, tangent: Vector): void |
| 设置到达切线 |
setLeaveTangent(index: number, tangent: Vector): void |
| 设置离开切线 |
setPointPosition(index: number, position: Vector): void |
| 设置线条中指定索引处的顶点位置 |
setPointRotation(index: number, rotation: Rotation): void |
| 设置线条中指定索引处的顶点旋转 |
setPointType(index: number, type: PointType): void |
| 设置线条类型 |
setPointXScale(index: number, xScale: number): void |
| 设置线条中指定索引处的顶点X轴缩放 |
drawBox(center: Vector, extent: Vector, color: LinearColor, rotation: Rotation, duration: number, thickness: number): void client |
| 绘制盒体 |
drawCapsule(center: Vector, halfHeight: number, radius: number, rotation: Rotation, color: LinearColor, duration: number, thickness: number): void client |
| 绘制胶囊体 |
drawCircle(center: Vector, radius: number, segments: number, color: LinearColor, duration: number, thickness: number, yAxis?: Vector, zAxis?: Vector, drawAxis?: boolean): void client |
| 绘制圆圈 |
drawLine(start: Vector, end: Vector, color: LinearColor, duration: number, thickness: number): void client |
| 绘制线段 |
drawPoint(position: Vector, size: number, color: LinearColor, duration: number): void client |
| 绘制点 |
drawSphere(center: Vector, radius: number, segments: number, color: LinearColor, duration: number, thickness: number): void client |
| 绘制球体 |
click
Methods
addComponent<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>, bInReplicates?: boolean): T: extends Script<T> |
|---|
| 添加一个脚本组件 |
asyncGetChildByName(name: string): Promise<GameObject> |
| 异步根据名称查找子物体 |
asyncReady(): Promise<GameObject> |
| 物体准备好后返回 |
clone(gameObjectInfo?: GameObjectInfo): GameObject |
| 复制对象 |
destroy(): void |
| 删除对象 |
getBoundingBox(nonColliding?: boolean, includeFromChild?: boolean, outer?: Vector): Vector |
| 获取物体包围盒大小 |
getBounds(onlyCollidingComponents: boolean, originOuter: Vector, boxExtentOuter: Vector, includeFromChild?: boolean): void |
| 获取物体边界 |
getChildByGameObjectId(gameObjectId: string): GameObject |
| 根据 gameObjectId 查找子物体 |
getChildByName(name: string): GameObject |
| 根据名称查找子物体 |
getChildByPath(path: string): GameObject |
| 根据路径查找子物体 |
getChildren(): GameObject[] |
| 获取子物体 |
getChildrenByName(name: string): GameObject[] |
| 通过名字查找所有的子物体 |
getComponent<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T> |
| 获取指定类型的组件 |
getComponentPropertys<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>): Map<string, IPropertyOptions> |
| 获取脚本组件属性 |
getComponents<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T>[] |
| 获取指定类型的所有组件 |
getCustomProperties(): string[] |
| 获取自定义属性名字数组,返回对象所有自定义属性。 |
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType |
| 获取自定义属性的值,服务器客户端均可调用,客户端调用需注意属性同步的延迟。 |
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> client |
| 获取给定自定义属性修改时触发的事件代理。双端对象在服务器修改自定义属性后,双端均会触发事件并执行绑定函数。 |
getVisibility(): boolean |
| 获取物体是否被显示 |
moveBy(velocity: Vector, isLocal?: boolean): void other |
| 按给定的速度矢量随时间平滑地移动对象 |
moveTo(targetPosition: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other |
| 在指定时间内从当前位置平滑移动至目标位置 |
rotateBy(rotation: Quaternion Rotation, multiplier: number, isLocal?: boolean): void other |
| 按给定的旋转量随时间平滑地旋转对象 |
rotateTo(targetRotation: Quaternion Rotation, time: number, isLocal?: boolean, onComplete?: () => void): void other |
| 在指定时间内从当前旋转平滑变化至目标旋转 |
scaleBy(scale: Vector, isLocal?: boolean): void other |
| 按每秒给定的缩放矢量随时间平滑缩放对象 |
scaleTo(targetScale: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other |
| 在指定时间内从当前缩放平滑变化至目标缩放 |
setAbsolute(absolutePosition?: boolean, absoluteRotation?: boolean, absoluteScale?: boolean): void |
| 设置物体localTransform是相对于父物体或者世界 |
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void server |
| 设置自定义属性的值,双端对象需在服务器调用。当设置的属性不存在时会新增自定义属性。 |
setVisibility(status: boolean PropertyStatus, propagateToChildren?: boolean): void |
| 设置物体是否被显示 |
stopMove(): void other |
| 中断moveTo()、moveBy()的进一步移动 |
stopRotate(): void other |
| 中断从rotateTo()或rotateBy()的进一步旋转 |
stopScale(): void other |
| 中断从ScaleTo()或ScaleBy()的进一步缩放 |
asyncFindGameObjectById(gameObjectId: string): Promise<GameObject> |
| 通过 gameObjectId 异步查找 GameObject |
asyncGetGameObjectByPath(path: string): Promise<GameObject> |
| 通过路径异步查找物体 |
asyncSpawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): Promise<T: extends GameObject<T>> |
| 异步构造一个物体,创建时请尽量把信息通过 gameObjectInfo 传入以达到性能最优化。 |
bulkPivotTo(gameObjects: GameObject[], transforms: Transform[]): void |
| 批量设置位置 |
findGameObjectById(gameObjectId: string): GameObject |
| 通过 gameObjectId 查找物体 |
findGameObjectByName(name: string): GameObject |
| 通过名字查找物体 |
findGameObjectsByName(name: string): GameObject[] |
| 通过名字查找物体 |
findGameObjectsByTag(tag: string): GameObject[] |
| 通过自定义标签获取物体 |
getGameObjectByPath(path: string): GameObject |
| 通过路径查找物体 |
spawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): T: extends GameObject<T> |
| 构造一个物体,创建时请尽量把信息通过 gameObjectInfo 传入以达到性能最优化。 |
Properties
Accessors
color
• | • | ||||
|---|---|---|---|---|---|
获取样条线颜色 Returns
| 设置样条线颜色 Parameters
|
loop
• | • | ||||
|---|---|---|---|---|---|
获取是否自动闭合,起点和终点生成一条连接线 Returns
| 设置是否自动闭合,起点和终点生成一条连接线 Parameters
|
pointCount
• | • | ||||
|---|---|---|---|---|---|
获取样条线点的数量 Returns
| 设置样条线点的数量 Parameters
|
width
• | • | ||||
|---|---|---|---|---|---|
获取样条线的宽度 Returns
| 设置样样条线的宽度 Parameters
|
Methods
clearLinePoints
• clearLinePoints(): void
清空线条点
getArriveTangent
• getArriveTangent(index): Vector
获取到达切线
Parameters
index number | 索引 type: 整型 range: 无 |
|---|
Returns
Vector | 到达切线 |
|---|
getLeaveTangent
• getLeaveTangent(index): Vector
获取离开切线
Parameters
index number | 索引 type: 整型 range: 无 |
|---|
Returns
Vector | 离开切线 |
|---|
getPointPosition
• getPointPosition(index): Vector
获取线条中指定索引处的顶点位置
Parameters
index number | 索引 type: 整型 range: 无 |
|---|
Returns
Vector | 顶点位置 |
|---|
getPointRotation
• getPointRotation(index): Rotation
获取线条中指定索引处的顶点旋转
Parameters
index number | 索引 type: 整型 range: 无 |
|---|
Returns
Rotation | 顶点旋转 |
|---|
getPointType
• getPointType(index): PointType
获取线条类型
Parameters
index number | 索引 type: 整型 range: 无 |
|---|
Returns
PointType | 顶点线条类型 |
|---|
getPointXScale
• getPointXScale(index): number
获取线条中指定索引处的顶点X轴缩放
Parameters
index number | 索引 type: 整型 range: 无 |
|---|
Returns
number | 顶点X轴缩放 |
|---|
setArriveTangent
• setArriveTangent(index, tangent): void
设置到达切线
Parameters
index number | 索引 type: 整型 range: 无 |
|---|---|
tangent Vector | 到达切线 |
setLeaveTangent
• setLeaveTangent(index, tangent): void
设置离开切线
Parameters
index number | 索引 type: 整型 range: 无 |
|---|---|
tangent Vector | 离开切线 |
setPointPosition
• setPointPosition(index, position): void
设置线条中指定索引处的顶点位置
Parameters
index number | 索引 type: 整型 range: 无 |
|---|---|
position Vector | 顶点位置 |
setPointRotation
• setPointRotation(index, rotation): void
设置线条中指定索引处的顶点旋转
Parameters
index number | 索引 type: 整型 range: 无 |
|---|---|
rotation Rotation | 顶点旋转 |
setPointType
• setPointType(index, type): void
设置线条类型
Parameters
index number | 索引 type: 整型 range: 无 |
|---|---|
type PointType | 顶点线条类型 |
setPointXScale
• setPointXScale(index, xScale): void
设置线条中指定索引处的顶点X轴缩放
Parameters
index number | 索引 type: 整型 range: 无 |
|---|---|
xScale number | 顶点X轴缩放 default:1 range: [0.01, 1000] type: 浮点型 |
drawBox
• Static drawBox(center, extent, color, rotation, duration, thickness): void client
绘制盒体
Parameters
center Vector | 中心位置 |
|---|---|
extent Vector | 盒体范围 |
color LinearColor | 颜色 |
rotation Rotation | 盒体朝向 |
duration number | 持续时间 range: 无 type: 浮点型 |
thickness number | 厚度 range: 无 type: 浮点型 |
ts
@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawBox(Vector.zero, Vector.one, LinearColor.white, Rotation.zero, 1, 1);
});
}
}
}@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawBox(Vector.zero, Vector.one, LinearColor.white, Rotation.zero, 1, 1);
});
}
}
}drawCapsule
• Static drawCapsule(center, halfHeight, radius, rotation, color, duration, thickness): void client
绘制胶囊体
Parameters
center Vector | 中心位置 |
|---|---|
halfHeight number | 胶囊体半高 range: 无 type: 浮点型 |
radius number | 胶囊体半径 range: 无 type: 浮点型 |
rotation Rotation | 胶囊体朝向 |
color LinearColor | 颜色 |
duration number | 持续时间 range: 无 type: 浮点型 |
thickness number | 厚度 range: 无 type: 浮点型 |
ts
@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawCapsule(Vector.zero, 20, 10, Rotation.zero, LinearColor.white, 1, 1);
});
}
}
}@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawCapsule(Vector.zero, 20, 10, Rotation.zero, LinearColor.white, 1, 1);
});
}
}
}drawCircle
• Static drawCircle(center, radius, segments, color, duration, thickness, yAxis?, zAxis?, drawAxis?): void client
绘制圆圈
Parameters
center Vector | 中心位置 |
|---|---|
radius number | 半径 range: 无 type: 浮点型 |
segments number | 段数 range: 无 type: 整形 |
color LinearColor | 颜色 default: |
duration number | 持续时间 range: 无 type: 浮点型 |
thickness number | 厚度 range: 无 type: 浮点型 |
yAxis? Vector | Y轴方向 default: undefined |
zAxis? Vector | Z轴方向 default: undefined |
drawAxis? boolean | 是否绘制轴 range:[true,false] default: undefined |
ts
@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawCircle(Vector.zero, 1, 4, LinearColor.white, 1, 1);
});
}
}
}@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawCircle(Vector.zero, 1, 4, LinearColor.white, 1, 1);
});
}
}
}drawLine
• Static drawLine(start, end, color, duration, thickness): void client
绘制线段
Parameters
start Vector | 开始位置 |
|---|---|
end Vector | 结束位置 |
color LinearColor | 颜色 |
duration number | 持续时间 range: 无 type: 浮点型 |
thickness number | 厚度 range: 无 type: 浮点型 |
ts
@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawLine(Vector.zero, Vector.one, LinearColor.white, 1, 1);
});
}
}
}@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawLine(Vector.zero, Vector.one, LinearColor.white, 1, 1);
});
}
}
}drawPoint
• Static drawPoint(position, size, color, duration): void client
绘制点
Parameters
position Vector | 位置 |
|---|---|
size number | 尺寸 range: 无 type: 浮点型 |
color LinearColor | 颜色 |
duration number | 持续时间 range: 无 type: 浮点型 |
ts
@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawPoint(Vector.zero, 1, LinearColor.white, 1);
});
}
}
}@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawPoint(Vector.zero, 1, LinearColor.white, 1);
});
}
}
}drawSphere
• Static drawSphere(center, radius, segments, color, duration, thickness): void client
绘制球体
Parameters
center Vector | 中心位置 |
|---|---|
radius number | 半径 range: 无 type: 浮点型 |
segments number | 段数 range: 无 type: 整形 |
color LinearColor | 颜色 |
duration number | 持续时间 range: 无 type: 浮点型 |
thickness number | 厚度 range: 无 type: 浮点型 |
ts
@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawSphere(Vector.zero, 1, 4, LinearColor.white, 1, 1);
});
}
}
}@Component
export default class SplineExample extends Script {
// 当脚本被实例后,会在第一帧更新前调用此函数
protected async onStart(): Promise<void> {
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
// 绘制点
Spline.drawSphere(Vector.zero, 1, 4, LinearColor.white, 1, 1);
});
}
}
}