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

60 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-12-26 07:58:52 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class OldPhotoEffectScene extends cc.Component {
private _oldLevelSlider: cc.Slider = null;
private _oldLevelSliderLabel: cc.Label = null;
private _examplesParentNode: cc.Node = null;
onLoad() {
this._oldLevelSlider = cc.find("Canvas/Content/Sliders/OldLevelSlider/Slider").getComponent(cc.Slider);
this._oldLevelSliderLabel = cc.find("Canvas/Content/Sliders/OldLevelSlider/ValueLabel").getComponent(cc.Label);
this._examplesParentNode = cc.find("Canvas/Content/Examples");
}
onEnable() {
this._oldLevelSlider.node.on("slide", this._onSliderChanged, this);
}
onDisable() {
this._oldLevelSlider.node.off("slide", this._onSliderChanged, this);
}
start() {
this._onSliderChanged();
}
private _onSliderChanged() {
this._oldLevelSliderLabel.string = `${this._oldLevelSlider.progress.toFixed(2)}`;
// 更新材质
this._updateRenderComponentMaterial({
oldLevel: this._oldLevelSlider.progress
});
}
/**
*
*
* 1.
* 2. unitform
* 3.
*/
private _updateRenderComponentMaterial(param: {
/**
* [0.0, 1.0] 1.0
*/
oldLevel: number;
}) {
this._examplesParentNode.children.forEach(childNode => {
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
let material: cc.Material = renderComponent.getMaterial(0);
material.setProperty("oldLevel", param.oldLevel);
renderComponent.setMaterial(0, material);
});
});
}
}