Scene / EffectService
EffectService Class
Effect Manager
Effect It is usually used to enhance the graphics of the game, present visual effect or convey specific emotions or information. Effect can be various forms of visual effect, such as particle effects, lighting effects, explosion effects, smoke effects, etc. The MW editor provides a large number of particle effect in the left effect bar. You can drag the effect to the scene to view and use it.
EffectService Many static methods can be directly called, including:
playAtPosition、 playOnGameObject Method control the position of particle effect playing.
stop Method to control particle effects to stop playing.
Table of contents
Properties
checkPlayParams: any |
---|
Check Player parameters |
Methods
getEffectById(playId : number ): Promise <Effect > other |
---|
Get a effect object according to the playing ID |
playAtPosition(assetId : string , position : Vector , params? : Object ): number other |
Play effect in one position |
playOnGameObject(assetId : string , target : GameObject , params? : Object ): number other |
Play effect on a GameObject |
stop(playId : number ): void other |
Stop a currently playing special effect |
stopAll(): void other |
Stop all effect |
stopEffectFromHost(source : string , target : Player GameObject ): void other |
Stop the effect of all asset IDs on the target object |
Properties
checkPlayParams
▪ Static
Private
checkPlayParams: any
Check Player parameters
Methods
getEffectById
• Static
getEffectById(playId
): Promise
<Effect
> other
Get a effect object according to the playing ID
Parameters
playId number | The unique ID for playing, the sound effect asset ID, is equal to the assetId. The difference is that playId passes a number type, such as 4330; The assetId can be transferred to the string type "4330". Range: string length depends on the length of asset ID type: integer |
---|
Returns
Promise <Effect > | GameObject of Particle Object |
---|
Example usage: Create a script called Effectiveness Example, place it in the object bar, open the script, modify the original content to the following, save and run the game, and a flame effect will be played in the scene. After 5 seconds, obtain the effect object and move it to the (200, 0, 200) position
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId = EffectService.playAtPosition(fireAssetId, new Vector(0, 0, 200), { loopCount: 0});
// Move the effect to the (200, 0, 200) position after 5 seconds
TimeUtil.delaySecond(5).then(() => {
EffectService.getEffectById(playId).then((effect) => {
effect.worldTransform.position = new Vector(200, 0, 200);
});
});
}
}
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId = EffectService.playAtPosition(fireAssetId, new Vector(0, 0, 200), { loopCount: 0});
// Move the effect to the (200, 0, 200) position after 5 seconds
TimeUtil.delaySecond(5).then(() => {
EffectService.getEffectById(playId).then((effect) => {
effect.worldTransform.position = new Vector(200, 0, 200);
});
});
}
}
playAtPosition
• Static
playAtPosition(assetId
, position
, params?
): number
other
Play effect in one position
Parameters
assetId string | The unique ID of the play, the ID of the sound effect asset, is equal to the playId. The difference is that playId passes a number type, such as 4330; The assetId can be transferred to the string type "4330". Range: string length depends on the length of asset ID |
---|---|
position Vector | World coordinates |
params? Object | Play parameter default: View the following values |
params.duration? number | - |
params.loopCount? number | - |
params.rotation? Rotation | - |
params.scale? Vector | - |
Returns
number | The unique ID of this play, which can be used to stop playing. If 0 is returned, description indicates that the parameter is wrong and the play fails |
---|
Example usage: Create a script called Effectiveness Example, place it in the object bar, open the script, modify the original content to the following, save and run the game, and a flame effect will be played at coordinates (0,0,200)
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId = EffectService.playAtPosition(fireAssetId, new mw.Vector(0, 0, 200), { loopCount: 0});
}
}
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId = EffectService.playAtPosition(fireAssetId, new mw.Vector(0, 0, 200), { loopCount: 0});
}
}
playOnGameObject
• Static
playOnGameObject(assetId
, target
, params?
): number
other
Play effect on a GameObject
Parameters
assetId string | The unique ID of the play, the ID of the sound effect asset, is equal to the playId. The difference is that playId passes a number type, such as 4330; The assetId can be transferred to the string type "4330". Range: string length depends on the length of asset ID |
---|---|
target GameObject | Target GameObject |
params? Object | Playback parameters, slotType - hanging point type (default null), loopCount - number of cycles (default 1), duration - playback duration (unit: seconds, default 0, setting this field will ignore loopCount), position - coordinate offset (default Vector. zero), rotation - rotation offset (default Rotation. zero), scale - scale (Vector. one) default: undefined |
params.duration? number | - |
params.loopCount? number | - |
params.position? Vector | - |
params.rotation? Rotation | - |
params.scale? Vector | - |
params.slotType? HumanoidSlotType | - |
Returns
number | The unique ID of this play, which can be used to stop playing. If 0 is returned, description indicates that the parameter is wrong and the play fails |
---|
Usage example: create a script named EffectExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and a flame effect will be played on all Player
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
mw.Player.getAllPlayers().forEach((player) => {
const playId = EffectService.playOnGameObject(fireAssetId, player.character, { loopCount: 0});
})
}
}
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
mw.Player.getAllPlayers().forEach((player) => {
const playId = EffectService.playOnGameObject(fireAssetId, player.character, { loopCount: 0});
})
}
}
stop
• Static
stop(playId
): void
other
Stop a currently playing special effect
Parameters
playId number | The unique ID for playing, the sound effect asset ID, is equal to the assetId. The difference is that playId passes a number type, such as 4330; The assetId can be transferred to the string type "4330". Range: string length depends on the length of asset ID type: integer |
---|
Usage example: create a script named EffectExample, place it in the object bar, open the script, modify the original content as follows, save and run the game, and a flame effect will be played in the scene, and the effect will stop after 5 seconds
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId = EffectService.playAtPosition(fireAssetId, new mw.Vector(0, 0, 200), { loopCount: 0});
// Stop special effects after 5 seconds
TimeUtil.delaySecond(5).then(() => {
EffectService.stop(playId);
})
}
}
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId = EffectService.playAtPosition(fireAssetId, new mw.Vector(0, 0, 200), { loopCount: 0});
// Stop special effects after 5 seconds
TimeUtil.delaySecond(5).then(() => {
EffectService.stop(playId);
})
}
}
stopAll
• Static
stopAll(): void
other
Stop all effect
Usage example: create a script named EffectExample, place it in the object bar, open the script, modify the original content as follows, save and run the game, three flame effect will be played in the scene, and all effect will be stopped after 5 seconds
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId1 = EffectService.playAtPosition(fireAssetId, new mw.Vector(0, 0, 200), { loopCount: 0});
const playId2 = EffectService.playAtPosition(fireAssetId, new mw.Vector(200, 0, 200), { loopCount: 0});
const playId3 = EffectService.playAtPosition(fireAssetId, new mw.Vector(400, 0, 200), { loopCount: 0});
// Stop all effect in 5 seconds
TimeUtil.delaySecond(5).then(() => {
EffectService.stopAll();
})
}
}
@Component
export default class EffectExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
const fireAssetId = "4330";
const playId1 = EffectService.playAtPosition(fireAssetId, new mw.Vector(0, 0, 200), { loopCount: 0});
const playId2 = EffectService.playAtPosition(fireAssetId, new mw.Vector(200, 0, 200), { loopCount: 0});
const playId3 = EffectService.playAtPosition(fireAssetId, new mw.Vector(400, 0, 200), { loopCount: 0});
// Stop all effect in 5 seconds
TimeUtil.delaySecond(5).then(() => {
EffectService.stopAll();
})
}
}
stopEffectFromHost
• Static
stopEffectFromHost(source
, target
): void
other
Stop the effect of all asset IDs on the target object
Parameters
source string | Special effect source, the first parameter of playEffect. range: |
---|---|
target Player GameObject | Target object (Player or NPC or GameObject) |