Gameplay / Interactor
Interactor Class
Interactive objects, please ensure that animation asset have been loaded before interaction, otherwise position errors or other unexpected performance may result
Usage example: create a script named "InteractorSample", place it in a child of a interactor in the object manager, open the script, enter the following code to save it, search for 4175 animation asset in the local asset library, and drag it into the priority loading directory in the object manager. Running the game, you will see the effect of an interactive object in the scene, and players can interact with this interactive object. The code is as follows:
@Component
export default class InteractorSample extends Script {
protected async onStart(): Promise<void> {
const interObj = this.gameObject as Interactor;
// Start interactive callback
interObj.onEnter.add(() => {
console.log("onEnter")
console.log("onEnter ", interObj.getCurrentCharacter())
console.log("onEnter ", interObj.occupied)
})
interObj.slot = HumanoidSlotType.Buttocks;
interObj.animationId = "4175";
// End interaction callback
interObj.onLeave.add(() => {
console.log("onLeave")
})
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
interObj.enter(Player.localPlayer.character, HumanoidSlotType.Buttocks, "4175");
})
InputUtil.onKeyDown(Keys.Two, () => {
// When exiting the interaction without transmission, it will automatically return to the coordinates and rotation before the interaction
interObj.leave();
})
}
}
}
@Component
export default class InteractorSample extends Script {
protected async onStart(): Promise<void> {
const interObj = this.gameObject as Interactor;
// Start interactive callback
interObj.onEnter.add(() => {
console.log("onEnter")
console.log("onEnter ", interObj.getCurrentCharacter())
console.log("onEnter ", interObj.occupied)
})
interObj.slot = HumanoidSlotType.Buttocks;
interObj.animationId = "4175";
// End interaction callback
interObj.onLeave.add(() => {
console.log("onLeave")
})
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
interObj.enter(Player.localPlayer.character, HumanoidSlotType.Buttocks, "4175");
})
InputUtil.onKeyDown(Keys.Two, () => {
// When exiting the interaction without transmission, it will automatically return to the coordinates and rotation before the interaction
interObj.leave();
})
}
}
}
Hierarchy
↳
Interactor
Table of contents
Properties
onEnter: MulticastDelegate <() => void > |
---|
Execute binding function at the beginning of interaction. It is usually used in pairs with enter. See the example code in the method enter for usage example. |
onLeave: MulticastDelegate <() => void > |
Execute the binding function at the end of the interaction. It is usually used in pairs with leave. See the example code in the method leave for usage example. |
click
Properties
onBeforeDestroyDelegate: MulticastDelegate <() => void > other |
---|
Event callback before object destruction |
onCustomPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Monitor custom attribute synchronization events |
onDestroyDelegate: MulticastDelegate <() => void > other |
Event callback after object destruction |
onPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> |
Monitor system replicated events |
Accessors
animationId(): string |
---|
Interactive animation asset id |
nonHumanoidAnimationId(): string |
Interactive non human animation asset id |
nonHumanoidSlot(): NonHumanoidSlotType |
Interactive object non humanoid slot |
occupied(): boolean |
The interaction state of the interactor |
slot(): HumanoidSlotType |
Interactive slot |
click
Accessors
actorFlagValue(): number other |
---|
Get object tags |
actorLevel(): number other |
Obtain Actor Level |
assetId(): string other |
Retrieve the UID of the resource currently being used by the object |
gameObjectId(): string other |
Get the unique identification of an object (a string that uniquely identifies an object). |
isDestroyed(): boolean other |
Has the current object been destroyed |
isReady(): boolean other |
Current object status |
localTransform(): Transform other |
Local transformation of the current object |
name(): string other |
Return the current object name |
netStatus(): NetStatus other |
Get the current object synchronization status |
parent(): GameObject other |
Retrieve the current parent object |
tag(): string other |
Get the tag of the current object |
worldTransform(): Transform other |
Current object world transformation |
Methods
enter(character : Character , slot? : NonHumanoidSlotType HumanoidSlotType , animationId? : string ): boolean other |
---|
When starting interaction, please ensure that the animation asset have been loaded before interaction, otherwise it may lead to position errors or other unexpected performance |
getCurrentCharacter(): Character other |
Get the character being interacted |
leave(position? : Vector , rotation? : Rotation , animationId? : string ): boolean other |
End interaction. It is usually used in pairs with enter. See the example code in the method enter for usage example. |
click
Methods
addComponent<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >, bInReplicates? : boolean ): T : extends Script <T > other |
---|
Add a script component |
asyncGetChildByName(name : string ): Promise <GameObject > other |
Asynchronous search for sub objects based on their names |
asyncReady(): Promise <GameObject > other |
Return after the object is ready |
clone(gameObjectInfo? : GameObjectInfo ): GameObject other |
Copy Objects |
destroy(): void other |
delete object |
getBoundingBox(nonColliding? : boolean , includeFromChild? : boolean , outer? : Vector ): Vector other |
Get the size of the object's bounding box |
getBounds(onlyCollidingComponents : boolean , originOuter : Vector , boxExtentOuter : Vector , includeFromChild? : boolean ): void other |
Obtain object boundaries |
getChildByGameObjectId(gameObjectId : string ): GameObject other |
Search for sub objects based on gameObjectid |
getChildByName(name : string ): GameObject other |
Search for sub objects by name |
getChildByPath(path : string ): GameObject other |
Find sub objects according to path |
getChildren(): GameObject [] other |
Obtain sub objects |
getChildrenBoundingBoxCenter(outer? : Vector ): Vector other |
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0]) |
getChildrenByName(name : string ): GameObject [] other |
Search for all sub objects by name |
getComponent<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T > other |
Get the component of the specified type |
getComponentPropertys<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >): Map <string , IPropertyOptions > other |
Get property of script component |
getComponents<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T >[] other |
Get all component of the specified type |
getCustomProperties(): string [] other |
Get all customize property |
getCustomProperty<T : extends CustomPropertyType >(propertyName : string ): T : extends CustomPropertyType other |
Get customize property |
getCustomPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Event proxy triggered when a given object property is modified |
getPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Event proxy triggered when a given object property is modified |
getVisibility(): boolean other |
Obtain whether the object is displayed |
isPrefabActor(): boolean other |
Return whether the current object is a prefabricated body |
moveBy(velocity : Vector , isLocal? : boolean ): void other |
Smoothly move an object over time according to a given velocity vector |
moveTo(targetPosition : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly move from the current position to the target position within the specified time |
rotateBy(rotation : Quaternion Rotation , multiplier : number , isLocal? : boolean ): void other |
Rotate the object smoothly over time according to the given rotation amount |
rotateTo(targetRotation : Quaternion Rotation , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly changes from the current rotation to the target rotation within the specified time |
scaleBy(scale : Vector , isLocal? : boolean ): void other |
Smoothly scale objects over time using a given scaling vector per second |
scaleTo(targetScale : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly changes from the current scale to the target scale within the specified time |
setAbsolute(absolutePosition? : boolean , absoluteRotation? : boolean , absoluteScale? : boolean ): void other |
Set whether the object localTransform is relative to the parent object or the world |
setCustomProperty(propertyName : string , value : undefined CustomPropertyType ): void other |
Set custom attributes |
setVisibility(status : boolean PropertyStatus , propagateToChildren? : boolean ): void other |
Set whether the object is displayed |
stopMove(): void other |
Interrupt further movement of moveTo() and moveBy() |
stopRotate(): void other |
Interrupt further rotation from rotateTo() or rotateBy() |
stopScale(): void other |
Interrupt further scale from ScaleTo() or ScaleBy() |
asyncFindGameObjectById(gameObjectId : string ): Promise <GameObject > other |
Asynchronous search for GameObject through gameObjectid |
asyncGetGameObjectByPath(path : string ): Promise <GameObject > other |
Asynchronously find objects through path |
asyncSpawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): Promise <T : extends GameObject <T >> other |
Asynchronous construction of an object |
bulkPivotTo(gameObjects : GameObject [], transforms : Transform []): void other |
Batch set position |
findGameObjectById(gameObjectId : string ): GameObject other |
Search for objects through gameObjectid |
findGameObjectByName(name : string ): GameObject other |
Search for objects by name |
findGameObjectsByName(name : string ): GameObject [] other |
Search for objects by name |
findGameObjectsByTag(tag : string ): GameObject [] other |
Get objects through customize tag |
getGameObjectByPath(path : string ): GameObject other |
Search for objects through paths |
spawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): T : extends GameObject <T > other |
Construct an object |
Properties
onEnter
• onEnter: MulticastDelegate
<() => void
>
Execute binding function at the beginning of interaction. It is usually used in pairs with enter. See the example code in the method enter for usage example.
Precautions
It will be broadcast automatically. If it is a double ended object, it can be call on any client
onLeave
• onLeave: MulticastDelegate
<() => void
>
Execute the binding function at the end of the interaction. It is usually used in pairs with leave. See the example code in the method leave for usage example.
Precautions
It will be broadcast automatically. If it is a double ended object, it can be call on any client
Accessors
animationId
• | • | ||||
---|---|---|---|---|---|
Interactive animation asset id Returns
| Interactive animation asset id Parameters
|
nonHumanoidAnimationId
• | • | ||||
---|---|---|---|---|---|
Interactive non human animation asset id Returns
| Interactive non human animation asset id Parameters
|
nonHumanoidSlot
• | • | ||||
---|---|---|---|---|---|
Interactive object non humanoid slot Returns
| Interactive object non humanoid slot Parameters
|
occupied
• | ||
---|---|---|
The interaction state of the interactor Returns
|
slot
• | • | ||||
---|---|---|---|---|---|
Interactive slot Returns
| Interactive slot Parameters
|
Methods
enter
• enter(character
, slot?
, animationId?
): boolean
other
When starting interaction, please ensure that the animation asset have been loaded before interaction, otherwise it may lead to position errors or other unexpected performance
Parameters
character Character | Character to be interacted (either Player or AI) |
---|---|
slot? NonHumanoidSlotType HumanoidSlotType | Interactive slot, default to attribute slot without transmission. default: attribute slot |
animationId? string | Interactive posture, default based on attribute animationId, default: attribute animationId range: determines string length based on animation resource ID |
Returns
boolean | Whether the interaction is successful, asynchronous logic, and the return value do not mean that the interaction has been completed. To ensure that the interaction has been completed, please use onEnter delegate |
---|
Example usage: Create a script called "InteractorStartEndSample" and place it in a child level of an interaction object in the object manager. Open the script, enter the following code to save it, run the game, and you will see the effect of an interaction object in the scene. Players can interact with this interaction object. The code is as follows:
@Component
export default class InteractorStartEndSample extends Script {
protected async onStart(): Promise<void> {
const interObj = this.gameObject as Interactor;
// Start interactive callback
interObj.onEnter.add(() => {
console.log("onEnter")
})
// End interaction callback
interObj.onLeave.add(() => {
console.log("onLeave")
})
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
interObj.enter(Player.localPlayer.character, HumanoidSlotType.Buttocks, "4175");
})
InputUtil.onKeyDown(Keys.Two, () => {
// When exiting the interaction without transmission, it will automatically return to the coordinates and rotation before the interaction
interObj.leave();
})
}
}
}
@Component
export default class InteractorStartEndSample extends Script {
protected async onStart(): Promise<void> {
const interObj = this.gameObject as Interactor;
// Start interactive callback
interObj.onEnter.add(() => {
console.log("onEnter")
})
// End interaction callback
interObj.onLeave.add(() => {
console.log("onLeave")
})
if (SystemUtil.isClient()) {
InputUtil.onKeyDown(Keys.One, () => {
interObj.enter(Player.localPlayer.character, HumanoidSlotType.Buttocks, "4175");
})
InputUtil.onKeyDown(Keys.Two, () => {
// When exiting the interaction without transmission, it will automatically return to the coordinates and rotation before the interaction
interObj.leave();
})
}
}
}
getCurrentCharacter
• getCurrentCharacter(): Character
other
Get the character being interacted
Returns
Character | True: In interaction |
---|
Usage example: create a script named "InteractorGetInteractCharacterSample", place it in the child of a interactor in the object manager, open the script, enter the following code to save, run the game, and you will see the effect of a interactor in the scene. Player can interact with this interactor, and the code is as follows:
@Component
export default class InteractorGetInteractCharacterSample extends Script {
protected async onStart(): Promise<void> {
const interObj = this.gameObject as Interactor;
// Start interactive callback
interObj.onEnter.add(() => {
console.log(`onEnter status: ${interObj.getCurrentCharacter()}`)
})
// Omit the start interaction code
}
}
@Component
export default class InteractorGetInteractCharacterSample extends Script {
protected async onStart(): Promise<void> {
const interObj = this.gameObject as Interactor;
// Start interactive callback
interObj.onEnter.add(() => {
console.log(`onEnter status: ${interObj.getCurrentCharacter()}`)
})
// Omit the start interaction code
}
}
leave
• leave(position?
, rotation?
, animationId?
): boolean
other
End interaction. It is usually used in pairs with enter. See the example code in the method enter for usage example.
Parameters
position? Vector | End position default: the coordinates before the Player starts interaction shall prevail |
---|---|
rotation? Rotation | End rotation amount default: The rotation before the player starts the interaction shall prevail. If the player's posture before starting is tilted, it will not be corrected internally |
animationId? string | New stance, default: Player's stance before starting interaction (animation will turn to stance) range: string length is determine according to animation asset ID |
Returns
boolean | true It indicates that the end interaction logic has been triggered. The asynchronous operation and the return value cannot indicate that the end interaction logic has been successful. If you need to ensure that the end interaction logic is completed before execution, please use onLeave delegate |
---|