CocosCreator-Shader-Effect-.../assets/scripts/GaussianBlurEffectScene.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-01-16 01:50:23 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class GaussianBlurEffectScene extends cc.Component {
private _grayLevelSlider: cc.Slider = null;
private _grayLevelSliderLabel: cc.Label = null;
private _examplesParentNode: cc.Node = null;
onLoad() {
2020-01-20 15:14:39 +00:00
cc.dynamicAtlasManager.enabled = false;
2020-01-21 08:15:35 +00:00
2020-01-16 01:50:23 +00:00
this._grayLevelSlider = cc.find("Canvas/Content/Controller/GrayLevelSlider/Slider").getComponent(cc.Slider);
this._grayLevelSliderLabel = cc.find("Canvas/Content/Controller/GrayLevelSlider/ValueLabel").getComponent(cc.Label);
this._examplesParentNode = cc.find("Canvas/Content/Examples");
}
onEnable() {
this._grayLevelSlider.node.on("slide", this._onSliderChanged, this);
}
onDisable() {
this._grayLevelSlider.node.off("slide", this._onSliderChanged, this);
}
start() {
this._onSliderChanged();
}
private _onSliderChanged() {
this._grayLevelSliderLabel.string = `${this._grayLevelSlider.progress.toFixed(2)}`;
// 更新材质
2020-01-21 08:15:35 +00:00
this._updateRenderComponentMaterial({});
2020-01-16 01:50:23 +00:00
}
/**
*
*
* 1.
* 2. unitform
* 3.
*/
2020-01-21 08:15:35 +00:00
private _updateRenderComponentMaterial(param: {}) {
2020-01-16 01:50:23 +00:00
this._examplesParentNode.children.forEach(childNode => {
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
let material: cc.Material = renderComponent.getMaterial(0);
2020-01-21 08:15:35 +00:00
material.setProperty("textureSize", cc.v2(childNode.width, childNode.height));
2020-01-16 01:50:23 +00:00
renderComponent.setMaterial(0, material);
});
});
}
}