2020-01-16 01:50:23 +00:00
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
@ccclass
|
2020-02-07 01:30:12 +00:00
|
|
|
export default class GaussianBlurV1EffectScene extends cc.Component {
|
|
|
|
private _blurSlider: cc.Slider = null;
|
|
|
|
private _blurSliderLabel: cc.Label = null;
|
2020-01-16 01:50:23 +00:00
|
|
|
|
|
|
|
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-02-07 01:30:12 +00:00
|
|
|
this._blurSlider = cc.find("Canvas/Content/Controller/BlurSlider/Slider").getComponent(cc.Slider);
|
|
|
|
this._blurSliderLabel = cc.find("Canvas/Content/Controller/BlurSlider/ValueLabel").getComponent(cc.Label);
|
2020-01-16 01:50:23 +00:00
|
|
|
|
|
|
|
this._examplesParentNode = cc.find("Canvas/Content/Examples");
|
|
|
|
}
|
|
|
|
|
|
|
|
onEnable() {
|
2020-02-07 01:30:12 +00:00
|
|
|
this._blurSlider.node.on("slide", this._onSliderChanged, this);
|
2020-01-16 01:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDisable() {
|
2020-02-07 01:30:12 +00:00
|
|
|
this._blurSlider.node.off("slide", this._onSliderChanged, this);
|
2020-01-16 01:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
this._onSliderChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private _onSliderChanged() {
|
2020-02-07 01:30:12 +00:00
|
|
|
this._blurSliderLabel.string = `${this._blurSlider.progress.toFixed(2)}`;
|
2020-01-16 01:50:23 +00:00
|
|
|
|
|
|
|
// 更新材质
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|