Skip to content
ParticleEmitter

场景 / ParticleEmitter

ParticleEmitter Class

粒子特效

通常用于游戏场景中的效果表现,目前开放部分粒子效果,当编辑器细节面板勾选自动启用时,运行游戏会自动播放特效。

如需精确控制特效的播放与停止,请使用 play 和 stop 方法。该特效需要手动控制生命周期,效果可通过细节面板中参数调节。

使用示例:创建一个名为"EffectExample"的脚本,拖拽到对象栏特效下,打开脚本,输入以下代码保存,运行游戏,你将在场景中看到粒子的变化效果。代码如下:
ts
@Component
export default class EffectExample extends Script {

    protected onStart(): void {

         let Effect = this.gameObject as ParticleEmitter;
         // 涉及部分对生命周期内效果的修改
         // 创建尺寸生命周期数组 效果为由蓝线性过度至红色
         let ColorSequence = Array<mw.colorSequencePoint>();
         // 生命周期0%时为蓝色 详见LinearColor
         ColorSequence.push(new mw.colorSequencePoint(0, new LinearColor(1,0,0)));
         // 生命周期100%时为红色
         ColorSequence.push(new mw.colorSequencePoint(0, new LinearColor(0,0,1)));
         Effect.color = ColorSequence;
         // 创建透明度生命周期数组 效果为逐渐清晰
         let TransparencySequence = Array<mw.numberSequencePoint>();
         // 刚生成时透明度为0 看不见
         TransparencySequence.push(new mw.numberSequencePoint(0, 0));
         // 逐渐过渡到生命周期末 全显示
         TransparencySequence.push(new mw.numberSequencePoint(1, 1));
         Effect.transparency = TransparencySequence;

         // 创建尺寸生命周期数组 效果为变大再缩小
         let SizeSequence = Array<mw.numberSequencePoint>();
         // 生命周期0%时大小为0
         Size
         // 生命周期50%时大小为4
         SizeSequence.push(new mw.numberSequencePoint(0.5, 4));
         // 生命周期100%时大小回到0
         SizeSequence.push(new mw.numberSequencePoint(1, 0));
         Effect.size = SizeSequence;

         // 设置特效阻力为1
         Effect.drag = 1;
         // 增加特效生成的速度
         Effect.rate = 100;
         // 不进行边缘裁剪,全部保留,方形
         Effect.maskRadius = 1;
         // 在球形范围内生成
         Effect.shape = mw.ParticleEmitterShape.Sphere;
         // 仅在球形表面生成
         Effect.shapeStyle = mw.ParticleEmitterShapeStyle.OnlySurface;

         // 生命周期在1~10范围内随机
         Effect.lifetime = new Vector2(1, 10);
         // 10秒后停止, 不影响已生成粒子
         setTimeout(() => {
             Effect.stop();
         }, 10000);
    }
}
@Component
export default class EffectExample extends Script {

    protected onStart(): void {

         let Effect = this.gameObject as ParticleEmitter;
         // 涉及部分对生命周期内效果的修改
         // 创建尺寸生命周期数组 效果为由蓝线性过度至红色
         let ColorSequence = Array<mw.colorSequencePoint>();
         // 生命周期0%时为蓝色 详见LinearColor
         ColorSequence.push(new mw.colorSequencePoint(0, new LinearColor(1,0,0)));
         // 生命周期100%时为红色
         ColorSequence.push(new mw.colorSequencePoint(0, new LinearColor(0,0,1)));
         Effect.color = ColorSequence;
         // 创建透明度生命周期数组 效果为逐渐清晰
         let TransparencySequence = Array<mw.numberSequencePoint>();
         // 刚生成时透明度为0 看不见
         TransparencySequence.push(new mw.numberSequencePoint(0, 0));
         // 逐渐过渡到生命周期末 全显示
         TransparencySequence.push(new mw.numberSequencePoint(1, 1));
         Effect.transparency = TransparencySequence;

         // 创建尺寸生命周期数组 效果为变大再缩小
         let SizeSequence = Array<mw.numberSequencePoint>();
         // 生命周期0%时大小为0
         Size
         // 生命周期50%时大小为4
         SizeSequence.push(new mw.numberSequencePoint(0.5, 4));
         // 生命周期100%时大小回到0
         SizeSequence.push(new mw.numberSequencePoint(1, 0));
         Effect.size = SizeSequence;

         // 设置特效阻力为1
         Effect.drag = 1;
         // 增加特效生成的速度
         Effect.rate = 100;
         // 不进行边缘裁剪,全部保留,方形
         Effect.maskRadius = 1;
         // 在球形范围内生成
         Effect.shape = mw.ParticleEmitterShape.Sphere;
         // 仅在球形表面生成
         Effect.shapeStyle = mw.ParticleEmitterShapeStyle.OnlySurface;

         // 生命周期在1~10范围内随机
         Effect.lifetime = new Vector2(1, 10);
         // 10秒后停止, 不影响已生成粒子
         setTimeout(() => {
             Effect.stop();
         }, 10000);
    }
}

Hierarchy

Table of contents

Properties

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

acceleration(): vectorSequencePoint[] client
获取生命周期内加速度变化曲线
brightness(): number client
亮度
color(): [color](mw.ParticleEmitter.md#color)SequencePoint[] client
获取设置生命周期内颜色变化曲线
drag(): number client
阻力
lifetime(): Vector2 client
生命周期
lightInfluence(): number client
光照影响
maskRadius(): number client
遮罩半径
rate(): number client
速率(即单位时间生成粒子的数量)
rotSpeed(): numberSequencePoint[] client
获取生命周期内旋转速度变化曲线
rotation(): number client
初始旋转
shapeExtents(): Vector client
形状范围
shapeStyle(): ParticleEmitterShapeStyle client
形状样式
size(): numberSequencePoint[] client
获取生命周期内大小变化曲线
speed(): Vector2 client
初始速度
spreadAngle(): number client
扩散角度
texture([texture](mw.ParticleEmitter.md#texture)Id): void client
自定义贴图
transparency(): numberSequencePoint[] client
获取生命周期内透明度变化曲线
click

Accessors

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

Methods

forceStop(): void client
强制停止特效,所有粒子全部销毁
play(): void client
播放特效
stop(): 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[]
获取子物体
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
获取物体是否被显示
isPrefabActor(): 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

Accessors

acceleration

get acceleration(): vectorSequencePoint[] client

set acceleration(sequence): void client

获取生命周期内加速度变化曲线

Returns

vectorSequencePoint[]特效向量值曲线节点数组

设置生命周期内加速度变化曲线

Parameters

sequence vectorSequencePoint[]特效向量值曲线节点数组

brightness

get brightness(): number client

set brightness(brightness): void client

亮度

Returns

number特效的亮度

亮度

Parameters

brightness number生成粒子的亮度

color

get color(): colorSequencePoint[] client

set color(sequence): void client

获取设置生命周期内颜色变化曲线

Returns

colorSequencePoint[]特效颜色值曲线节点数组

设置生命周期内颜色变化曲线

Parameters

sequence colorSequencePoint[]特效颜色值曲线节点数组

drag

get drag(): number client

set drag(drag): void client

阻力

Returns

number特效的阻力

阻力

Parameters

drag number生成粒子所受到的的阻力

lifetime

get lifetime(): Vector2 client

set lifetime(lifetime): void client

生命周期

Returns

Vector2特效的生命周期 (x为最小值y为最大值,粒子生成时在x~y范围内随机取值)

生命周期

Parameters

lifetime Vector2生命周期,粒子的存在时间(x为最小值y为最大值,粒子生成时在x~y范围内随机取值)

lightInfluence

get lightInfluence(): number client

set lightInfluence(lightInfluence): void client

光照影响

Returns

number特效的光照影响程度

光照影响

Parameters

lightInfluence number特效的光照影响程度

maskRadius

get maskRadius(): number client

set maskRadius(radius): void client

遮罩半径

Returns

number生成粒子的遮罩剔除半径

遮罩半径

Parameters

radius number生成粒子的遮罩剔除半径

rate

get rate(): number client

set rate(rate): void client

速率(即单位时间生成粒子的数量)

Returns

number特效的速率

速率(即单位时间生成粒子的数量)

Parameters

rate number速率

rotSpeed

get rotSpeed(): numberSequencePoint[] client

set rotSpeed(sequence): void client

获取生命周期内旋转速度变化曲线

Returns

numberSequencePoint[]特效标量值曲线节点数组

设置生命周期内旋转速度变化曲线

Parameters

sequence numberSequencePoint[]特效标量值曲线节点数组

rotation

get rotation(): number client

set rotation(initialRotation): void client

初始旋转

Returns

number特效的初始旋转

初始旋转

Parameters

initialRotation number生成粒子的初始旋转值

shapeExtents

get shapeExtents(): Vector client

set shapeExtents(extents): void client

形状范围

Returns

Vector特效的形状样式

形状范围

Parameters

extents Vector特效的形状范围 (设置粒子发射器的形状大小, 这决定了粒子会在多大的范围内随机生成) 仅非点状类型时生效 X 代表圆/球半径 三角形边长 Y 代表等腰三角形内角 Z 代表体积高度

shapeStyle

get shapeStyle(): ParticleEmitterShapeStyle client

set shapeStyle(style): void client

形状样式

Returns

ParticleEmitterShapeStyle特效的形状样式

形状样式

Parameters

style ParticleEmitterShapeStyle特效的形状样式表面生成还是体积内生成,仅非点状类型时生效)

size

get size(): numberSequencePoint[] client

set size(sequence): void client

获取生命周期内大小变化曲线

Returns

numberSequencePoint[]

设置生命周期内大小变化曲线

Parameters

sequence numberSequencePoint[]特效标量值曲线节点数组

speed

get speed(): Vector2 client

set speed(speed): void client

初始速度

Returns

Vector2生成粒子的初始速度(x为最小值y为最大值,粒子生成时在x~y范围内随机取值)

初始速度

Parameters

speed Vector2生成粒子的初始速度(x为最小值y为最大值,粒子生成时在x~y范围内随机取值)

spreadAngle

get spreadAngle(): number client

set spreadAngle(spreadAngle): void client

扩散角度

Returns

number特效的扩散角度

扩散角度

Parameters

spreadAngle number生成粒子的扩散角度

texture

set texture(textureId): void client

自定义贴图

Parameters

textureId string number特效自定义贴图ID

transparency

get transparency(): numberSequencePoint[] client

set transparency(sequence): void client

获取生命周期内透明度变化曲线

Returns

numberSequencePoint[]特效标量值曲线节点数组

设置生命周期内透明度变化曲线

Parameters

sequence numberSequencePoint[]特效标量值曲线节点数组

Methods


forceStop

forceStop(): void client

强制停止特效,所有粒子全部销毁


play

play(): void client

播放特效


stop

stop(): void client

停止特效,不影响已经生成的粒子