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

83 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-01-10 09:44:43 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class LocalDiffusionEffectScene extends cc.Component {
private _oldLevelSlider: cc.Slider = null;
private _oldLevelSliderLabel: cc.Label = null;
private _examplesParentNode: cc.Node = null;
onLoad() {
2020-01-10 15:05:44 +00:00
cc.dynamicAtlasManager.enabled = false;
2020-01-10 09:44:43 +00:00
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)}`;
2020-01-10 15:05:44 +00:00
// // 更新材质
// this._updateRenderComponentMaterial({
// oldLevel: this._oldLevelSlider.progress
// });
2020-01-10 09:44:43 +00:00
}
/**
*
*
* 1.
* 2. unitform
* 3.
*/
private _updateRenderComponentMaterial(param: {
/**
2020-01-10 15:05:44 +00:00
*
*/
centerColor: cc.Color;
/**
* ([0.0, 1.0], [0.0, 1.0])
*/
certerPoint: cc.Vec2;
/**
* [0.0, 1.0]
2020-01-10 09:44:43 +00:00
*/
2020-01-10 15:05:44 +00:00
radius: number;
2020-01-10 09:44:43 +00:00
}) {
this._examplesParentNode.children.forEach(childNode => {
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
let material: cc.Material = renderComponent.getMaterial(0);
2020-01-10 15:05:44 +00:00
// material.setProperty("centerColor", cc.v4(1.0, 1.0, 0.0, 1.0));
material.setProperty(
"centerColor",
cc.v4(
param.centerColor.getR() / 255,
param.centerColor.getG() / 255,
param.centerColor.getB() / 255,
param.centerColor.getA() / 255
)
);
material.setProperty("centerPoint", param.certerPoint);
material.setProperty("radius", param.radius);
2020-01-10 09:44:43 +00:00
renderComponent.setMaterial(0, material);
});
});
}
}