场景 / 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.shapeStyle = mw.ParticleEmitterShapeStyle.OnlySurface;
// 生成范围长宽高100
Effect.shapeExtents = new Vector(100, 100, 100);
// 生命周期在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.shapeStyle = mw.ParticleEmitterShapeStyle.OnlySurface;
// 生成范围长宽高100
Effect.shapeExtents = new Vector(100, 100, 100);
// 生命周期在1~10范围内随机
Effect.lifetime = new Vector2(1, 10);
// 10秒后停止, 不影响已生成粒子
setTimeout(() => {
Effect.stop();
}, 10000);
}
}Hierarchy
↳
ParticleEmitter
Table of contents
Properties
click
Properties
onBeforeDestroyDelegate: MulticastDelegate<() => void> |
|---|
| 物体销毁前事件回调 |
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other |
| 监听自定义属性同步事件 |
onDestroyDelegate: MulticastDelegate<() => void> |
| 物体销毁后事件回调 |
Accessors
acceleration(): vectorSequencePoint[] client |
|---|
| 获取生命周期内加速度变化曲线 |
brightness(): numberSequencePoint[] client |
| 亮度 |
color(): [color](mw.ParticleEmitter.md#color)SequencePoint[] client |
| 获取设置生命周期内颜色变化曲线 |
drag(): number client |
| 阻力 |
flipbookCellCount(): number client |
| 序列帧布局可用单元数量 |
flipbookCirculationTime(): number client |
| 序列帧动画循环次数 |
flipbookLayout(): ParticleFlipbookLayout client |
| 序列帧贴图的布局 |
flipbookMode(): ParticleFlipbookMode client |
| 序列帧的播放模式 |
isLocalSpace(): boolean client |
| 是否使用局部空间 |
lifetime(): Vector2 client |
| 生命周期 |
lightInfluence(): number client |
| 光照影响 |
maskRadius(): number client |
| 遮罩半径 |
orientation(): ParticleEmitterOrientation client |
| 发射取向/对齐方式 |
rate(): number client |
| 速率(即单位时间生成粒子的数量) |
rotSpeed(): numberSequencePoint[] client |
| 获取生命周期内旋转速度变化曲线 |
rotation(): number client |
| 初始旋转 |
shape(): ParticleEmitterShape client |
| 形状 |
shapeExtents(): Vector client |
| 形状范围 |
shapeInOut(): ParticleEmitterShapeInOut client |
| 获取发射内外朝向 |
shapeStyle(): ParticleEmitterShapeStyle client |
| 形状样式 |
size(): vector2DSequencePoint[] client |
| 获取生命周期内大小变化曲线 |
speed(): Vector2 client |
| 初始速度 |
spreadAngle(): number client |
| 扩散角度 |
texture([texture](mw.ParticleEmitter.md#texture)Id): void client |
| 自定义贴图 |
transparency(): numberSequencePoint[] client |
| 获取生命周期内透明度变化曲线 |
click
Accessors
assetId(): string |
|---|
| 获取当前物体使用资源的GUID |
gameObjectId(): string |
| 获取物体的唯一标识(唯一标识一个对象的字符串)。 |
isDestroyed(): boolean |
| 当前物体是否被销毁 |
isReady(): boolean |
| 当前物体状态 |
localTransform(): Transform |
| 当前物体本地变换 |
name(): string |
| 返回当前物体名称 |
netStatus(): NetStatus |
| 获取当前物体同步状态 |
parent(): GameObject |
| 获取当前父物体 |
prefabAssetId(): string |
| 返回当前物体使用的预制体资源ID,如果当前物体不是预制体,则返回空 |
sceneCaptureTag(): string |
| 获取当前物体的捕捉标签 |
tag(): string |
| 获取当前物体的标签 |
worldTransform(): Transform |
| 当前物体世界变换 |
Methods
emit([emit](mw.ParticleEmitter.md#emit)Count): void client |
|---|
| 发射固定数量粒子 |
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[] |
| 获取子物体 |
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>> client |
| 获取给定自定义属性修改时触发的事件代理。双端对象在服务器修改自定义属性后,双端均会触发事件并执行绑定函数。 |
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 server |
| 设置自定义属性的值,双端对象需在服务器调用。当设置的属性不存在时会新增自定义属性。 |
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>> |
| 异步构造一个物体,创建时请尽量把信息通过 gameObjectInfo 传入以达到性能最优化。 |
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> |
| 构造一个物体,创建时请尽量把信息通过 gameObjectInfo 传入以达到性能最优化。 |
Properties
Accessors
acceleration
• | • | ||||
|---|---|---|---|---|---|
获取生命周期内加速度变化曲线 Returns
| 设置生命周期内加速度变化曲线 Parameters
|
brightness
• | • | ||||
|---|---|---|---|---|---|
亮度 Returns
| 亮度 Parameters
|
color
• | • | ||||
|---|---|---|---|---|---|
获取设置生命周期内颜色变化曲线 Returns
| 设置生命周期内颜色变化曲线 Parameters
|
drag
• | • | ||||
|---|---|---|---|---|---|
阻力 Returns
| 阻力 Parameters
|
flipbookCellCount
• | • | ||||
|---|---|---|---|---|---|
序列帧布局可用单元数量 Returns
| 序列帧布局可用单元数量 Parameters
|
flipbookCirculationTime
• | • | ||||
|---|---|---|---|---|---|
序列帧动画循环次数 Returns
| 序列帧动画循环次数 Parameters
|
flipbookLayout
• | • | ||||
|---|---|---|---|---|---|
序列帧贴图的布局 Returns
| 序列帧贴图的布局 Parameters
|
flipbookMode
• | • | ||||
|---|---|---|---|---|---|
序列帧的播放模式 Returns
| 序列帧的播放模式 Parameters
|
isLocalSpace
• | • | ||||
|---|---|---|---|---|---|
是否使用局部空间 Returns
| 是否使用局部空间 Parameters
|
lifetime
• | • | ||||
|---|---|---|---|---|---|
生命周期 Returns
| 生命周期 Parameters
|
lightInfluence
• | • | ||||
|---|---|---|---|---|---|
光照影响 Returns
| 光照影响 Parameters
|
maskRadius
• | • | ||||
|---|---|---|---|---|---|
遮罩半径 Returns
| 遮罩半径 Parameters
|
orientation
• | • | ||||
|---|---|---|---|---|---|
发射取向/对齐方式 Returns
| 发射取向/对齐方式 Parameters
|
rate
• | • | ||||
|---|---|---|---|---|---|
速率(即单位时间生成粒子的数量) Returns
| 速率(即单位时间生成粒子的数量) Parameters
|
rotSpeed
• | • | ||||
|---|---|---|---|---|---|
获取生命周期内旋转速度变化曲线 Returns
| 设置生命周期内旋转速度变化曲线 Parameters
|
rotation
• | • | ||||
|---|---|---|---|---|---|
初始旋转 Returns
| 初始旋转 Parameters
|
shape
• | • | ||||
|---|---|---|---|---|---|
形状 Returns
| 形状 Parameters
|
shapeExtents
• | • | ||||
|---|---|---|---|---|---|
形状范围 Returns
| 形状范围 Parameters
|
shapeInOut
• | • | ||||
|---|---|---|---|---|---|
获取发射内外朝向 Returns
| 设置发射内外朝向 Parameters
|
shapeStyle
• | • | ||||
|---|---|---|---|---|---|
形状样式 Returns
| 形状样式 Parameters
|
size
• | • | ||||
|---|---|---|---|---|---|
获取生命周期内大小变化曲线 Returns
| 设置生命周期内大小变化曲线 Parameters
|
speed
• | • | ||||
|---|---|---|---|---|---|
初始速度 Returns
| 初始速度 Parameters
|
spreadAngle
• | • | ||||
|---|---|---|---|---|---|
扩散角度 Returns
| 扩散角度 Parameters
|
texture
• | ||
|---|---|---|
自定义贴图 Parameters
|
transparency
• | • | ||||
|---|---|---|---|---|---|
获取生命周期内透明度变化曲线 Returns
| 设置生命周期内透明度变化曲线 Parameters
|
Methods
emit
• emit(emitCount): void client
发射固定数量粒子
Parameters
emitCount number | 需要发射的粒子数量 range: 不做限制 type: 浮点数 |
|---|
forceStop
• forceStop(): void client
强制停止特效,所有粒子全部销毁
play
• play(): void client
播放特效
stop
• stop(): void client
停止特效,不影响已经生成的粒子