Scene / Effect
Effect Class
Effect
It is usually used for the effect performance in the game scene, such as fire, water flow, weapon trailing, etc. When the editor details panel checks Auto enable, the running game will automatically play effect.
To precisely control the play and stop of effect, please use the play and stop methods. Different effect have different life cycles, and some effect can be adjusted through the parameters in the detail panel.
Example usage: Create a script called "Effectiveness Example", place it in the object bar, open the script, enter the following code to save, run the game, and you will see the effect of particle effects exploding in the scene. The code is as follows:
@Component
export default class EffectExample extends Script {
private readonly effect = {
assetID: "145884",
object: null as mw.Effect,
};
protected onStart(): void {
this.createEffect();
}
@RemoteFunction(Client)
public async createEffect(): Promise<void> {
const success = await mw.AssetUtil.asyncDownloadAsset(this.effect.assetID);
if (success) {
// Download completed create effect
this.effect.object = await mw.GameObject.asyncSpawn(this.effect.assetID) as mw.Effect;
// Set effect transform
const transform = new mw.Transform(new mw.Vector(500, 0, 0), new mw.Rotation(0, 0, 0), new mw.Vector(1, 1, 1));
this.effect.object.localTransform = transform;
// Play effect
this.effect.object.play();
// Set the scalar value of effect parameter Life
this.effect.object.setFloat("LifeTime", 10);
// Set the special effect parameter Speed vector value
this.effect.object.setVector("Speed", new mw.Vector(0,0,150));
// Set the color value of effect parameter Color
this.effect.object.setColor("Color", new mw.LinearColor(1,0,0,1));
}
}
}
@Component
export default class EffectExample extends Script {
private readonly effect = {
assetID: "145884",
object: null as mw.Effect,
};
protected onStart(): void {
this.createEffect();
}
@RemoteFunction(Client)
public async createEffect(): Promise<void> {
const success = await mw.AssetUtil.asyncDownloadAsset(this.effect.assetID);
if (success) {
// Download completed create effect
this.effect.object = await mw.GameObject.asyncSpawn(this.effect.assetID) as mw.Effect;
// Set effect transform
const transform = new mw.Transform(new mw.Vector(500, 0, 0), new mw.Rotation(0, 0, 0), new mw.Vector(1, 1, 1));
this.effect.object.localTransform = transform;
// Play effect
this.effect.object.play();
// Set the scalar value of effect parameter Life
this.effect.object.setFloat("LifeTime", 10);
// Set the special effect parameter Speed vector value
this.effect.object.setVector("Speed", new mw.Vector(0,0,150));
// Set the color value of effect parameter Color
this.effect.object.setColor("Color", new mw.LinearColor(1,0,0,1));
}
}
}
Hierarchy
↳
Effect
Table of contents
Properties
onFinish: MulticastDelegate <() => void > |
---|
Special effects playback completed event |
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
duration(): number other |
---|
Get the number of special effect loops, only valid for non permanent loop special effects |
loopCount(): number other |
Get the number of special effect loops, only valid for non permanent loop special effects |
timeLength(): number other |
Obtain the duration of a single special effect playback (s) |
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
forceStop(): void other |
---|
Force effect to stop, and destroy all particle |
play(onSuccess? : () => void ): void other |
Play effect |
setColor(parameterName : string , value : LinearColor ): void other |
Set effect Color Parameter Value |
setColorRandom(parameterName : string , maxValue : LinearColor , minValue : LinearColor ): void other |
Set special effect color parameters randomly |
setCullDistance(inCullDistance : number ): void other |
Objects beyond this distance between players will be cropped, and the final cropping distance will depend on the image quality level; When this property is modified to ≤ 0, the cropping distance will be automatically adjusted according to the object size (CullDistanceVolume function will be automatically enabled) |
setFloat(parameterName : string , value : number ): void other |
Set the effect scalar parameter value |
setFloatRandom(parameterName : string , maxValue : number , minValue : number ): void other |
Set special effects scalar parameters randomly |
setVector(parameterName : string , value : Vector ): void other |
Set effect Vector Parameter Value |
setVectorRandom(parameterName : string , maxValue : Vector , minValue : Vector ): void other |
Set the effect vector parameter range to be random, and take the random value of the vector within a certain range |
stop(): void other |
Stop effect without affecting generate particle |
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
onFinish
• onFinish: MulticastDelegate
<() => void
>
Special effects playback completed event
Accessors
duration
• | • | ||||
---|---|---|---|---|---|
Get the number of special effect loops, only valid for non permanent loop special effects Returns
| Set the duration of the special effect, only effective for loop effects Parameters
|
loopCount
• | • | ||||
---|---|---|---|---|---|
Get the number of special effect loops, only valid for non permanent loop special effects Returns
| Set the number of special effect loops, only valid for non permanent loop special effects Parameters
|
timeLength
• |
---|
Obtain the duration of a single special effect playback (s) Returns |
number | Duration of effect single play |
---|
Methods
forceStop
• forceStop(): void
other
Force effect to stop, and destroy all particle
play
• play(onSuccess?
): void
other
Play effect
Parameters
onSuccess? () => void | Usage: callback after special effects play, default: null |
---|
setColor
• setColor(parameterName
, value
): void
other
Set effect Color Parameter Value
Parameters
parameterName string | Usage: parameter name range: the field corresponding to the color parameter value you want to set |
---|---|
value LinearColor | Usage: Color Variables |
The special effect color parameter is the "color" field in the "Special Effect Parameter Control" property panel on the right after selecting the special effect.
There is a case where multiple color property can be set for a effect, such as "color01" and "color02".
setColorRandom
• setColorRandom(parameterName
, maxValue
, minValue
): void
other
Set special effect color parameters randomly
Parameters
parameterName string | Usage: parameter name range: the field corresponding to the color parameter value you want to set |
---|---|
maxValue LinearColor | Usage: Maximum value of color variable |
minValue LinearColor | Usage: Minimum value of color variable |
The special effect color parameter is the "color" field in the "Special Effect Parameter Control" property panel on the right after selecting the special effect.
setCullDistance
• setCullDistance(inCullDistance
): void
other
Objects beyond this distance between players will be cropped, and the final cropping distance will depend on the image quality level; When this property is modified to ≤ 0, the cropping distance will be automatically adjusted according to the object size (CullDistanceVolume function will be automatically enabled)
Parameters
inCullDistance number | Usage: cull distance range: recommended (2000, 4000) type: floating point |
---|
Precautions
The final cull distance will be related to the graphics quality level
setFloat
• setFloat(parameterName
, value
): void
other
Set the effect scalar parameter value
Parameters
parameterName string | Usage: parameter name range: desired effect scalar parameter name length |
---|---|
value number | Usage: Scalar value range: Unrestricted type: Floating point number |
setFloatRandom
• setFloatRandom(parameterName
, maxValue
, minValue
): void
other
Set special effects scalar parameters randomly
Parameters
parameterName string | Usage: parameter name range: desired effect scalar parameter name length |
---|---|
maxValue number | Usage: Scalar maximum value range: Unrestricted type: Floating point number |
minValue number | Usage: Scalar minimum value range: No restrictions type: Floating point number |
setVector
• setVector(parameterName
, value
): void
other
Set effect Vector Parameter Value
Parameters
parameterName string | Usage: parameter name range: desired effect scalar parameter name length |
---|---|
value Vector | Usage: vector value |
setVectorRandom
• setVectorRandom(parameterName
, maxValue
, minValue
): void
other
Set the effect vector parameter range to be random, and take the random value of the vector within a certain range
Parameters
parameterName string | Usage: parameter name range: reasonable range: effect scalar parameter name length you want to set |
---|---|
maxValue Vector | Usage: vector maximum value |
minValue Vector | Usage: vector minimum value |
stop
• stop(): void
other
Stop effect without affecting generate particle