Skip to content
IntegratedMover

玩法 / IntegratedMover

IntegratedMover Class

运动器组件

使用示例:创建一个名为"IMExample1"的脚本,放置在对象栏中,打开脚本,输入以下代码保存,运行游戏,你将在场景中看到两个长方体,分别以开启和不开启平滑运动的方式做重复线性运动。代码如下:
ts
@Component
export default class IMExample1 extends Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
      if (SystemUtil.isClient()) {
          // 创建一个长方体
          this.Obj1 = await GameObject.asyncSpawn("197386") as GameObject;
          // 设置起始位置
          this.Obj1.worldTransform.position = new Vector(300.0, -100.0, 300.0);
          // 设置起始缩放
          this.Obj1.worldTransform.scale = new Vector(0.5, 2.0, 0.5);

          // 创建一个运动器,并将运动器挂载到长方体上
          this.IM1 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
          this.IM1.attachToGameObject(this.Obj1);

          // 测试启用状态
          console.log("Enable status: " + this.IM1.enable);
          this.IM1.enable = true;
          console.log("New enable status: " + this.IM1.enable);

          // 添加一个线性运动
          this.IM1.linearSpeed = new Vector(0.0, 100.0, 0.0);
          this.IM1.linearRepeat = true;
          this.IM1.linearRepeatTime = 2.0;
          this.IM1.linearRepeatDelay = 0.0;
          this.IM1.linearReturnDelay = 0.0;

          // 用同样的方式创建第二个长方体与第二个运动器
          this.Obj2 = await GameObject.asyncSpawn("197386") as GameObject;
          this.Obj2.worldTransform.position = new Vector(300.0, -100.0, 150.0);
          this.Obj2.worldTransform.scale = new Vector(0.5, 2.0, 0.5);
          this.IM2 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
          this.IM2.attachToGameObject(this.Obj2);
          this.IM2.enable = true;

          // 给第二个运动器开启平滑运动
          console.log("Smooth status: " + this.IM2.smooth);
          this.IM2.smooth = true;
          console.log("New smooth status: " + this.IM2.smooth);

          // 添加一个同样的线性运动
          this.IM2.linearSpeed = new Vector(0.0, 100.0, 0.0);
          this.IM2.linearRepeat = true;
          this.IM2.linearRepeatTime = 2.0;
          this.IM2.linearRepeatDelay = 0.0;
          this.IM2.linearReturnDelay = 0.0;
      }
  }
}
@Component
export default class IMExample1 extends Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
      if (SystemUtil.isClient()) {
          // 创建一个长方体
          this.Obj1 = await GameObject.asyncSpawn("197386") as GameObject;
          // 设置起始位置
          this.Obj1.worldTransform.position = new Vector(300.0, -100.0, 300.0);
          // 设置起始缩放
          this.Obj1.worldTransform.scale = new Vector(0.5, 2.0, 0.5);

          // 创建一个运动器,并将运动器挂载到长方体上
          this.IM1 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
          this.IM1.attachToGameObject(this.Obj1);

          // 测试启用状态
          console.log("Enable status: " + this.IM1.enable);
          this.IM1.enable = true;
          console.log("New enable status: " + this.IM1.enable);

          // 添加一个线性运动
          this.IM1.linearSpeed = new Vector(0.0, 100.0, 0.0);
          this.IM1.linearRepeat = true;
          this.IM1.linearRepeatTime = 2.0;
          this.IM1.linearRepeatDelay = 0.0;
          this.IM1.linearReturnDelay = 0.0;

          // 用同样的方式创建第二个长方体与第二个运动器
          this.Obj2 = await GameObject.asyncSpawn("197386") as GameObject;
          this.Obj2.worldTransform.position = new Vector(300.0, -100.0, 150.0);
          this.Obj2.worldTransform.scale = new Vector(0.5, 2.0, 0.5);
          this.IM2 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
          this.IM2.attachToGameObject(this.Obj2);
          this.IM2.enable = true;

          // 给第二个运动器开启平滑运动
          console.log("Smooth status: " + this.IM2.smooth);
          this.IM2.smooth = true;
          console.log("New smooth status: " + this.IM2.smooth);

          // 添加一个同样的线性运动
          this.IM2.linearSpeed = new Vector(0.0, 100.0, 0.0);
          this.IM2.linearRepeat = true;
          this.IM2.linearRepeatTime = 2.0;
          this.IM2.linearRepeatDelay = 0.0;
          this.IM2.linearReturnDelay = 0.0;
      }
  }
}

Hierarchy

Table of contents

Properties

onLinearEnable: MulticastDelegate<() => void>
平移运动首次延迟启动时回调,延迟启动时间为0时表现不启用,无法获得回调事件
onLinearReturn: MulticastDelegate<() => void>
平移运动到达终点停顿时回调,到达后停顿时间为0时表现不启用,无法获得回调事件
onLinearStart: MulticastDelegate<() => void>
平移运动返回起点停顿时回调,到返程后停顿时间为0时表现不启用,无法获得回调事件
onRotationEnable: MulticastDelegate<() => void>
旋转运动首次延迟启动时回调,延迟启动时间为0时表现不启用,无法获得回调事件
onRotationReturn: MulticastDelegate<() => void>
旋转运动到达终点停顿时回调,到达后停顿时间为0时表现不启用,无法获得回调事件
onRotationStart: MulticastDelegate<() => void>
旋转运动返回起点停顿时回调,到返程后停顿时间为0时表现不启用,无法获得回调事件
onScaleEnable: MulticastDelegate<() => void>
缩放运动首次延迟启动时回调,延迟启动时间为0时表现不启用,无法获得回调事件
onScaleReturn: MulticastDelegate<() => void>
缩放运动到达终点停顿时回调,到达后停顿时间为0时表现不启用,无法获得回调事件
onScaleStart: MulticastDelegate<() => void>
缩放运动返回起点停顿时回调,到返程后停顿时间为0时表现不启用,无法获得回调事件
onSwingEnable: MulticastDelegate<() => void>
摆动:延迟启动回调
click

Properties

onBeforeDestroyDelegate: MulticastDelegate<() => void>
物体销毁前事件回调
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
监听自定义属性同步事件
onDestroyDelegate: MulticastDelegate<() => void>
物体销毁后事件回调
onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>
监听系统属性同步事件

Accessors

enable(): boolean
获取启用状态
linearDelayStartTime(): number
获取延时启动平移运行时间
linearRepeat(): boolean
获取平移重复运动状态
linearRepeatDelay(): number
获取平移到达后停顿时间
linearRepeatTime(): number
获取平移单程运动时间
linearReturnDelay(): number
获取平移返程后停顿时间
linearSpeed(): Vector
获取平移速度大小
motionCoordinate(): MotionAxis
获取运动坐标系
motionMode(): MotionMode
获取运动模式
rotationDelayStartTime(): number
获取延时启动旋转运行时间
rotationRepeat(): boolean
获取旋转重复运动状态
rotationRepeatDelay(): number
获取旋转到达后停顿时间
rotationRepeatTime(): number
获取旋转单程运动时间
rotationReturnDelay(): number
获取旋转返程后停顿时间
rotationSpeed(): Vector
获取旋转速度大小
scaleDelayStartTime(): number
获取延时启动缩放运行时间
scaleRepeat(): boolean
获取缩放重复运动状态
scaleRepeatDelay(): number
获取缩放到达后停顿时间
scaleRepeatTime(): number
获取缩放单程运动时间
scaleReturnDelay(): number
获取缩放返程后停顿时间
scaleSpeed(): Vector
获取缩放速度大小
smooth(): boolean
获取平滑状态
swingAngle(): number
获取摆动最大角度
swingDelayStartTime(): number
获取延时启动摆动运行时间
swingSpeed(): Vector
获取摆动运动速度
click

Accessors

assetId(): string
获取当前物体使用资源的GUID
gameObjectId(): string
获取物体的唯一标识(唯一标识一个对象的字符串)。
isDestroyed(): boolean
当前物体是否被销毁
isReady(): boolean
当前物体状态
localTransform(): Transform
当前物体本地变换
name(): string
返回当前物体名称
netStatus(): NetStatus
获取当前物体同步状态
parent(): GameObject
获取当前父物体
tag(): string
获取当前物体的标签
worldTransform(): Transform
当前物体世界变换

Methods

moverReset(OnReset?: () => void): void
将运动器状态重置,运动对象同时回到初始位置
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[]
获取子物体
getChildrenBoundingBoxCenter(outer?: Vector): Vector
获取所有子对象包围盒中心点(不包含父对象,父对象不可用返回[0,0,0])
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>> other
给定对象属性修改时触发的事件代理
getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
给定对象属性修改时触发的事件代理
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
设置自定义属性
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>>
异步构造一个物体
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>
构造一个物体

Properties


onLinearEnable

onLinearEnable: MulticastDelegate<() => void>

平移运动首次延迟启动时回调,延迟启动时间为0时表现不启用,无法获得回调事件


onLinearReturn

onLinearReturn: MulticastDelegate<() => void>

平移运动到达终点停顿时回调,到达后停顿时间为0时表现不启用,无法获得回调事件


onLinearStart

onLinearStart: MulticastDelegate<() => void>

平移运动返回起点停顿时回调,到返程后停顿时间为0时表现不启用,无法获得回调事件


onRotationEnable

onRotationEnable: MulticastDelegate<() => void>

旋转运动首次延迟启动时回调,延迟启动时间为0时表现不启用,无法获得回调事件


onRotationReturn

onRotationReturn: MulticastDelegate<() => void>

旋转运动到达终点停顿时回调,到达后停顿时间为0时表现不启用,无法获得回调事件


onRotationStart

onRotationStart: MulticastDelegate<() => void>

旋转运动返回起点停顿时回调,到返程后停顿时间为0时表现不启用,无法获得回调事件


onScaleEnable

onScaleEnable: MulticastDelegate<() => void>

缩放运动首次延迟启动时回调,延迟启动时间为0时表现不启用,无法获得回调事件


onScaleReturn

onScaleReturn: MulticastDelegate<() => void>

缩放运动到达终点停顿时回调,到达后停顿时间为0时表现不启用,无法获得回调事件


onScaleStart

onScaleStart: MulticastDelegate<() => void>

缩放运动返回起点停顿时回调,到返程后停顿时间为0时表现不启用,无法获得回调事件


onSwingEnable

onSwingEnable: MulticastDelegate<() => void>

摆动:延迟启动回调

Accessors


enable

get enable(): boolean

set enable(newEnable): void

获取启用状态

Returns

boolean启用状态

设置启用状态

Parameters

newEnable boolean启用状态

linearDelayStartTime

get linearDelayStartTime(): number

set linearDelayStartTime(newDelay): void

获取延时启动平移运行时间

Returns

number延时启动时间

设置延时启动平移运动时间

Parameters

newDelay number延时启动时间

linearRepeat

get linearRepeat(): boolean

set linearRepeat(newRepeat): void

获取平移重复运动状态

Returns

boolean平移重复运动状态

设置平移重复运动状态

Parameters

newRepeat boolean平移重复运动状态

linearRepeatDelay

get linearRepeatDelay(): number

set linearRepeatDelay(newDelay): void

获取平移到达后停顿时间

Returns

number平移到达后停顿时间

设置平移到达后停顿时间,该属性需要重复运动状态为true时才会生效

Parameters

newDelay number平移到达后停顿时间

linearRepeatTime

get linearRepeatTime(): number

set linearRepeatTime(newTime): void

获取平移单程运动时间

Returns

number平移单程运动时间

设置平移单程运动时间,该属性需要重复运动状态为true时才会生效

Parameters

newTime number平移单程运动时间

linearReturnDelay

get linearReturnDelay(): number

set linearReturnDelay(newDelay): void

获取平移返程后停顿时间

Returns

number平移返程后停顿时间

设置平移返程后停顿时间,该属性需要重复运动状态为true时才会生效

Parameters

newDelaynumber

平移返程后停顿时间


linearSpeed

get linearSpeed(): Vector

set linearSpeed(newSpeed): void

获取平移速度大小

Returns

Vector平移速度大小

设置平移速度大小

Parameters

newSpeed Vector平移速度大小
使用示例:创建一个名为"IMExample2"的脚本,放置在对象栏中,打开脚本,输入以下代码保存,运行游戏,你将在场景中看到两个长方体,分别演示有无延迟启动的非重复线性运动,以及有无起点终点停顿的重复线性运动。代码如下:
ts
@Component
export default class IMExample2 extends Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await GameObject.asyncSpawn( "197386") as GameObject;
            this.Obj2 = await GameObject.asyncSpawn("197386") as GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new Vector(300.0, 0.0, 300.0);
            this.Obj2.worldTransform.position = new Vector(300.0, 0.0, 150.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new Vector(0.5, 2.0, 0.5);
            this.Obj2.worldTransform.scale = new Vector(0.5, 2.0, 0.5);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的运动速度,运动器2设置延迟五秒启动
            this.IM1.linearSpeed = new Vector(0.0, 100.0, 0.0);
            this.IM1.linearRepeat = false;
            this.IM1.linearDelayStartTime = 0.0;

            this.IM2.linearSpeed = new Vector(0.0, 100.0, 0.0);
            this.IM2.linearRepeat = false;
            this.IM2.linearDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onLinearEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })

            // 等待十秒后,将长方体1和2归位,重新设置运动器1和2,让它们变成重复运动模式,且运动器2在起点和终点设置两秒延迟
            setTimeout(() => {
                this.IM1.moverReset();
                this.IM2.moverReset();

                this.IM1.linearRepeat = true;
                this.IM1.linearRepeatTime = 2.0;
                this.IM1.linearDelayStartTime = 0.0;
                this.IM1.linearRepeatDelay = 0.0;
                this.IM1.linearReturnDelay = 0.0;

                this.IM2.linearRepeat = true;
                this.IM2.linearRepeatTime = 2.0;
                this.IM2.linearDelayStartTime = 0.0;
                this.IM2.linearRepeatDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onLinearReturn.add(() => {
                    console.log("IM2 paused at end point");
                })
                this.IM2.linearReturnDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onLinearStart.add(() => {
                    console.log("IM2 paused at start point");
                })
            }, 10000);
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}
@Component
export default class IMExample2 extends Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await GameObject.asyncSpawn( "197386") as GameObject;
            this.Obj2 = await GameObject.asyncSpawn("197386") as GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new Vector(300.0, 0.0, 300.0);
            this.Obj2.worldTransform.position = new Vector(300.0, 0.0, 150.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new Vector(0.5, 2.0, 0.5);
            this.Obj2.worldTransform.scale = new Vector(0.5, 2.0, 0.5);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await GameObject.asyncSpawn("PhysicsSports") as IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的运动速度,运动器2设置延迟五秒启动
            this.IM1.linearSpeed = new Vector(0.0, 100.0, 0.0);
            this.IM1.linearRepeat = false;
            this.IM1.linearDelayStartTime = 0.0;

            this.IM2.linearSpeed = new Vector(0.0, 100.0, 0.0);
            this.IM2.linearRepeat = false;
            this.IM2.linearDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onLinearEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })

            // 等待十秒后,将长方体1和2归位,重新设置运动器1和2,让它们变成重复运动模式,且运动器2在起点和终点设置两秒延迟
            setTimeout(() => {
                this.IM1.moverReset();
                this.IM2.moverReset();

                this.IM1.linearRepeat = true;
                this.IM1.linearRepeatTime = 2.0;
                this.IM1.linearDelayStartTime = 0.0;
                this.IM1.linearRepeatDelay = 0.0;
                this.IM1.linearReturnDelay = 0.0;

                this.IM2.linearRepeat = true;
                this.IM2.linearRepeatTime = 2.0;
                this.IM2.linearDelayStartTime = 0.0;
                this.IM2.linearRepeatDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onLinearReturn.add(() => {
                    console.log("IM2 paused at end point");
                })
                this.IM2.linearReturnDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onLinearStart.add(() => {
                    console.log("IM2 paused at start point");
                })
            }, 10000);
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}

motionCoordinate

get motionCoordinate(): MotionAxis

set motionCoordinate(newMotionCoordinate): void

获取运动坐标系

Returns

MotionAxis运动坐标系

设置运动坐标系

Parameters

newMotionCoordinate MotionAxis运动坐标系

motionMode

get motionMode(): MotionMode

set motionMode(mode): void

获取运动模式

Returns

MotionMode运动器运动模式

设置运动模式

Parameters

mode MotionMode运动器运动模式

rotationDelayStartTime

get rotationDelayStartTime(): number

set rotationDelayStartTime(newDelay): void

获取延时启动旋转运行时间

Returns

number延时启动时间

设置延时启动旋转运动时间

Parameters

newDelay number延时启动时间

rotationRepeat

get rotationRepeat(): boolean

set rotationRepeat(newRepeat): void

获取旋转重复运动状态

Returns

boolean旋转重复运动状态

设置旋转重复运动状态

Parameters

newRepeat boolean旋转重复运动状态

rotationRepeatDelay

get rotationRepeatDelay(): number

set rotationRepeatDelay(newDelay): void

获取旋转到达后停顿时间

Returns

number旋转到达后停顿时间

设置旋转到达后停顿时间

该属性需要重复运动状态为 true 时才会生效

Parameters

newDelay number旋转到达后停顿时间 range: (0, +∞) type:浮点数

rotationRepeatTime

get rotationRepeatTime(): number

set rotationRepeatTime(newTime): void

获取旋转单程运动时间

Returns

number旋转单程运动时间

设置旋转单程运动时间

该属性需要重复运动状态为 true 时才会生效。

Parameters

newTime number旋转单程运动时间。range: (0, +∞) type:浮点数

rotationReturnDelay

get rotationReturnDelay(): number

set rotationReturnDelay(newDelay): void

获取旋转返程后停顿时间

Returns

number返程后停顿时间

设置旋转返程后停顿时间,该属性需要重复运动状态为true时才会生效

Parameters

newDelay number返程后停顿时间 range: (0, +∞) type:浮点数

rotationSpeed

get rotationSpeed(): Vector

set rotationSpeed(newSpeed): void

获取旋转速度大小

Returns

Vector旋转速度大小

设置旋转速度大小

Parameters

newSpeed Vector旋转速度大小
使用示例:创建一个名为"IMExample3"的脚本,放置在对象栏中,打开脚本,输入以下代码保存,运行游戏,你将在场景中看到两个长方体,分别演示有无延迟启动的非重复旋转,以及有无起点终点停顿的重复旋转。代码如下:
ts
@Component
export default class IMExample3 extends mw.Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (Util.SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            this.Obj2 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new mw.Vector(300.0, 200.0, 200.0);
            this.Obj2.worldTransform.position = new mw.Vector(300.0, -200.0, 200.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);
            this.Obj2.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的旋转速度,运动器2设置延迟五秒启动
            this.IM1.rotationSpeed = new mw.Vector(90.0, 0.0, 0.0);
            this.IM1.rotationRepeat = false;
            this.IM1.rotationDelayStartTime = 0.0;

            this.IM2.rotationSpeed = new mw.Vector(90.0, 0.0, 0.0);
            this.IM2.rotationRepeat = false;
            this.IM2.rotationDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onRotationEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })

            // 等待十秒后,将长方体1和2归位,重新设置运动器1和2,让它们变成重复运动模式,且运动器2在起点和终点设置两秒延迟
            setTimeout(() => {
                this.IM1.moverReset();
                this.IM2.moverReset();

                this.IM1.rotationRepeat = true;
                this.IM1.rotationRepeatTime = 2.0;
                this.IM1.rotationDelayStartTime = 0.0;
                this.IM1.rotationRepeatDelay = 0.0;
                this.IM1.rotationReturnDelay = 0.0;

                this.IM2.rotationRepeat = true;
                this.IM2.rotationRepeatTime = 2.0;
                this.IM2.rotationDelayStartTime = 0.0;
                this.IM2.rotationRepeatDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onRotationReturn.add(() => {
                    console.log("IM2 paused at end point");
                })
                this.IM2.rotationReturnDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onRotationStart.add(() => {
                    console.log("IM2 paused at start point");
                })
            }, 10000);
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}
@Component
export default class IMExample3 extends mw.Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (Util.SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            this.Obj2 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new mw.Vector(300.0, 200.0, 200.0);
            this.Obj2.worldTransform.position = new mw.Vector(300.0, -200.0, 200.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);
            this.Obj2.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的旋转速度,运动器2设置延迟五秒启动
            this.IM1.rotationSpeed = new mw.Vector(90.0, 0.0, 0.0);
            this.IM1.rotationRepeat = false;
            this.IM1.rotationDelayStartTime = 0.0;

            this.IM2.rotationSpeed = new mw.Vector(90.0, 0.0, 0.0);
            this.IM2.rotationRepeat = false;
            this.IM2.rotationDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onRotationEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })

            // 等待十秒后,将长方体1和2归位,重新设置运动器1和2,让它们变成重复运动模式,且运动器2在起点和终点设置两秒延迟
            setTimeout(() => {
                this.IM1.moverReset();
                this.IM2.moverReset();

                this.IM1.rotationRepeat = true;
                this.IM1.rotationRepeatTime = 2.0;
                this.IM1.rotationDelayStartTime = 0.0;
                this.IM1.rotationRepeatDelay = 0.0;
                this.IM1.rotationReturnDelay = 0.0;

                this.IM2.rotationRepeat = true;
                this.IM2.rotationRepeatTime = 2.0;
                this.IM2.rotationDelayStartTime = 0.0;
                this.IM2.rotationRepeatDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onRotationReturn.add(() => {
                    console.log("IM2 paused at end point");
                })
                this.IM2.rotationReturnDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onRotationStart.add(() => {
                    console.log("IM2 paused at start point");
                })
            }, 10000);
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}

scaleDelayStartTime

get scaleDelayStartTime(): number

set scaleDelayStartTime(newDelay): void

获取延时启动缩放运行时间

Returns

number延时启动时间

设置延时启动缩放运动时间

Parameters

newDelay number延时启动时间 range: (0, +∞) type:浮点数

scaleRepeat

get scaleRepeat(): boolean

set scaleRepeat(newRepeat): void

获取缩放重复运动状态

Returns

boolean重复运动状态

设置缩放重复运动状态

Parameters

newRepeat boolean重复运动状态

scaleRepeatDelay

get scaleRepeatDelay(): number

set scaleRepeatDelay(newDelay): void

获取缩放到达后停顿时间

Returns

number到达后停顿时间

设置缩放到达后停顿时间,该属性需要重复运动状态为true时才会生效

Parameters

newDelay number到达后停顿时间 range: (0, +∞) type:浮点数

scaleRepeatTime

get scaleRepeatTime(): number

set scaleRepeatTime(newTime): void

获取缩放单程运动时间

Returns

number单程运动时间

设置缩放单程运动时间,该属性需要重复运动状态为true时才会生效

Parameters

newTime number单程运动时间 range: (0, +∞) type:浮点数

scaleReturnDelay

get scaleReturnDelay(): number

set scaleReturnDelay(newDelay): void

获取缩放返程后停顿时间

Returns

number返程后停顿时间

设置缩放返程后停顿时间,该属性需要重复运动状态为true时才会生效

Parameters

newDelay number返程后停顿时间 range: (0, +∞) type:浮点数

scaleSpeed

get scaleSpeed(): Vector

set scaleSpeed(newSpeed): void

获取缩放速度大小

Returns

Vector缩放速度大小

设置缩放速度大小

Parameters

newSpeed Vector缩放速度大小
使用示例:创建一个名为"IMExample4"的脚本,放置在对象栏中,打开脚本,输入以下代码保存,运行游戏,你将在场景中看到两个正方体,分别演示有无延迟启动的非重复缩放,以及有无起点终点停顿的重复缩放。代码如下:
ts
@Component
export default class IMExample4 extends mw.Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (Util.SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            this.Obj2 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new mw.Vector(300.0, 200.0, 200.0);
            this.Obj2.worldTransform.position = new mw.Vector(300.0, -200.0, 200.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new mw.Vector(1.0, 1.0, 1.0);
            this.Obj2.worldTransform.scale = new mw.Vector(1.0, 1.0, 1.0);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的缩放速度,运动器2设置延迟五秒启动
            this.IM1.scaleSpeed = new mw.Vector(-0.1, -0.1, -0.1);
            this.IM1.scaleRepeat = false;
            this.IM1.scaleDelayStartTime = 0.0;

            this.IM2.scaleSpeed = new mw.Vector(-0.1, -0.1, -0.1);
            this.IM2.scaleRepeat = false;
            this.IM2.scaleDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onScaleEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })

            // 等待十秒后,将长方体1和2归位,重新设置运动器1和2,让它们变成重复运动模式,且运动器2在起点和终点设置两秒延迟
            setTimeout(() => {
                this.IM1.moverReset();
                this.IM2.moverReset();

                this.IM1.scaleRepeat = true;
                this.IM1.scaleRepeatTime = 2.0;
                this.IM1.scaleDelayStartTime = 0.0;
                this.IM1.scaleRepeatDelay = 0.0;
                this.IM1.scaleReturnDelay = 0.0;

                this.IM2.scaleRepeat = true;
                this.IM2.scaleRepeatTime = 2.0;
                this.IM2.scaleDelayStartTime = 0.0;
                this.IM2.scaleRepeatDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onScaleReturn.add(() => {
                    console.log("IM2 paused at end point");
                })
                this.IM2.scaleReturnDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onScaleStart.add(() => {
                    console.log("IM2 paused at start point");
                })
            }, 10000);
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}
@Component
export default class IMExample4 extends mw.Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (Util.SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            this.Obj2 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new mw.Vector(300.0, 200.0, 200.0);
            this.Obj2.worldTransform.position = new mw.Vector(300.0, -200.0, 200.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new mw.Vector(1.0, 1.0, 1.0);
            this.Obj2.worldTransform.scale = new mw.Vector(1.0, 1.0, 1.0);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的缩放速度,运动器2设置延迟五秒启动
            this.IM1.scaleSpeed = new mw.Vector(-0.1, -0.1, -0.1);
            this.IM1.scaleRepeat = false;
            this.IM1.scaleDelayStartTime = 0.0;

            this.IM2.scaleSpeed = new mw.Vector(-0.1, -0.1, -0.1);
            this.IM2.scaleRepeat = false;
            this.IM2.scaleDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onScaleEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })

            // 等待十秒后,将长方体1和2归位,重新设置运动器1和2,让它们变成重复运动模式,且运动器2在起点和终点设置两秒延迟
            setTimeout(() => {
                this.IM1.moverReset();
                this.IM2.moverReset();

                this.IM1.scaleRepeat = true;
                this.IM1.scaleRepeatTime = 2.0;
                this.IM1.scaleDelayStartTime = 0.0;
                this.IM1.scaleRepeatDelay = 0.0;
                this.IM1.scaleReturnDelay = 0.0;

                this.IM2.scaleRepeat = true;
                this.IM2.scaleRepeatTime = 2.0;
                this.IM2.scaleDelayStartTime = 0.0;
                this.IM2.scaleRepeatDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onScaleReturn.add(() => {
                    console.log("IM2 paused at end point");
                })
                this.IM2.scaleReturnDelay = 2.0;
                // 运动器2绑定终点停顿回调
                this.IM2.onScaleStart.add(() => {
                    console.log("IM2 paused at start point");
                })
            }, 10000);
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}

smooth

get smooth(): boolean

set smooth(newSmooth): void

获取平滑状态

Returns

boolean平滑状态

设置平滑状态,启用后运动速度会由慢逐渐加快,直到最大值

Parameters

newSmooth boolean平滑状态

swingAngle

get swingAngle(): number

set swingAngle(newAngle): void

获取摆动最大角度

Returns

number摆动最大角度

设置摆动最大角度

Parameters

newAngle number摆动最大角度 range: (0, +∞) type:浮点数

swingDelayStartTime

get swingDelayStartTime(): number

set swingDelayStartTime(newDelay): void

获取延时启动摆动运行时间

Returns

number延时启动时间

设置延时启动摆动运动时间

Parameters

newDelay number延时启动时间 range: (0, +∞) type:浮点数

swingSpeed

get swingSpeed(): Vector

set swingSpeed(newSpeed): void

获取摆动运动速度

Returns

Vector摆动运动速度

设置摆动运动速度

Parameters

newSpeed Vector摆动运动速度
使用示例:创建一个名为"IMExample5"的脚本,放置在对象栏中,打开脚本,输入以下代码保存,运行游戏,你将在场景中看到两个长方体,分别演示有无延迟启动的单摆运动。代码如下:
ts
@Component
export default class IMExample5 extends mw.Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (Util.SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            this.Obj2 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new mw.Vector(300.0, 200.0, 200.0);
            this.Obj2.worldTransform.position = new mw.Vector(300.0, -200.0, 200.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);
            this.Obj2.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的单摆速度和角度,运动器2设置延迟五秒启动
            this.IM1.swingSpeed = new mw.Vector(1.0, 0.0, 0.0);
            this.IM1.swingAngle = 90.0;
            this.IM1.swingDelayStartTime = 0.0;

            this.IM2.swingSpeed = new mw.Vector(1.0, 0.0, 0.0);
            this.IM2.swingAngle = 90.0;
            this.IM2.swingDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onSwingEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}
@Component
export default class IMExample5 extends mw.Script {

    // 声明变量
    Obj1;
    Obj2;
    IM1;
    IM2;

    // 当脚本被实例后,会在第一帧更新前调用此函数
    protected async onStart(): `Promise`<`void`\> {
        if (Util.SystemUtil.isClient()) {
            // 创建长方体1和长方体2
            this.Obj1 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            this.Obj2 = await mw.GameObject.asyncSpawn("197386") as mw.GameObject;
            // 设置起始位置
            this.Obj1.worldTransform.position = new mw.Vector(300.0, 200.0, 200.0);
            this.Obj2.worldTransform.position = new mw.Vector(300.0, -200.0, 200.0);
            // 设置起始缩放
            this.Obj1.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);
            this.Obj2.worldTransform.scale = new mw.Vector(0.5, 2.0, 0.5);

            // 创建运动器1和运动器2,并将运动器挂载到对应长方体上
            this.IM1 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM1.attachToGameObject(this.Obj1);
            this.IM1.enable = true;

            this.IM2 = await mw.GameObject.asyncSpawn("PhysicsSports") as mw.IntegratedMover;
            this.IM2.attachToGameObject(this.Obj2);
            this.IM2.enable = true;

            // 运动器1和2都设置同样的单摆速度和角度,运动器2设置延迟五秒启动
            this.IM1.swingSpeed = new mw.Vector(1.0, 0.0, 0.0);
            this.IM1.swingAngle = 90.0;
            this.IM1.swingDelayStartTime = 0.0;

            this.IM2.swingSpeed = new mw.Vector(1.0, 0.0, 0.0);
            this.IM2.swingAngle = 90.0;
            this.IM2.swingDelayStartTime = 5.0;
            // 运动器2绑定延迟启动回调
            this.IM2.onSwingEnable.add(() => {
                console.log("IM2 enabled with a delay");
            })
        }
    }

    //
    // 周期函数 每帧执行
    // 此函数执行需要将this.useUpdate赋值为true
    // @param dt 当前帧与上一帧的延迟 / 秒
    protected onUpdate(dt: number): void {

    }

    // 脚本被销毁时最后一帧执行完调用此函数
    protected onDestroy(): void {

    }
}

Methods


moverReset

moverReset(OnReset?): void

将运动器状态重置,运动对象同时回到初始位置

Parameters

OnReset? () => void执行回调 default:null