mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Optimize the serialization size of particle resources. (#6264)
* Optimize the serialization size of particle resources. * fix ci * add multiplier * refine code * fix ci * modify serialize data * fix culling
This commit is contained in:
@@ -7,6 +7,13 @@ import { lerp } from '../../core/math';
|
||||
import { Enum } from '../../core/value-types';
|
||||
import { AnimationCurve } from '../../core/geometry';
|
||||
|
||||
const SerializableTable = CC_EDITOR && [
|
||||
[ "mode", "constant", "multiplier" ],
|
||||
[ "mode", "curve", "multiplier" ],
|
||||
[ "mode", "curveMin", "curveMax", "multiplier" ],
|
||||
[ "mode", "constantMin", "constantMax", "multiplier"]
|
||||
];
|
||||
|
||||
export const Mode = Enum({
|
||||
Constant: 0,
|
||||
Curve: 1,
|
||||
@@ -105,6 +112,10 @@ export default class CurveRange {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public _onBeforeSerialize (props) {
|
||||
return SerializableTable[this.mode];
|
||||
}
|
||||
}
|
||||
|
||||
// CCClass.fastDefine('cc.CurveRange', CurveRange, {
|
||||
|
||||
@@ -20,6 +20,14 @@ const GRADIENT_RANGE_MODE_RANDOM_COLOR = 2;
|
||||
const GRADIENT_RANGE_MODE_GRADIENT = 3;
|
||||
const GRADIENT_RANGE_MODE_TWO_GRADIENT = 4;
|
||||
|
||||
const SerializableTable = CC_EDITOR && [
|
||||
[ "_mode", "color" ],
|
||||
[ "_mode", "gradient" ],
|
||||
[ "_mode", "colorMin", "colorMax" ],
|
||||
[ "_mode", "gradientMin", "gradientMax"],
|
||||
[ "_mode", "gradient" ]
|
||||
];
|
||||
|
||||
const Mode = Enum({
|
||||
Color: 0,
|
||||
Gradient: 1,
|
||||
@@ -107,7 +115,7 @@ export default class GradientRange {
|
||||
private _color = Color.WHITE.clone();
|
||||
|
||||
public evaluate (time: number, rndRatio: number) {
|
||||
switch (this.mode) {
|
||||
switch (this._mode) {
|
||||
case Mode.Color:
|
||||
return this.color;
|
||||
case Mode.TwoColors:
|
||||
@@ -124,6 +132,10 @@ export default class GradientRange {
|
||||
return this.color;
|
||||
}
|
||||
}
|
||||
|
||||
public _onBeforeSerialize (props: any): any {
|
||||
return SerializableTable[this._mode];
|
||||
}
|
||||
}
|
||||
|
||||
// CCClass.fastDefine('cc.GradientRange', GradientRange, {
|
||||
|
||||
@@ -27,8 +27,20 @@ import { Space } from './enum';
|
||||
import { particleEmitZAxis } from './particle-general-function';
|
||||
import ParticleSystemRenderer from './renderer/particle-system-renderer';
|
||||
import TrailModule from './renderer/trail';
|
||||
import { indexOf } from '../core/utils/array';
|
||||
|
||||
const _world_mat = new Mat4();
|
||||
const _module_props = [
|
||||
"colorOverLifetimeModule",
|
||||
"shapeModule",
|
||||
"sizeOvertimeModule",
|
||||
"velocityOvertimeModule",
|
||||
"forceOvertimeModule",
|
||||
"limitVelocityOvertimeModule",
|
||||
"rotationOvertimeModule",
|
||||
"textureAnimationModule",
|
||||
"trailModule"
|
||||
]
|
||||
|
||||
@ccclass('cc.ParticleSystemComponent')
|
||||
@menu('Components/ParticleSystem')
|
||||
@@ -418,6 +430,14 @@ export class ParticleSystemComponent extends RenderableComponent {
|
||||
})
|
||||
public renderer: ParticleSystemRenderer = new ParticleSystemRenderer();
|
||||
|
||||
// serilized culling
|
||||
@property({
|
||||
type: Boolean,
|
||||
displayOrder: 27,
|
||||
tooltip:'是否剔除非 enable 的模块数据',
|
||||
})
|
||||
public isCulling: Boolean = true;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
@@ -826,4 +846,8 @@ export class ParticleSystemComponent extends RenderableComponent {
|
||||
get time () {
|
||||
return this._time;
|
||||
}
|
||||
|
||||
public _onBeforeSerialize (props) {
|
||||
return this.isCulling ? props.filter(p => !_module_props.includes(p) || this[p].enable) : props;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user