fix particle trail material error (#4359)

This commit is contained in:
zxg0622
2019-05-05 09:57:42 +08:00
committed by Weiliang Wang
parent 42c30271c8
commit a8c0e9c1ac
2 changed files with 13 additions and 7 deletions
@@ -360,10 +360,12 @@ export class ParticleSystemComponent extends Component {
if (this.playOnAwake) {
this.play();
}
this.renderer!.enabled = this.enabledInHierarchy;
this.trailModule.onEnable();
}
protected onDisable () {
this.renderer!.enabled = this.enabledInHierarchy;
this.trailModule.onDisable();
}
@@ -387,7 +387,16 @@ export default class ParticleSystemRenderer extends RenderableComponent {
}
public _onMaterialModified (index: number, material: Material) {
this._updateMaterialParams();
if (index === 0) {
this._updateMaterialParams();
} else {
if (this.particleSystem.trailModule.enable) {
this.particleSystem.trailModule._updateMaterial();
const mat = this.getMaterial(1, CC_EDITOR)!;
mat!.recompileShaders(this._trailDefines);
}
}
this._updateModel();
}
@@ -407,7 +416,7 @@ export default class ParticleSystemRenderer extends RenderableComponent {
if (this.sharedMaterial == null && this._defaultMat == null) {
this._defaultMat = Material.getInstantiatedMaterial(builtinResMgr.get<Material>('default-particle-material'), this, true);
}
let mat: Material | null = this.sharedMaterial ? this.getMaterial(0, CC_EDITOR)! : this._defaultMat;
const mat: Material | null = this.sharedMaterial ? this.getMaterial(0, CC_EDITOR)! : this._defaultMat;
if (this.particleSystem._simulationSpace === Space.World) {
this._defines[CC_USE_WORLD_SPACE] = true;
this._trailDefines[CC_USE_WORLD_SPACE] = true;
@@ -458,11 +467,6 @@ export default class ParticleSystemRenderer extends RenderableComponent {
} else {
mat!.setProperty('frameTile_velLenScale', this.frameTile_velLenScale);
}
if (this.particleSystem.trailModule.enable) {
mat = this.getMaterial(1, CC_EDITOR)!;
mat!.recompileShaders(this._trailDefines);
}
}
private _updateModel () {